def cmd_check(args): proj_name = args['<project_name>'] cmd_show(args, short=True) print print Fore.GREEN + Style.BRIGHT + 'Searching for updates on PyPI...' print pkg_dist_version = get_pkg_res().get_distribution(proj_name).version pypi_rel = get_pypi_releases(proj_name) if pypi_rel: pypi_last_version = get_pkg_res().parse_version(pypi_rel[0]) current_version = get_pkg_res().parse_version(pkg_dist_version) try: version_index = pypi_rel.index(pkg_dist_version) except: version_index = len(pypi_rel) for version in pypi_rel[0:version_index+3]: print Fore.WHITE + Style.BRIGHT + ' Version %s' % version, if version==pypi_rel[0]: print Fore.BLUE + Style.BRIGHT + '[last version]', if version==pkg_dist_version: print Fore.GREEN + Style.BRIGHT + '[your version]', print print if pypi_last_version > current_version: print Fore.RED + Style.BRIGHT + \ ' Your version is outdated, you\'re using ' + \ Fore.WHITE + Style.BRIGHT + 'v.%s,' % pkg_dist_version + \ Fore.RED + Style.BRIGHT + \ ' but the last version is ' + Fore.WHITE + Style.BRIGHT + \ 'v.%s !' % pypi_rel[0] if pypi_last_version == current_version: print Fore.GREEN + Style.BRIGHT + ' Your version is updated !' if pypi_last_version < current_version: print Fore.YELLOW + Style.BRIGHT + \ ' Your version newer than the version available at PyPI !' print Fore.YELLOW + Style.BRIGHT + ' You\'re using ' + \ Fore.WHITE + Style.BRIGHT + 'v.%s,' % pkg_dist_version + \ Fore.YELLOW + Style.BRIGHT + \ ' but the last version in PyPI ' + Fore.WHITE + Style.BRIGHT + \ 'v.%s !' % pypi_rel[0] else: print 'No versions found on PyPI !'
def releases(dist_name): """ This is the /pypi/releases/<dist_name> entry point, it is the interface between Stallion and the PyPI RPC service when checking for updates. :param dist_name: the package name (distribution name). """ pkg_res = get_pkg_res() data = {} pkg_dist_version = pkg_res.get_distribution(dist_name).version pypi_rel = get_pypi_releases(dist_name) data["dist_name"] = dist_name data["pypi_info"] = pypi_rel data["current_version"] = pkg_dist_version if pypi_rel: pypi_last_version = pkg_res.parse_version(pypi_rel[0]) current_version = pkg_res.parse_version(pkg_dist_version) last_version = pkg_dist_version.lower() != pypi_rel[0].lower() data["last_is_great"] = pypi_last_version > current_version data["last_version_differ"] = last_version if data["last_is_great"]: DIST_PYPI_CACHE.add(dist_name.lower()) else: try: DIST_PYPI_CACHE.remove(dist_name.lower()) except KeyError: pass return render_template('pypi_update.html', **data)
def check_pypi_update(dist_name): """ Just check for updates and return a json with the attribute "has_update". :param dist_name: distribution name :rtype: json :return: json with the attribute "has_update" """ pkg_res = get_pkg_res() pkg_dist_version = pkg_res.get_distribution(dist_name).version pypi_rel = get_pypi_releases(dist_name) if pypi_rel: pypi_last_version = pkg_res.parse_version(pypi_rel[0]) current_version = pkg_res.parse_version(pkg_dist_version) if pypi_last_version > current_version: DIST_PYPI_CACHE.add(dist_name.lower()) return jsonify({"has_update": 1}) try: DIST_PYPI_CACHE.remove(dist_name.lower()) except KeyError: pass return jsonify({"has_update": 0})
def cmd_list(args): '''This function implements the package list command. :param args: the docopt parsed arguments ''' compact = args['--compact'] filt = args['<filter>'] distributions = get_shared_data()['distributions'] if compact: print Fore.YELLOW + Style.BRIGHT + \ 'Project Name'.ljust(26) + 'Version'.ljust(14) + 'Summary' print '-' * 80 for dist in distributions: if filt: if filt.lower() not in dist.project_name.lower(): continue pkg_dist = get_pkg_res().get_distribution(dist.key) pkg_metadata = pkg_dist.get_metadata(metadata.METADATA_NAME) parsed, key_known = metadata.parse_metadata(pkg_metadata) distinfo = metadata.metadata_to_dict(parsed, key_known) if compact: cmd_list_compact(dist, distinfo) else: cmd_list_detail(dist, distinfo)
def console_scripts(): """ Entry point for the global console scripts """ data = {} data.update(get_shared_data()) data['menu_console_scripts'] = 'active' data['breadpath'] = [Crumb('Console Scripts')] entry_console = get_pkg_res().iter_entry_points('console_scripts') data['scripts'] = entry_console return render_template('console_scripts.html', **data)
def get_shared_data(): """ Returns a new dictionary with the shared-data between different Stallion views (ie. a lista of distribution packages). :rtype: dict :return: the dictionary with the shared data. """ shared_data = {'pypi_update_cache': DIST_PYPI_CACHE, 'distributions': [d for d in get_pkg_res().working_set]} return shared_data
def get_shared_data(): """ Returns a new dictionary with the shared-data between different Stallion views (ie. a lista of distribution packages). :rtype: dict :return: the dictionary with the shared data. """ shared_data = { 'pypi_update_cache': DIST_PYPI_CACHE, 'distributions': [d for d in get_pkg_res().working_set] } return shared_data
def distribution(dist_name=None): """ The Distribution entry-point (/distribution/<dist_name>) for the Stallion server. :param dist_name: the package name """ pkg_dist = get_pkg_res().get_distribution(dist_name) data = {} data.update(get_shared_data()) data['dist'] = pkg_dist data['breadpath'] = [ Crumb('Main', url_for('index')), Crumb('Package'), Crumb(pkg_dist.project_name) ] settings_overrides = { 'raw_enabled': 0, # no raw HTML code 'file_insertion_enabled': 0, # no file/URL access 'halt_level': 2, # at warnings or errors, raise an exception 'report_level': 5, # never report problems with the reST code } pkg_metadata = pkg_dist.get_metadata(metadata.METADATA_NAME) parsed, key_known = metadata.parse_metadata(pkg_metadata) distinfo = metadata.metadata_to_dict(parsed, key_known) parts = None try: parts = publish_parts(source=distinfo['description'], writer_name='html', settings_overrides=settings_overrides) except: pass data['distinfo'] = distinfo data['entry_map'] = pkg_dist.get_entry_map() if parts is not None: data['description_render'] = parts['body'] return render_template('distribution.html', **data)
def distribution(dist_name=None): """ The Distribution entry-point (/distribution/<dist_name>) for the Stallion server. :param dist_name: the package name """ pkg_dist = get_pkg_res().get_distribution(dist_name) data = {} data.update(get_shared_data()) data['dist'] = pkg_dist data['breadpath'] = [Crumb('Main', url_for('index')), Crumb('Package'), Crumb(pkg_dist.project_name)] settings_overrides = { 'raw_enabled': 0, # no raw HTML code 'file_insertion_enabled': 0, # no file/URL access 'halt_level': 2, # at warnings or errors, raise an exception 'report_level': 5, # never report problems with the reST code } pkg_metadata = pkg_dist.get_metadata(metadata.METADATA_NAME) parsed, key_known = metadata.parse_metadata(pkg_metadata) distinfo = metadata.metadata_to_dict(parsed, key_known) parts = None try: parts = publish_parts(source=distinfo['description'], writer_name='html', settings_overrides=settings_overrides) except: pass data['distinfo'] = distinfo data['entry_map'] = pkg_dist.get_entry_map() if parts is not None: data['description_render'] = parts['body'] return render_template('distribution.html', **data)
def cmd_show(args, short=False): '''This function implements the package show command. :param args: the docopt parsed arguments ''' proj_name = args['<project_name>'] try: pkg_dist = get_pkg_res().get_distribution(proj_name) except: print Fore.RED + Style.BRIGHT + \ 'Error: unable to locate the project \'%s\' !' % proj_name raise RuntimeError('Project not found !') pkg_metadata = pkg_dist.get_metadata(metadata.METADATA_NAME) parsed, key_known = metadata.parse_metadata(pkg_metadata) distinfo = metadata.metadata_to_dict(parsed, key_known) proj_head = Fore.GREEN + Style.BRIGHT + pkg_dist.project_name proj_head += Fore.YELLOW + Style.BRIGHT + ' ' + pkg_dist.version print proj_head, proj_sum = Fore.WHITE + Style.DIM proj_sum += '- ' + parse_dict(distinfo, 'summary', True) print proj_sum # Remove long fields and used fields if 'description' in distinfo: del distinfo['description'] if 'summary' in distinfo: del distinfo['summary'] if 'name' in distinfo: del distinfo['name'] if 'version' in distinfo: del distinfo['version'] classifier = None if 'classifier' in distinfo: classifier = distinfo['classifier'] del distinfo['classifier'] for key in distinfo: print get_field_formatted(distinfo, key) if short: return print print get_kv_colored('location', pkg_dist.location) requires = pkg_dist.requires() if len(requires) == 0: print get_kv_colored('requires', 'none') else: req_text = '\n' for req in requires: req_text += ' ' * 4 + str(req) + '\n' print get_kv_colored('requires', req_text) entry_points = pkg_dist.get_entry_map() console_scripts = entry_points.get('console_scripts') if console_scripts: console_scr_text = Fore.WHITE + Style.BRIGHT + ' Console Scripts:' + '\n' for name, entry in console_scripts.items(): console_scr_text += Fore.YELLOW + Style.BRIGHT + ' '*4 + \ name + Fore.WHITE + Style.BRIGHT console_scr_text += ' -> ' + Fore.GREEN + Style.BRIGHT + \ entry.module_name + ':' + ','.join(entry.attrs) + '\n' print console_scr_text if classifier: distinfo['classifier'] = classifier print get_field_formatted(distinfo, 'classifier')
def cmd_show(args, short=False): '''This function implements the package show command. :param args: the docopt parsed arguments ''' proj_name = args['<project_name>'] try: pkg_dist = get_pkg_res().get_distribution(proj_name) except: print Fore.RED + Style.BRIGHT + \ 'Error: unable to locate the project \'%s\' !' % proj_name raise RuntimeError('Project not found !') pkg_metadata = pkg_dist.get_metadata(metadata.METADATA_NAME) parsed, key_known = metadata.parse_metadata(pkg_metadata) distinfo = metadata.metadata_to_dict(parsed, key_known) proj_head = Fore.GREEN + Style.BRIGHT + pkg_dist.project_name proj_head += Fore.YELLOW + Style.BRIGHT + ' ' + pkg_dist.version print proj_head, proj_sum = Fore.WHITE + Style.DIM proj_sum += '- ' + parse_dict(distinfo, 'summary', True) print proj_sum # Remove long fields and used fields if 'description' in distinfo: del distinfo['description'] if 'summary' in distinfo: del distinfo['summary'] if 'name' in distinfo: del distinfo['name'] if 'version' in distinfo: del distinfo['version'] classifier = None if 'classifier' in distinfo: classifier = distinfo['classifier'] del distinfo['classifier'] for key in distinfo: print get_field_formatted(distinfo, key) if short: return print print get_kv_colored('location', pkg_dist.location) requires = pkg_dist.requires() if len(requires) == 0: print get_kv_colored('requires', 'none') else: req_text = '\n' for req in requires: req_text += ' '*4 + str(req) + '\n' print get_kv_colored('requires', req_text) entry_points = pkg_dist.get_entry_map() console_scripts = entry_points.get('console_scripts') if console_scripts: console_scr_text = Fore.WHITE + Style.BRIGHT + ' Console Scripts:' + '\n' for name, entry in console_scripts.items(): console_scr_text += Fore.YELLOW + Style.BRIGHT + ' '*4 + \ name + Fore.WHITE + Style.BRIGHT console_scr_text += ' -> ' + Fore.GREEN + Style.BRIGHT + \ entry.module_name + ':' + ','.join(entry.attrs) + '\n' print console_scr_text if classifier: distinfo['classifier'] = classifier print get_field_formatted(distinfo, 'classifier')
def test_get_pkg_res_instance_true(self): pkg = main.get_pkg_res() self.assertEqual(pkg, _pkg_resources)