def create(self, filename): """ Creates a blank text file (no content). """ _, basename = os.path.split(filename) return template.format(name=os.path.splitext(basename)[0], author=fix_author( self.config.get('author', None)), date=date())
def create_setup(self, filename, *args): """ Create a basic setup.py. """ name, ver, desc = self.parse_setup_args(*args) shebangexe = self.config.get('shebangexe', '/usr/bin/env python3') tmpargs = { 'author': self.config.get('author', os.environ.get('USER', '?')), 'date': date(), 'desc': desc or 'My default description.', 'email': self.config.get('email', '*****@*****.**'), 'pkgname': name or 'MyApp', 'shebangexe': shebangexe, 'version': (ver or self.config.get('default_version', default_version)) } tmpargs['doc_author'] = fix_author(tmpargs['author']) # Render the template. content = template_setup.format(**tmpargs) # See if a SignalAction is needed. base, _ = os.path.split(filename) setupfile = os.path.join(base, 'setup.py') if filename == setupfile: return content raise SignalAction(message='Using required setup.py file name.', filename=setupfile, content=content)
def create_setup(self, filename, *args): """ Create a basic setup.py. """ name, ver, desc = self.parse_setup_args(*args) shebangexe = self.config.get('shebangexe', '/usr/bin/env python3') tmpargs = { 'author': self.config.get('author', os.environ.get('USER', '?')), 'date': date(), 'desc': desc or 'My default description.', 'email': self.config.get('email', '*****@*****.**'), 'pkgname': name or 'MyApp', 'shebangexe': shebangexe, 'version': ( ver or self.config.get('default_version', default_version) ) } tmpargs['doc_author'] = fix_author(tmpargs['author']) # Render the template. content = template_setup.format(**tmpargs) # See if a SignalAction is needed. base, _ = os.path.split(filename) setupfile = os.path.join(base, 'setup.py') if filename == setupfile: return content raise SignalAction( message='Using required setup.py file name.', filename=setupfile, content=content )
def create(self, filename): """ Creates a blank Rust file. """ return template.format( name=os.path.splitext(os.path.split(filename)[-1])[0], author=fix_author(self.config.get('author', None)), date=date(), imports=self.format_imports())
def create(self, filename): """ Creates a blank text file (no content). """ _, basename = os.path.split(filename) return template.format( name=os.path.splitext(basename)[0], author=fix_author(self.config.get('author', None)), date=date() )
def create(self, filename): """ Creates a basic C/C++ header file. """ parentdir, filepath = os.path.split(filename) filebase = os.path.splitext(filepath)[0] return template_lib.format( filename=filepath, author=fix_author(self.config.get('author', None)), date=date(), header_def='_{}_H'.format(filebase.upper()), )
def create(self, fname): """ Creates a blank js/node file. """ # Using the node shebang, even though this may not be for node. basename = os.path.split(fname)[-1] name = os.path.splitext(basename)[0] if self.argd['--short']: # Only the comment header. return HEADER.format( name=name, author=fix_author(self.config.get('author', None)), date=date()).lstrip() # Full template. return ''.join(( SHEBANG, HEADER, TEMPLATE)).format( name=name, author=fix_author(self.config.get('author', None)), date=date(), scriptname=basename, version=self.config.get('default_version', default_version))
def create(self, filename): """ Creates a basic nasm file. """ _, basename = os.path.split(filename) name, _ = os.path.splitext(basename) objfile = '{}.o'.format(name) return self.get_template(filename).format( name=name, filename=basename, author=fix_author(self.config.get('author', None)), date=date(), objectfile=objfile, outputfile=name, )
def create(self, filename): """ Creates a basic C file. """ basename, ext = os.path.splitext(filename) if self.argd['--lib'] or (ext in CHeaderPlugin.extensions): # Just do the CHeader thing. self.debug('Library file mode, no automakefile: {}'.format( filename )) # Remove .c,.cpp extensions. filename = basename while not filename.endswith(CHeaderPlugin.extensions): filename, ext = os.path.splitext(filename) if not ext: # Add any missing CHeader extensions. filename = '{}.h'.format(filename) break self.debug('Switching to CHeader mode: {}'.format(filename)) raise SignalAction( filename=filename, content=CHeaderPlugin().create(filename), ignore_post={'automakefile', 'chmodx'}, ) parentdir, basename = os.path.split(filename) fileext = os.path.splitext(filename)[-1].lower() if fileext in self.cpp_extensions: includes = self.make_includes( self.argd['--include'], defaults=cpp_headers, ) namespace = '\nusing std::cout;\nusing std::endl;\n' else: includes = self.make_includes( self.argd['--include'], defaults=c_headers, ) namespace = '' return template.format( filename=basename, author=fix_author(self.config.get('author', None)), date=date(), defines=self.make_defines(self.argd['--define']), includes=includes, namespace=namespace ).replace('\n\n\n', '\n\n')
def create(self, filename): """ Creates a basic C file. """ basename, ext = os.path.splitext(filename) if self.argd['--lib'] or (ext in CHeaderPlugin.extensions): # Just do the CHeader thing. self.debug( 'Library file mode, no automakefile: {}'.format(filename)) # Remove .c,.cpp extensions. filename = basename while not filename.endswith(CHeaderPlugin.extensions): filename, ext = os.path.splitext(filename) if not ext: # Add any missing CHeader extensions. filename = '{}.h'.format(filename) break self.debug('Switching to CHeader mode: {}'.format(filename)) raise SignalAction( filename=filename, content=CHeaderPlugin().create(filename), ignore_post={'automakefile', 'chmodx'}, ) parentdir, basename = os.path.split(filename) fileext = os.path.splitext(filename)[-1].lower() if fileext in self.cpp_extensions: includes = self.make_includes( self.argd['--include'], defaults=cpp_headers, ) namespace = '\nusing std::cout;\nusing std::endl;\n' else: includes = self.make_includes( self.argd['--include'], defaults=c_headers, ) namespace = '' return template.format( filename=basename, author=fix_author(self.config.get('author', None)), date=date(), defines=self.make_defines(self.argd['--define']), includes=includes, namespace=namespace).replace('\n\n\n', '\n\n')
def create(self, filename): """ Creates a Bats test file (bash automated testing). """ if self.argd['--setup']: setup = template_setup else: setup = '' if self.argd['--teardown']: teardown = template_teardown else: teardown = '' return template.format( author=fix_author(self.config.get('author', None)), date=date(), name=os.path.splitext(os.path.split(filename)[-1])[0], setup=setup, teardown=teardown)
def create(self, filename): """ Creates a Bats test file (bash automated testing). """ if self.argd['--setup']: setup = template_setup else: setup = '' if self.argd['--teardown']: teardown = template_teardown else: teardown = '' return template.format( author=fix_author(self.config.get('author', None)), date=date(), name=os.path.splitext(os.path.split(filename)[-1])[0], setup=setup, teardown=teardown )
def create(self, filename): """ Creates a basic bash source file. """ sections = [template] if self.argd['--simple']: self.debug('Using simple template...') else: if self.argd['--args']: self.debug('Using args template...') sections.append(template_args) if self.argd['--func']: self.debug('Using function template...') sections.append(template_func) return '\n'.join(sections).format( author=fix_author(self.config.get('author', None)), date=date(), description=' '.join(self.argd['DESCRIPTION']) or '...', filename=os.path.splitext(os.path.split(filename)[-1])[0], version=self.config.get('default_version', default_version))
def create(self, filename): """ Creates a basic bash source file. """ sections = [template] if self.argd['--simple']: self.debug('Using simple template...') else: if self.argd['--args']: self.debug('Using args template...') sections.append(template_args) if self.argd['--func']: self.debug('Using function template...') sections.append(template_func) return '\n'.join(sections).format( author=fix_author(self.config.get('author', None)), date=date(), description=' '.join(self.argd['DESCRIPTION']) or '...', filename=os.path.splitext(os.path.split(filename)[-1])[0], version=self.config.get('default_version', default_version) )
def create(self, filename): """ Creates an executable php script. """ return template.format( name=os.path.split(filename)[-1], author=fix_author(self.config.get('author', None)), date=date())
def create(self, filename): """ Creates a basic perl source file. """ return template.format( author=fix_author(self.config.get('author', None)), date=date(), description=' '.join(self.argv))
def create(self, filename): """ Creates a new python source file. Several templates are available. """ if self.argd['--templates']: # Viewing template names. exitcode = self.print_templates() raise SignalExit(code=exitcode) templateid = ( self.argd['TEMPLATE'] or self.config.get('template', 'docopt') ).lower() # Setup.py is completely different, these really need to be separated. if self.argd['TEMPLATE'] == 'setup': # Hack for ambiguos docopt usage string, use imports as args. return self.create_setup(filename, *self.argd['IMPORTS']) template_args = templates.get(templateid, None) if not template_args: msg = '\n'.join(( 'No template by that name: {}'.format(templateid), 'Use \'-t\' or \'--templates\' to list known templates.' )) raise ValueError(msg) template_base = template_bases.get(template_args['base'], None) if not template_base: errmsg = 'Misconfigured template base: {}' raise ValueError(errmsg.format(templateid)) imports = self.argd['IMPORTS'] + template_args['imports'] scriptname = os.path.split(filename)[-1] shebangexe = self.config.get('shebangexe', '/usr/bin/env python3') version = self.config.get('default_version', default_version) # Regular template (none, unittest, docopt)... template_args.update({ 'author': fix_author(self.config.get('author', None)), 'explanation': self.config.get('explanation', ''), 'date': date(), 'default_version': version, 'imports': self.parse_importlist(imports), 'scriptname': scriptname, 'shebangexe': shebangexe, }) testaction = None if templateid in {'unittest', 'test'}: # unittest is a special case. # It may need to change the file name if scriptname.startswith('test_'): testtarget = scriptname[5:] else: # Fix the filename to look more like a unittest. testtarget = scriptname path, name = os.path.split(filename) scriptname = 'test_{}'.format(name) filename = os.path.join(path, scriptname) # Create an action that will allow the filename change. testaction = SignalAction( message='Switching to unittest file name format.', filename=filename) # Fix the scriptname, add the testtarget args. template_args['scriptname'] = scriptname template_args['testtarget'] = testtarget # Render the template, action is needed because of a name change. if testaction: testaction.content = template_base.format(**template_args) raise testaction # Render a normal template and return the content. return template_base.format(**template_args)
def create(self, filename): """ Creates a basic perl source file. """ return template.format(author=fix_author( self.config.get('author', None)), date=date(), description=' '.join(self.argv))
def create(self, filename): """ Creates a new python source file. Several templates are available. """ if self.argd['--templates']: # Viewing template names. exitcode = self.print_templates() raise SignalExit(code=exitcode) templateid = (self.argd['TEMPLATE'] or self.config.get('template', 'docopt')).lower() # Setup.py is completely different, these really need to be separated. if self.argd['TEMPLATE'] == 'setup': # Hack for ambiguos docopt usage string, use imports as args. return self.create_setup(filename, *self.argd['IMPORTS']) template_args = templates.get(templateid, None) if not template_args: msg = '\n'.join( ('No template by that name: {}'.format(templateid), 'Use \'-t\' or \'--templates\' to list known templates.')) raise ValueError(msg) template_base = template_bases.get(template_args['base'], None) if not template_base: errmsg = 'Misconfigured template base: {}' raise ValueError(errmsg.format(templateid)) imports = self.argd['IMPORTS'] + template_args['imports'] scriptname = os.path.split(filename)[-1] shebangexe = self.config.get('shebangexe', '/usr/bin/env python3') version = self.config.get('default_version', default_version) # Regular template (none, unittest, docopt)... template_args.update({ 'author': fix_author(self.config.get('author', None)), 'explanation': self.config.get('explanation', ''), 'date': date(), 'default_version': version, 'imports': self.parse_importlist(imports), 'scriptname': scriptname, 'shebangexe': shebangexe, }) testaction = None if templateid in {'unittest', 'test'}: # unittest is a special case. # It may need to change the file name if scriptname.startswith('test_'): testtarget = scriptname[5:] else: # Fix the filename to look more like a unittest. testtarget = scriptname path, name = os.path.split(filename) scriptname = 'test_{}'.format(name) filename = os.path.join(path, scriptname) # Create an action that will allow the filename change. testaction = SignalAction( message='Switching to unittest file name format.', filename=filename) # Fix the scriptname, add the testtarget args. template_args['scriptname'] = scriptname template_args['testtarget'] = testtarget # Render the template, action is needed because of a name change. if testaction: testaction.content = template_base.format(**template_args) raise testaction # Render a normal template and return the content. return template_base.format(**template_args)
def create(self, filename): """ Creates an executable php script. """ return template.format(name=os.path.split(filename)[-1], author=fix_author( self.config.get('author', None)), date=date())