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 an executable php script. """ basename = os.path.split(filename)[-1] author = self.config.get('author', '') if author: author = '-{} '.format(author) return template.format(name=basename, author=author, 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(self, filename): """ Creates a basic C file. """ # Disable automakefile if asked. library = self.has_arg('l(ib)?') if library: self.debug('Library file mode, no automakefile.') self.ignore_post.add('automakefile') parentdir, basename = os.path.split(filename) author = self.config.get('author', '') fileext = os.path.splitext(filename)[-1].lower() if fileext in self.cpp_extensions: include = 'iostream' namespace = '\nusing std::cout;\nusing std::endl;\n' else: include = 'stdio.h' namespace = '' return (template_lib if library else template).format( filename=basename, author='-{} '.format(author) if author else author, date=date(), include=include, namespace=namespace)
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_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 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 blank Rust file. """ author = self.config.get('author', '') return template.format( name=os.path.splitext(os.path.split(filename)[-1])[0], author='-{} '.format(author) if author else author, date=date(), imports=self.format_imports())
def create(self, filename): """ Creates a Bats test file (bash automated testing). """ author = self.config.get('author', None) return template.format( author='-{} '.format(author) if author else '', date=date(), name=os.path.splitext(os.path.split(filename)[-1])[0], setup=template_setup if self.has_arg('^s(etup)?') else '', teardown=template_teardown if self.has_arg('^t(eardown)?') else '')
def create(self, filename): """ Creates a basic perl source file. """ author = self.config.get('author', '') description = ' '.join(self.args) if self.args else '' return template.format( author='-{} '.format(author) if author else author, date=date(), description=description)
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, fname): """ Creates a blank js/node file. """ # Using the node shebang, even though this may not be for node. author = self.config.get('author', '') basename = os.path.split(fname)[-1] name = os.path.splitext(basename)[0] self.debug('Retrieved config..') return TEMPLATE.format( name=name, author='-{} '.format(author) if author else author, date=date(), scriptname=basename, version=self.config.get('default_version', default_version))
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 a basic bash source file. """ sections = [template] if self.has_arg('^a(rgs)?$'): self.debug('Using args template...') self.pop_args(self.args, ('a', 'args')) sections.append(template_args) if self.has_arg('^f(unc)?$'): self.debug('Using function template...') self.pop_args(self.args, ('f', 'func')) sections.append(template_func) author = self.config.get('author', '') description = ' '.join(self.args) if self.args else '' return '\n'.join(sections).format( author='-{} '.format(author) if author else author, date=date(), description=description, 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 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 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 new python source file. Several templates are available. """ if self.has_arg('^t(emplates)?$'): exitcode = self.print_templates() raise SignalExit(code=exitcode) templateid = (self.get_arg(0) or self.config.get('template', 'docopt')).lower() extra_imports = self.args[1:] 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)) author = self.config.get('author', '') imports = extra_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) template_args.update({ 'author': '-{} '.format(author) if author else author, '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 the 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 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))