Exemplo n.º 1
0
 def _grab_version(self):
     """Set the version to a non-development version."""
     original_version = self.vcs.version
     logger.debug("Extracted version: %s", original_version)
     if original_version is None:
         logger.critical('No version found.')
         sys.exit(1)
     suggestion = utils.cleanup_version(original_version)
     new_version = utils.ask_version("Enter version", default=suggestion)
     if not new_version:
         new_version = suggestion
     self.data['original_version'] = original_version
     self.data['new_version'] = new_version
Exemplo n.º 2
0
    def _update_version(self):
        """Ask for and store a new dev version string."""
        #current = self.vcs.version
        current = self.data['new_version']

        # Clean it up to a non-development version.
        current = utils.cleanup_version(current)
        # Try to make sure that the suggestion for next version after
        # 1.1.19 is not 1.1.110, but 1.1.20.
        current_split = current.split('.')
        major = '.'.join(current_split[:-1])
        minor = current_split[-1]
        try:
            minor = int(minor) + 1
            suggestion = '.'.join([major, str(minor)])
        except ValueError:
            # Fall back on simply updating the last character when it is
            # an integer.
            try:
                last = int(current[-1]) + 1
                suggestion = current[:-1] + str(last)
            except ValueError:
                logger.warn("Version does not end with a number, so we can't "
                            "calculate a suggestion for a next version.")
                suggestion = None
        print("Current version is %r" % current)
        q = "Enter new development version ('.dev0' will be appended)"
        version = utils.ask_version(q, default=suggestion)
        if not version:
            version = suggestion
        if not version:
            logger.error("No version entered.")
            sys.exit()

        self.data['new_version'] = version
        dev_version = self.data['dev_version_template'] % self.data
        self.data['dev_version'] = dev_version
        logger.info("New version string is %r",
                    dev_version)

        self.vcs.version = self.data['dev_version']
Exemplo n.º 3
0
def main():

    #
    # Ask about the project
    #

    here = os.path.dirname(os.path.realpath(__file__))

    project = ask_version('\nProject name')

    print('\nChoose a license, options are:')
    for index, license in enumerate(LICENSES):
        print('{}) {}'.format(index, license[0]))

    license = ask_version('Pick a version', '0')
    while 0 > int(license) or int(license) >= len(LICENSES):
        license = ask_version('Wrong version, try again', '0')

    license = LICENSES[int(license)]
    license_file = os.path.join(here, 'licenses', license[0])

    #
    # Create folder and copy license
    #

    project_dir = os.path.join(os.path.abspath(os.getcwd()), project)
    if not ask('\nCreate this project directory:\n{}'.format(project_dir)):
        print('Exit')
        sys.exit()

    try:
        os.mkdir(project)
    except FileExistsError:
        print('Directory "{}" already exits!!!'.format(project_dir))
        sys.exit(1)
    copy(license_file, os.path.join(project, 'LICENSE'))

    #
    # Render the templates
    #
    variables = {'project': project,
                 'license': license[1]}

    templates_dir = os.path.join(here, 'templates')
    env = Environment(loader=FileSystemLoader(templates_dir),
                      keep_trailing_newline=True)

    for path, subdirs, files in os.walk(templates_dir):
        if '__pycache__' in subdirs:
            subdirs.remove('__pycache__')

        for name in files:
            if should_skip_file(name):
                continue

            in_path = os.path.relpath(os.path.join(path, name), templates_dir)
            logging.info('Render {}'.format(in_path))
            out_path = os.path.join(project_dir, replace(in_path, variables))

            out_dir = os.path.dirname(out_path)
            if not os.path.exists(out_dir):
                os.makedirs(out_dir)

            render(env, in_path, out_path, variables)

    #
    # Init a git repo
    #

    logging.info('Create git repository')
    run('git init', cwd=project)
    run('git add .', cwd=project)
    run('git commit -a -m "Initial commit"', cwd=project)
    run('git checkout -b develop', cwd=project)

    # Create github repo
    if ask('Create a GitHub repo'):
        user = '******'
        pw = run('pass github | head -n 1', stdout=Capture()).stdout.text.strip()
        requests.post('https://api.github.com/user/repos',
                      auth=(user, pw),
                      data=json.dumps({'name': project,
                                       'homepage': 'http://{}.github.io/{}'.format(user, project)}))

        run('git remote add origin [email protected]:{}/{}.git'.format(user, project), cwd=project)
        run('git push --all --set-upstream origin', cwd=project)