Exemplo n.º 1
0
    def download(self):
        """ Download a server. """
        self.p_main('Finding build on SpaceGDN')

        try:
            result = backend.get_builds(self.args.server, self.args.channel,
                                        self.args.version, self.args.build)

            if type(result) is not list:
                self.error(result)
                return

            if len(result) < 1:
                self.p_sub('Could not find any build')
                return

            channel, version, build = backend.find_latest_build(result)

            self.result(
                'Found build:', '{} {} {} {}'.format(self.args.server, channel,
                                                     version, build['build']))

            if utils.ask('Continue to download?', skip=self.args.no_confirm):
                utils.download(build['url'],
                               destination=self.args.output,
                               checksum=build['checksum'],
                               prefix=' ' * 4)
                self.p_blank()
                self.p_raw('Done!')
        except ValueError as error:
            self.p_sub(error.args[0])
Exemplo n.º 2
0
    def download(self):
        """ Download a server. """
        self.p_main("Finding build on SpaceGDN")

        try:
            result = backend.get_builds(self.args.server, self.args.channel, self.args.version, self.args.build)

            if type(result) is not list:
                self.error(result)
                return

            if len(result) < 1:
                self.p_sub("Could not find any build")
                return

            channel, version, build = backend.find_latest_build(result)

            self.result("Found build:", "{} {} {} {}".format(self.args.server, channel, version, build["build"]))

            if utils.ask("Continue to download?", skip=self.args.no_confirm):
                utils.download(build["url"], destination=self.args.output, checksum=build["checksum"], prefix=" " * 4)
                self.p_blank()
                self.p_raw("Done!")
        except ValueError as error:
            self.p_sub(error.args[0])
Exemplo n.º 3
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!')
Exemplo n.º 4
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!')
Exemplo n.º 5
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')
Exemplo n.º 6
0
def download(question, frmt, plugins, skip=False):
    """ Download plugins.

    This function does the questioning, and installing of each plugin.

    Parameters:
        question    The question to ask the user.
        frmt        The format to format the prefix with. Must support two
                    parameters: total and part.
        plugins     A list of the plugins to install.
        skip        Whether to skip the confirmation.

    """
    if common.ask(question, skip=skip):
        for i in range(len(plugins)):
            plugin = plugins[i]
            prefix = frmt.format(total=len(plugins), part=i + 1)
            download_plugin(plugin, prefix)
Exemplo n.º 7
0
def download(question, frmt, plugins, skip=False):
    """ Download plugins.

    This function does the questioning, and installing of each plugin.

    Parameters:
        question    The question to ask the user.
        frmt        The format to format the prefix with. Must support two
                    parameters: total and part.
        plugins     A list of the plugins to install.
        skip        Whether to skip the confirmation.

    """
    if common.ask(question, skip=skip):
        for i in range(len(plugins)):
            plugin = plugins[i]
            prefix = frmt.format(total=len(plugins), part=i+1)
            download_plugin(plugin, prefix)
Exemplo n.º 8
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')
Exemplo n.º 9
0
def test_ask_empty():
    """ Test common.ask when user answers nothing. """
    assert common.ask('') is True
    assert common.ask('', default=False) is False
    assert common.ask('', skip=True) is True
    assert common.ask('', default=False, skip=True) is False
Exemplo n.º 10
0
def test_ask_no():
    """ Test common.ask when user answers 'No'. """
    assert common.ask('') is False
    assert common.ask('', default=False) is False
Exemplo n.º 11
0
def test_ask_yes():
    """ Test common.ask when user answers 'Yes'. """
    assert common.ask('') is True
    assert common.ask('', default=False) is True
Exemplo n.º 12
0
def test_ask_empty():
    """ Test common.ask when user answers nothing. """
    assert common.ask('') is True
    assert common.ask('', default=False) is False
    assert common.ask('', skip=True) is True
    assert common.ask('', default=False, skip=True) is False
Exemplo n.º 13
0
def test_ask_no():
    """ Test common.ask when user answers 'No'. """
    assert common.ask('') is False
    assert common.ask('', default=False) is False
Exemplo n.º 14
0
def test_ask_yes():
    """ Test common.ask when user answers 'Yes'. """
    assert common.ask('') is True
    assert common.ask('', default=False) is True