def quickly(project_template, project_dir, command_args, shell_completion=False):
    """Create a new quickly template from an existing one"""

    # We have nothing for this
    if shell_completion:
        return("")

    project_template = command_args[0]
    if len(command_args) < 2:
        cmd = commands_module.get_command('quickly', project_template)
        templatetools.usage_error(_("No destination template name provided."), cmd=cmd, template=project_template)

    destination_path = os.path.expanduser("~/quickly-templates/")
    # create ~/quickly-templates/ if needed
    if not os.path.exists(destination_path):
        os.makedirs(destination_path)

    template_destination_path = destination_path + command_args[1]
    if os.path.exists(template_destination_path):
        print _("%s already exists." % template_destination_path)
        return 1

    if not os.path.exists(template_destination_path):
        print _("Copy %s to create new %s template") % (project_template, template_destination_path)

    try:
        template_source_path = tools.get_template_directory(project_template)
    except tools.template_path_not_found, e:
        print(e)
        return 1
Exemple #2
0
def get_template_path_from_project():
    """Get current template path when in a project"""
    if not configurationhandler.project_config:
        configurationhandler.loadConfig()
    return os.path.abspath(
        tools.get_template_directory(
            configurationhandler.project_config['template']))
Exemple #3
0
def get_project_and_template_versions(template_name):
    """Return project and template version"""

    # take template version. Default is current Quickly version
    template_version = quicklyconfig.__version__
    template_path = tools.get_template_directory(template_name)
    file_command_parameters = file(
        os.path.join(template_path, 'commandsconfig'), 'rb')
    for line in file_command_parameters:
        fields = line.split(
            '#'
        )[0]  # Suppress commentary after the value in configuration file and in full line
        fields = fields.split('=')  # Separate variable from value
        # normally, we have two fields in "fields"
        if len(fields) == 2:
            targeted_property = fields[0].strip()
            value = fields[1].strip()
            if targeted_property == 'TEMPLATE_VERSION':
                template_version = value
                break

    # get current project version for this template. Default is no migration (ie take current version)
    configurationhandler.loadConfig()
    # if this project corresponding natively to this template
    if configurationhandler.project_config['template'] == template_name:
        try:
            project_version = configurationhandler.project_config['version']
        except KeyError:  # it was called format in quickly 0.2.x
            project_version = configurationhandler.project_config['format']
            configurationhandler.project_config['version'] = project_version
            del configurationhandler.project_config['format']
            configurationhandler.saveConfig()
    else:
        try:
            project_version = configurationhandler.project_config[
                'version_%s' % template_name]
        except KeyError:  # initialize with an empty project version to force first upgrade
            project_version = ''

    return (project_version, template_version)
Exemple #4
0
    def allow_template(self, template_in_cli):
        # get completion from this template
        if template_in_cli is None:
            return False
        if template_in_cli == self.template:
            return True

        # check if parent template can provide completion
        parent = None
        template_path = tools.get_template_directory(template_in_cli)

        try:
            files_command_parameters = file(
                os.path.join(template_path, "commandsconfig"), 'rb')
            for line in files_command_parameters:
                # Suppress commentary after the value in configuration
                # file and in full line.
                fields = line.split('#')[0]
                fields = fields.split('=')  # Separate variable from value
                reg_result = re.search('\[(.*)\]', fields[0].strip())
                if reg_result:
                    parent = reg_result.group(1)

                if len(fields) == 2:
                    if fields[0].strip() == 'IMPORT':
                        imports = [x.strip() for x in fields[1].split(';')]
                        if self.name in imports:
                            if parent == self.template:
                                return True

            # finished reading commandsconfig
            return False

        except (OSError, IOError):
            # cannot read commandsconfig
            return False
Exemple #5
0
def get_project_and_template_versions(template_name):
    """Return project and template version"""

    # take template version. Default is current Quickly version
    template_version = quicklyconfig.__version__
    template_path = tools.get_template_directory(template_name)
    file_command_parameters = file(os.path.join(template_path, 'commandsconfig'), 'rb')
    for line in file_command_parameters: 
        fields = line.split('#')[0] # Suppress commentary after the value in configuration file and in full line
        fields = fields.split('=') # Separate variable from value
        # normally, we have two fields in "fields"
        if len(fields) == 2:
            targeted_property = fields[0].strip()
            value = fields[1].strip()
            if targeted_property == 'TEMPLATE_VERSION':
                template_version = value
                break
    
    # get current project version for this template. Default is no migration (ie take current version)
    configurationhandler.loadConfig()
    # if this project corresponding natively to this template
    if configurationhandler.project_config['template'] == template_name:
        try:
            project_version = configurationhandler.project_config['version']
        except KeyError: # it was called format in quickly 0.2.x
            project_version = configurationhandler.project_config['format']
            configurationhandler.project_config['version'] = project_version
            del configurationhandler.project_config['format']
            configurationhandler.saveConfig()
    else:
        try:
            project_version = configurationhandler.project_config['version_%s' % template_name]
        except KeyError: # initialize with an empty project version to force first upgrade
            project_version = ''

    return (project_version, template_version)
Exemple #6
0
    def allow_template(self, template_in_cli):
        # get completion from this template
        if template_in_cli is None:
            return False
        if template_in_cli == self.template:
            return True
        
        # check if parent template can provide completion
        parent = None
        template_path = tools.get_template_directory(template_in_cli)

        try:
            files_command_parameters = file(
                os.path.join(template_path, "commandsconfig"), 'rb')
            for line in files_command_parameters:
                # Suppress commentary after the value in configuration
                # file and in full line.
                fields = line.split('#')[0]
                fields = fields.split('=') # Separate variable from value
                reg_result = re.search('\[(.*)\]', fields[0].strip())
                if reg_result:
                    parent = reg_result.group(1)

                if len(fields) == 2:
                    if fields[0].strip() == 'IMPORT':
                        imports = [x.strip() for x in fields[1].split(';')]
                        if self.name in imports:
                            if parent == self.template:
                                return True

            # finished reading commandsconfig
            return False

        except (OSError, IOError):
            # cannot read commandsconfig
            return False
Exemple #7
0
def get_template_path_from_project():
    """Get current template path when in a project"""
    if not configurationhandler.project_config:
        configurationhandler.loadConfig()
    return os.path.abspath(tools.get_template_directory(configurationhandler.project_config['template']))