text
stringlengths
0
828
if structure is not None:
xstruct = structure
else:
xstruct = self.structure()
if zipfile.is_zipfile(self.source()):
zfile = zipfile.ZipFile(self.source(), 'r')
else:
zfile = None
base = os.path.dirname(self.source())
# build the structure information
# noinspection PyShadowingNames
def build_level(root, xlevel):
# ignore the entry
if xlevel.get('enabled', 'True') == 'False':
return
# create a folder
if xlevel.tag == 'folder':
name = makotext.render(xlevel.get('name'), opts)
dirname = os.path.join(root, name)
if not os.path.exists(dirname):
os.mkdir(dirname)
for xchild in xlevel:
build_level(dirname, xchild)
# create a file
elif xlevel.tag == 'file':
name = makotext.render(xlevel.get('name'), opts)
fname = os.path.join(root, name)
# create from a template
templ = xlevel.get('templ')
if templ:
if zfile:
templ_str = zfile.read('templ/{0}'.format(templ))
else:
templ_path = os.path.join(base, 'templ', templ)
templ_str = open(templ_path, 'r').read()
rendered = makotext.render(templ_str, opts)
rendered = rendered.replace('\r\n', '\r')
f = open(fname, 'w')
f.write(rendered)
f.close()
# create a blank file
else:
f = open(fname, 'w')
f.close()
for xlevel in xstruct:
build_level(outpath, xlevel)
if zfile:
zfile.close()
return True"
3697,"def render(self, template, fail='## :todo: add {template}'):
""""""
Returns the rendered value for the inputted template name.
:param template | <str>
""""""
try:
return self._templates[template].render(scaffold=self)
except KeyError:
return fail.format(template=template)"
3698,"def run(self, path=None):
""""""
Runs the scaffold option generation for this scaffold in the given
path. If no path is supplied, then the current path is used.
:param path | <str> || None
""""""
if path is None:
path = '.'
for prop in self._properties.values():
if not prop.prompt():
return False
return self.build(path)"
3699,"def structure(self):
""""""
Returns the structure for this scaffold.
:return <xml.etree.ElementTree.Element> || None
""""""
opts = {'scaffold': self}
# build from a zip file
if zipfile.is_zipfile(self.source()):
zfile = zipfile.ZipFile(self.source(), 'r')
try:
contents = zfile.read('structure.xml')
contents = makotext.render(contents, opts)