Exemplo n.º 1
0
 def check_option(option, operation):
     key_option = vimanOptions.getKey4Option(option)
     key_operation = vimanOperations.getKey4Operation(operation)
     if not vimanOperations.operations[key_operation][0] in \
             vimanOptions.options[key_option][2]:
         print('error:invalid option `{}` for operation `{}`'.format(
             option, vimanOperations.operations[key_operation][0]),
               file=sys.stderr)
         # sys.exit(errno.EINVAL)
         raise vimanExcept.vimanExcept(errno.EINVAL,
                                       "Invalid option for operation!")
Exemplo n.º 2
0
 def removeByName(name):
     path = os.path.join(vimanGitWrapper.DIR_PLUGIN, name)
     if not os.path.isdir(path):
         print(
             'error:don\'t exist directory `{}`!'.format(path),
             file=sys.stderr)
         # sys.exit(errno.ENOENT)
         raise vimanExcept.vimanExcept(
             errno.ENOENT, "Don't exist directory `{}`".format(path))
     shutil.rmtree(path, ignore_errors=True)
     return 0
Exemplo n.º 3
0
 def install(url, recipe):
     '''
     @brief install a vim plugin to .vim/bundle by git from url
     @param url url of git repository
     '''
     if not os.path.isdir(vimanGitWrapper.DIR_PLUGIN):
         os.makedirs(vimanGitWrapper.DIR_PLUGIN)
     Repo.clone_from(url, os.path.join(
         vimanGitWrapper.DIR_PLUGIN,
         vimanUtils.vimanUtils.getPlugin4Url(url)))
     ret = os.system(recipe)
     if ret != 0:
         raise vimanExcept.vimanExcept(ret, "System scripts failed!")
Exemplo n.º 4
0
 def upgradeByYml(ymlName):
     if not os.path.isfile(ymlName):
         print(
             'error:don\'t exist file `{}`!'.format(ymlName),
             file=sys.stderr)
         # sys.exit(errno.EINVAL)
         raise vimanExcept.vimanExcept(
             errno.EINVAL, "Don't exist yml file `{}`!".format(ymlName))
     with open(ymlName) as f:
         yml = yaml.safe_load(f)
         if yml:
             for v in yml.values():
                 vimanGitWrapper.upgrade(v['url'])
Exemplo n.º 5
0
 def upgradeByName(name):
     '''
     @brief upgrade plugin by plugin name
     '''
     path = os.path.join(vimanGitWrapper.DIR_PLUGIN, name)
     if not os.path.isdir(path):
         print(
             'error:don\'t exist directory `{}`!'.format(path),
             file=sys.stderr)
         # sys.exit(errno.ENOENT)
         raise vimanExcept.vimanExcept(
             errno.ENOENT, "Don't exist path `{}`!".format(path))
     repo = Repo(path)
     r = remote.Remote(repo, 'origin')
     r.pull()
     return 0
Exemplo n.º 6
0
 def installByYml(ymlName):
     '''
     @brief install plugins by yml
     @param ymlName yml file name
     '''
     if not os.path.isfile(ymlName):
         print(
             'error:don\'t exist file `{}`!'.format(ymlName),
             file=sys.stderr)
         # sys.exit(errno.EINVAL)
         raise vimanExcept.vimanExcept(
             errno.EINVAL, "Don't exist yml file `{}`!".format(ymlName))
     with open(ymlName) as f:
         yml = yaml.safe_load(f)
         if yml:
             for v in yml.values():
                 vimanGitWrapper.install(v['url'], v['recipe'])
Exemplo n.º 7
0
    def __init__(self, args):
        '''
        @brief parse command line arguments
        @param args sys.argv[1:]
        @retval generated object
        '''
        options_short = \
             vimanOperations.getOperationsShort() +\
             vimanOptions.getOptionShort()
        # print(options_short)
        options_short = ''.join(options_short)
        options_long = \
                vimanOperations.getOperationsLong() +\
                vimanOptions.getOptionLong()
        # print(options_long)

        opts, rest = getopt.getopt(args, options_short, options_long)

        self.targets = rest  # targets git repository url

        opts = map(lambda opt: opt[0].replace('-', ''), opts)
        # print(list(opts))

        operations = vimanOperations.getOperations()
        options = vimanOptions.getOptions()

        opts_operations = list(
            filter(lambda opt: opt in operations, copy.deepcopy(opts)))
        # print(opts_operations)
        opts_options = list(
            filter(lambda opt: opt in options, copy.deepcopy(opts)))

        # check operations
        if not 1 == len(opts_operations):
            print('error: only one operation may be used at a time!',
                  file=sys.stderr)
            # sys.exit(errno.EINVAL)
            raise vimanExcept.vimanExcept(errno.EINVAL,
                                          "Multiple operations at one time!")

        # check options
        def check_option(option, operation):
            key_option = vimanOptions.getKey4Option(option)
            key_operation = vimanOperations.getKey4Operation(operation)
            if not vimanOperations.operations[key_operation][0] in \
                    vimanOptions.options[key_option][2]:
                print('error:invalid option `{}` for operation `{}`'.format(
                    option, vimanOperations.operations[key_operation][0]),
                      file=sys.stderr)
                # sys.exit(errno.EINVAL)
                raise vimanExcept.vimanExcept(errno.EINVAL,
                                              "Invalid option for operation!")

        for opt in opts_options:
            check_option(opt, opts_operations[0])

        if len(opts_operations[0]) > 1:
            # operations
            self.operations = vimanOperations.operations[opts_operations[0]][0]
        else:
            self.operations = opts_operations[0]

        opts_options_short = filter(lambda o: 1 == len(o),
                                    copy.deepcopy(opts_options))
        opts_options_long = filter(lambda o: 1 < len(o),
                                   copy.deepcopy(opts_options))
        opts_options_long = map(lambda l: vimanOptions.operations[ops][0],
                                opts_options_long)
        opts_options = list(opts_options_short) + list(opts_options_long)
        self.options = opts_options  # options
Exemplo n.º 8
0
def main(argv):
    '''
    @brief viman for vim plugins manager
    @return error
    '''

    parser = vimanArgParser.vimanArgParser(argv[1:])

    if parser.operations[0] == vimanArgParser.vimanOperations.\
            operations['sync'][0]:
        # sync
        if vimanArgParser.vimanOptions.options['file'][0] in parser.options:
            # yml file
            for yml_file in parser.targets:
                vimanGitWrapper.vimanGitWrapper.installByYml(yml_file)
        elif vimanArgParser.vimanOptions.options['current'][0] in \
                parser.options:
            # current yml string
            for yml in parser.targets:
                vimanGitWrapper.vimanGitWrapper.installByCurrent(yml)
        elif vimanArgParser.vimanOptions.options['sysupgrade'][0] in \
                parser.options:
            # sysupgrade
            vimanGitWrapper.vimanGitWrapper.upgradeByYml(
                vimanYamlWrapper.vimanYamlWrapper.ymlDefault)
        elif vimanArgParser.vimanOptions.options['name'][0] in \
                parser.options:
            # install by name
            for name in parser.targets:
                vimanGitWrapper.vimanGitWrapper.install_by_name(name)
        else:
            for target in parser.targets:
                vimanGitWrapper.vimanGitWrapper.install(target, '')

    elif parser.operations[0] == vimanArgParser.vimanOperations.\
            operations['remove'][0]:
        if vimanArgParser.vimanOptions.options['file'][0] in parser.options:
            # yml file
            for yml_file in parser.targets:
                vimanGitWrapper.vimanGitWrapper.removeByYml(yml_file)
        elif vimanArgParser.vimanOptions.options['name'][0] in parser.options:
            for name in parser.targets:
                vimanGitWrapper.vimanGitWrapper.removeByName(name)

        else:
            for target in parser.targets:
                vimanGitWrapper.vimanGitWrapper.remove(target)

    elif parser.operations[0] == vimanArgParser.vimanOperations.\
            operations['upgrade'][0]:
        if vimanArgParser.vimanOptions.options['file'][0] in parser.options:
            # upgrade by yml file
            for yml_file in parser.targets:
                vimanGitWrapper.vimanGitWrapper.upgradeByYml(yml_file)
        elif vimanArgParser.vimanOptions.options['recursive'][0] in \
                parser.options:
            # upgrade recursive
            vimanGitWrapper.vimanGitWrapper.upgradeByYml(
                vimanYamlWrapper.vimanYamlWrapper.ymlDefault)
        for target in parser.targets:
            vimanGitWrapper.vimanGitWrapper.upgrade(target)
    elif parser.operations[0] == vimanArgParser.vimanOperations.\
            operations['query'][0]:
        yml = vimanYamlWrapper.vimanYamlWrapper.loadYml()
        if yml is None:
            print(yml)
        else:
            for name in yml:
                print(name)
    elif parser.operations[0] == vimanArgParser.vimanOperations.\
            operations['version'][0]:
        print('{}-{}'.format(PROGRAM, VERSION))
    elif parser.operations[0] == vimanArgParser.vimanOperations.\
            operations['help'][0]:
        # help
        vimanArgParser.vimanArgParser.printUsage()
    else:
        # invalid operation
        print('error:invalid operation `{}`!'.format(parser.operations[0]),
              file=sys.stderr)
        # return errno.EINVAL
        raise vimanExcept.vimanExcept(errno.EINVAL, "Invalid operation!")
    return 0