示例#1
0
 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())
示例#2
0
文件: php.py 项目: havocesp/new
 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())
示例#3
0
文件: python.py 项目: welbornprod/new
    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
        )
示例#4
0
文件: c.py 项目: havocesp/new
    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)
示例#5
0
 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())
示例#6
0
文件: python.py 项目: welbornprod/new
    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)
示例#7
0
文件: lisp.py 项目: welbornprod/new
 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()
     )
示例#8
0
文件: rust.py 项目: havocesp/new
    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())
示例#9
0
 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 '')
示例#10
0
    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)
示例#11
0
    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()),
        )
示例#12
0
文件: c.py 项目: welbornprod/new
    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()),
        )
示例#13
0
 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))
示例#14
0
文件: asm.py 项目: welbornprod/new
 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,
     )
示例#15
0
文件: js.py 项目: havocesp/new
    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))
示例#16
0
文件: c.py 项目: welbornprod/new
    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')
示例#17
0
    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')
示例#18
0
文件: bats.py 项目: welbornprod/new
    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)
示例#19
0
文件: bats.py 项目: welbornprod/new
    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
        )
示例#20
0
    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))
示例#21
0
文件: bash.py 项目: welbornprod/new
    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)
        )
示例#22
0
    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))
示例#23
0
文件: php.py 项目: welbornprod/new
 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())
示例#24
0
文件: perl.py 项目: welbornprod/new
 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))
示例#25
0
文件: php.py 项目: welbornprod/new
 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())
示例#26
0
文件: python.py 项目: welbornprod/new
    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)
示例#27
0
    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)
示例#28
0
文件: python.py 项目: welbornprod/new
    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)
示例#29
0
文件: perl.py 项目: welbornprod/new
 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))