示例#1
0
    def info(self):
        """ Display info about a plugin. """
        query = self.args.plugins
        self.p_main('Finding `{}` on BukGet'.format(query))

        plugin = backend.info(self.server, query)
        if plugin is None:
            self.p_sub('Could not find `{}`'.format(query))
            return

        self.p_main('Found {}:'.format(plugin['plugin_name']))
        self.p_blank()

        website = plugin['website']
        if len(website) == 0:
            website = plugin['dbo_page']
        authors = common.list_names(plugin['authors'])
        categories = common.list_names(plugin['categories'])
        stage = plugin['stage']
        name = plugin['plugin_name']
        desciption = plugin['description'].strip()

        self.p_sub('Name:        {}', name)
        self.p_sub('Description: {}', desciption)
        self.p_sub('Authors:     {}', authors)
        self.p_sub('Website:     {}', website)
        self.p_sub('Categories:  {}', categories)
        self.p_sub('Stage:       {}', stage)

        self.p_blank()
        self.p_sub('Versions:')
        self.p_sub('    R - Release, B - Beta, A - Alpha')

        versions = plugin['versions']
        # Sorting
        if self.args.size >= 0:
            versions = versions[:min(self.args.size, len(versions))]
        else:
            versions = versions[max(self.args.size, -len(versions)):]

        # Formatting
        max_len = max([len(v['version']) for v in versions])
        frmt = '({{:1}})    {{:>{}}} - {{}}'.format(max_len)

        for version in versions:
            line = frmt.format(version['type'].upper()[0], version['version'],
                               common.list_names(version['game_versions']))
            self.p_sub(line)

        self.p_blank()
示例#2
0
    def info(self):
        """ Display info about a plugin. """
        query = self.args.plugins
        self.p_main('Finding `{}` on BukGet'.format(query))

        plugin = backend.info(self.server, query)
        if plugin is None:
            self.p_sub('Could not find `{}`'.format(query))
            return

        self.p_main('Found {}:'.format(plugin['plugin_name']))
        self.p_blank()

        website = plugin['website']
        if len(website) == 0:
            website = plugin['dbo_page']
        authors = common.list_names(plugin['authors'])
        categories = common.list_names(plugin['categories'])
        stage = plugin['stage']
        name = plugin['plugin_name']
        desciption = plugin['description'].strip()

        self.p_sub('Name:        {}', name)
        self.p_sub('Description: {}', desciption)
        self.p_sub('Authors:     {}', authors)
        self.p_sub('Website:     {}', website)
        self.p_sub('Categories:  {}', categories)
        self.p_sub('Stage:       {}', stage)

        self.p_blank()
        self.p_sub('Versions:')
        self.p_sub('    R - Release, B - Beta, A - Alpha')

        versions = plugin['versions']
        # Sorting
        if self.args.size >= 0:
            versions = versions[:min(self.args.size, len(versions))]
        else:
            versions = versions[max(self.args.size, -len(versions)):]

        # Formatting
        max_len = max([len(v['version']) for v in versions])
        frmt = '({{:1}})    {{:>{}}} - {{}}'.format(max_len)

        for version in versions:
            line = frmt.format(version['type'].upper()[0], version['version'],
                               common.list_names(version['game_versions']))
            self.p_sub(line)

        self.p_blank()
示例#3
0
 def result(self, head, results):
     """ Print results with head. """
     self.p_main(head)
     self.p_blank()
     if type(results) is str:
         self.p_sub(results)
     elif len(results) >= 1:
         self.p_sub(utils.list_names(results))
     else:
         self.p_sub('No results...')
     self.p_blank()
示例#4
0
 def result(self, head, results):
     """ Print results with head. """
     self.p_main(head)
     self.p_blank()
     if type(results) is str:
         self.p_sub(results)
     elif len(results) >= 1:
         self.p_sub(utils.list_names(results))
     else:
         self.p_sub("No results...")
     self.p_blank()
示例#5
0
    def download(self):
        """ Download plugins. """
        self.args.ignored = [e.lower() for e in self.args.ignored]

        self.p_main('Finding installed plugins')
        installed = backend.list_plugins()

        self.p_main('Finding plugins on BukGet')
        plugins = backend.dependencies(self.args.server,
                                       self.args.plugins,
                                       self.args.version,
                                       deps=self.args.resolve_dependencies)

        to_install = list()
        for plugin in plugins:
            if plugin['plugin_name'].lower() in self.args.ignored:
                self.p_sub("Ignoring {}", plugin['plugin_name'])
                continue
            if len(plugin['versions']) < 1:
                self.p_sub("Could not find any versions for {}",
                           plugin['plugin_name'])
                continue
            for i_plugin in installed:
                if i_plugin['slug'] == plugin['slug'] \
                        and not i_plugin['versions'][0]['version'] > \
                        plugin['versions'][0]['version']:
                    self.p_sub("{} is allready installed, and up to date",
                               plugin['plugin_name'])
                    break
            else:
                to_install.append(plugin)
        plugins = to_install

        if len(plugins) < 1:
            self.p_main('No plugins left to install')
            return

        self.p_main('Plugins to install:')
        self.p_blank()
        self.p_sub(
            common.list_names([
                p['plugin_name'] + '#' + p['versions'][0]['version']
                for p in plugins
            ]))
        self.p_blank()

        backend.download(
            'Continue to download?',
            '({{part:>{}}}/{{total}}) '.format(len(str(len(plugins)))),
            plugins, self.args.no_confirm)

        self.p_blank()
        self.p_raw('Done!')
示例#6
0
    def download(self):
        """ Download plugins. """
        self.args.ignored = [e.lower() for e in self.args.ignored]

        self.p_main('Finding installed plugins')
        installed = backend.list_plugins()

        self.p_main('Finding plugins on BukGet')
        plugins = backend.dependencies(self.args.server, self.args.plugins,
                                       self.args.version,
                                       deps=self.args.resolve_dependencies)

        to_install = list()
        for plugin in plugins:
            if plugin['plugin_name'].lower() in self.args.ignored:
                self.p_sub("Ignoring {}", plugin['plugin_name'])
                continue
            if len(plugin['versions']) < 1:
                self.p_sub("Could not find any versions for {}",
                           plugin['plugin_name'])
                continue
            for i_plugin in installed:
                if i_plugin['slug'] == plugin['slug'] \
                        and not i_plugin['versions'][0]['version'] > \
                        plugin['versions'][0]['version']:
                    self.p_sub("{} is allready installed, and up to date",
                               plugin['plugin_name'])
                    break
            else:
                to_install.append(plugin)
        plugins = to_install

        if len(plugins) < 1:
            self.p_main('No plugins left to install')
            return

        self.p_main('Plugins to install:')
        self.p_blank()
        self.p_sub(common.list_names([p['plugin_name'] + '#'
                                     + p['versions'][0]['version']
                                     for p in plugins]))
        self.p_blank()

        backend.download('Continue to download?',
                         '({{part:>{}}}/{{total}}) '.format(
                             len(str(len(plugins)))),
                         plugins, self.args.no_confirm)

        self.p_blank()
        self.p_raw('Done!')
示例#7
0
    def update(self):
        """ Update installed plugins. """
        self.args.ignored = [e.lower() for e in self.args.ignored]

        self.p_main('Finding installed plugins')

        installed = backend.list_plugins()

        self.p_main('Looking up versions on BukGet')

        to_update = list()
        for i in installed:
            if i['plugin_name'].lower() in self.args.ignored:
                self.p_sub('Ignoring {}', i['plugin_name'])
                continue
            n_version = utils.select_newest_version(i, self.args.version)
            if n_version is None:
                continue
            i_version = utils.select_installed_version(i)
            if n_version['version'] > i_version['version']:
                to_update.append(i)

        self.p_main('Plugins to update:')
        self.p_blank()

        if len(to_update) < 1:
            self.p_sub('All plugins are up to date!')
            self.p_sub(('Maybe you want a pre-release? Try passing --beta, '
                        '--alpha or even --latest as command options'))
            self.p_blank()
            return

        self.p_sub(
            common.list_names([
                p['plugin_name'] + '#' + p['versions'][0]['version']
                for p in to_update
            ]))
        self.p_blank()

        if common.ask('Continue to update?', skip=self.args.no_confirm):
            prefix_format = '({{part:>{}}}/{{total}}) '.format(
                len(str(len(to_update))))
            for i in range(len(to_update)):
                plugin = to_update[i]
                os.remove(plugin['installed_file'])
                prefix = prefix_format.format(total=len(to_update), part=i + 1)
                backend.download_plugin(plugin, prefix)
            self.p_blank()
            self.p_raw('Done!')
示例#8
0
    def update(self):
        """ Update installed plugins. """
        self.args.ignored = [e.lower() for e in self.args.ignored]

        self.p_main('Finding installed plugins')

        installed = backend.list_plugins()

        self.p_main('Looking up versions on BukGet')

        to_update = list()
        for i in installed:
            if i['plugin_name'].lower() in self.args.ignored:
                self.p_sub('Ignoring {}',
                           i['plugin_name'])
                continue
            n_version = utils.select_newest_version(i, self.args.version)
            if n_version is None:
                continue
            i_version = utils.select_installed_version(i)
            if n_version['version'] > i_version['version']:
                to_update.append(i)

        self.p_main('Plugins to update:')
        self.p_blank()

        if len(to_update) < 1:
            self.p_sub('All plugins are up to date!')
            self.p_sub(('Maybe you want a pre-release? Try passing --beta, '
                        '--alpha or even --latest as command options'))
            self.p_blank()
            return

        self.p_sub(common.list_names([p['plugin_name'] + '#'
                                      + p['versions'][0]['version']
                                      for p in to_update]))
        self.p_blank()

        if common.ask('Continue to update?', skip=self.args.no_confirm):
            prefix_format = '({{part:>{}}}/{{total}}) '.format(
                len(str(len(to_update))))
            for i in range(len(to_update)):
                plugin = to_update[i]
                os.remove(plugin['installed_file'])
                prefix = prefix_format.format(total=len(to_update), part=i+1)
                backend.download_plugin(plugin, prefix)
            self.p_blank()
            self.p_raw('Done!')
示例#9
0
def test_list_names():
    """ Test common.list_names. """
    assert common.list_names(['one']) == 'one'
    assert common.list_names(['one', 'two']) == 'one and two'
    assert common.list_names(['one', 'two'],
                             last_separator=' + ') == 'one + two'
    assert common.list_names(['one', 'two', 'three']) == 'one, two and three'
    assert common.list_names(['one', 'two', 'three'],
                             last_separator=' + ') == 'one, two + three'
    assert common.list_names(['one', 'two', 'three'],
                             separator='; ') == 'one; two and three'
    assert common.list_names(['one', 'two', 'three'],
                             separator='; ',
                             last_separator=' + ') == 'one; two + three'
示例#10
0
def test_list_names():
    """ Test common.list_names. """
    assert common.list_names(['one']) == 'one'
    assert common.list_names(['one', 'two']) == 'one and two'
    assert common.list_names(['one', 'two'],
                             last_separator=' + ') == 'one + two'
    assert common.list_names(['one', 'two', 'three']) == 'one, two and three'
    assert common.list_names(['one', 'two', 'three'],
                             last_separator=' + ') == 'one, two + three'
    assert common.list_names(['one', 'two', 'three'],
                             separator='; ') == 'one; two and three'
    assert common.list_names(['one', 'two', 'three'],
                             separator='; ',
                             last_separator=' + ') == 'one; two + three'
示例#11
0
    def run(self):
        """ Run the command. """
        if self.args.input is not stdin:
            self.p_main('Parsing file and finding plugins and servers')

        document = json.loads('\n'.join(self.args.input))

        plugins = document['plugins']
        remote_plugins = p_backend.find_versions([
            (e['slug'], e['version-slug']) for e in plugins
        ])

        servers = document['servers']
        remote_servers = s_backend.find_servers([e['id'] for e in servers])

        self.parse_plugins(plugins, remote_plugins)
        self.parse_servers(servers, remote_servers)

        self.p_main('Files to download:')
        self.p_blank()
        self.p_sub(common.list_names([i[0] for i in self.to_download]))
        self.p_blank()

        if not common.ask('Do you want to continue?',
                          skip=self.args.no_confirm):
            return

        prefix = '({{part:>{}}}/{}) '.format(len(str(len(self.to_download))),
                                             len(self.to_download))
        for i in range(len(self.to_download)):
            jar = self.to_download[i]
            this_prefix = prefix.format(part=i + 1)
            destination = self.args.destination + '/' + jar[0]
            if jar[1].endswith('.zip'):
                destination = jar[1].split('/')[-1]
            common.download(jar[1],
                            destination=destination,
                            checksum=jar[2],
                            prefix=this_prefix)
            if jar[1].endswith('.zip'):
                print(' ' * len(this_prefix) + "Unzipping...", end=' ')
                p_backend.unzip_plugin(destination,
                                       '/'.join(jar[0].split('/')[:-1]) + '/')
                os.remove(destination)
                print('Success')
示例#12
0
    def run(self):
        """ Run the command. """
        if self.args.input is not stdin:
            self.p_main('Parsing file and finding plugins and servers')

        document = json.loads('\n'.join(self.args.input))

        plugins = document['plugins']
        remote_plugins = p_backend.find_versions(
            [(e['slug'], e['version-slug'])
             for e in plugins])

        servers = document['servers']
        remote_servers = s_backend.find_servers([e['id'] for e in servers])

        self.parse_plugins(plugins, remote_plugins)
        self.parse_servers(servers, remote_servers)

        self.p_main('Files to download:')
        self.p_blank()
        self.p_sub(common.list_names([i[0] for i in self.to_download]))
        self.p_blank()

        if not common.ask('Do you want to continue?',
                          skip=self.args.no_confirm):
            return

        prefix = '({{part:>{}}}/{}) '.format(
            len(str(len(self.to_download))), len(self.to_download))
        for i in range(len(self.to_download)):
            jar = self.to_download[i]
            this_prefix = prefix.format(part=i+1)
            destination = self.args.destination + '/' + jar[0]
            if jar[1].endswith('.zip'):
                destination = jar[1].split('/')[-1]
            common.download(jar[1], destination=destination, checksum=jar[2],
                            prefix=this_prefix)
            if jar[1].endswith('.zip'):
                print(' ' * len(this_prefix) + "Unzipping...", end=' ')
                p_backend.unzip_plugin(destination,
                                       '/'.join(jar[0].split('/')[:-1]) + '/')
                os.remove(destination)
                print('Success')
示例#13
0
    def run(self):
        """ Run the command. """
        self.p_main('Saving {} to {}'.format(
            common.list_names(self.args.types), self.args.output.name))

        plugins = dict()
        servers = dict()

        if 'plugins' in self.args.types:
            self.p_main('Finding plugins')
            for plugin in p_backend.list_plugins():
                version = p_utils.select_installed_version(plugin)
                plugins[plugin['installed_file']] = (plugin['slug'],
                                                     version['slug'])
        if 'servers' in self.args.types:
            self.p_main('Finding servers')
            servers = s_backend.list_servers()

        self.p_main('Writing file')
        document = dict()
        document['servers'] = list()
        for file, key in servers.items():
            server = dict()
            server['id'] = key
            server['file'] = file

            document['servers'].append(server)

        document['plugins'] = list()
        for file, (slug, version) in plugins.items():
            plugin = dict()
            plugin['file'] = file
            plugin['slug'] = slug
            plugin['version-slug'] = version

            document['plugins'].append(plugin)

        self.args.output.write(json.dumps(document))
        self.args.output.write('\n')
示例#14
0
    def run(self):
        """ Run the command. """
        self.p_main('Saving {} to {}'.format(
            common.list_names(self.args.types), self.args.output.name))

        plugins = dict()
        servers = dict()

        if 'plugins' in self.args.types:
            self.p_main('Finding plugins')
            for plugin in p_backend.list_plugins():
                version = p_utils.select_installed_version(plugin)
                plugins[plugin['installed_file']] = (plugin['slug'],
                                                     version['slug'])
        if 'servers' in self.args.types:
            self.p_main('Finding servers')
            servers = s_backend.list_servers()

        self.p_main('Writing file')
        document = dict()
        document['servers'] = list()
        for file, key in servers.items():
            server = dict()
            server['id'] = key
            server['file'] = file

            document['servers'].append(server)

        document['plugins'] = list()
        for file, (slug, version) in plugins.items():
            plugin = dict()
            plugin['file'] = file
            plugin['slug'] = slug
            plugin['version-slug'] = version

            document['plugins'].append(plugin)

        self.args.output.write(json.dumps(document))
        self.args.output.write('\n')