def search_for_builddep(module): try: if not isinstance(module, _Npm2Deb): _debug(1, 'getting builddep - calling npm view %s' % module) npm_out = _getstatusoutput('npm view "%s" ' 'devDependencies --json 2>/dev/null' % module)[1] builddeb = _parseJSON(npm_out) else: builddeb = module.json['devDependencies'] module = module.name except ValueError: return None mapper = _Mapper.get_instance() result = {} for dep in sorted(builddeb.keys()): result[dep] = {} result[dep]['version'] = builddeb[dep] result[dep]['debian'] = mapper.get_debian_package(dep)['repr'] print_formatted_dependency("%s (%s)" % (dep, result[dep]['version']), result[dep]['debian']) return result
def _get_Depends(self): depends = ['nodejs (>= 6)'] mapper = Mapper.get_instance() if 'dependencies' in self.json: dependencies = self.json['dependencies'] for dep in dependencies: name = mapper.get_debian_package(dep)['name'] if not name: name = 'node-%s' % dep mapper.append_warning( 'error', dep, 'dependency %s ' 'not in debian' % (name)) version = dependencies[dep] if version: version = version.lower().replace('~', '').replace( '^', '').replace('.x', '.0') if version[0].isdigit(): version = '>= %s' % version elif version == '*' or version == 'latest': version = None if version: dep_debian = "%s (%s)" % (name, version) else: dep_debian = name depends.append(dep_debian) return '\n , '.join(depends)
def print_view(args): npm2deb_instance = get_npm2deb_instance(args) formatted = "{0:40}{1}" for key in ['name', 'version', 'description', 'homepage', 'license']: attr_key = key if key == 'license' or key == 'version': attr_key = 'upstream_%s' % key print(formatted.format("%s:" % key.capitalize(), getattr(npm2deb_instance, attr_key, None))) mapper = Mapper.get_instance() print(formatted.format("Debian:", mapper .get_debian_package(npm2deb_instance.name)['repr'])) if mapper.has_warnings(): print("") _show_mapper_warnings()
def search_for_dependencies(module, recursive=False, force=False, prefix=u'', expanded_dependencies=[]): try: if not isinstance(module, _Npm2Deb): _debug(1, 'getting dependencies - calling npm view %s' % module) npm_out = _getstatusoutput('npm view "%s" ' 'dependencies --json 2>/dev/null' % module)[1] dependencies = _parseJSON(npm_out) else: dependencies = module.json['dependencies'] module = module.name except ValueError: return None mapper = _Mapper.get_instance() result = {} keys = sorted(list(dependencies.keys())) last_dep = False for dep in keys: if dep == keys[-1]: last_dep = True result[dep] = {} result[dep]['version'] = dependencies[dep] result[dep]['debian'] = mapper.get_debian_package(dep)['repr'] dep_prefix = u'└─' if last_dep else u'├─' print_formatted_dependency( u"%s %s (%s)" % (dep_prefix, dep, result[dep]['version']), result[dep]['debian'], prefix) if recursive and not dep in expanded_dependencies: expanded_dependencies.append(dep) if (result[dep]['debian'] and force) or \ result[dep]['debian'] is None: new_prefix = "%s%s " % (prefix, u" " if last_dep else u"│ ") result[dep]['dependencies'] = \ search_for_dependencies(dep, recursive, force, new_prefix, expanded_dependencies) else: result[dep]['dependencies'] = None return result
def search_for_dependencies(module, recursive=False, force=False, prefix=u'', expanded_dependencies=[]): try: if not isinstance(module, _Npm2Deb): _debug(1, 'getting dependencies - calling npm view %s' % module) npm_out = _getstatusoutput('npm view "%s" ' 'dependencies --json 2>/dev/null' % module)[1] dependencies = _parseJSON(npm_out) else: dependencies = module.json['dependencies'] module = module.name except ValueError: return None mapper = _Mapper.get_instance() result = {} keys = sorted(list(dependencies.keys())) last_dep = False for dep in keys: if dep == keys[-1]: last_dep = True result[dep] = {} result[dep]['version'] = dependencies[dep] result[dep]['debian'] = mapper.get_debian_package(dep)['repr'] dep_prefix = u'└─' if last_dep else u'├─' print_formatted_dependency(u"%s %s (%s)" % (dep_prefix, dep, result[dep]['version']), result[dep]['debian'], prefix) if recursive and not dep in expanded_dependencies: expanded_dependencies.append(dep) if (result[dep]['debian'] and force) or \ result[dep]['debian'] is None: new_prefix = "%s%s " % (prefix, u" " if last_dep else u"│ ") result[dep]['dependencies'] = \ search_for_dependencies(dep, recursive, force, new_prefix, expanded_dependencies) else: result[dep]['dependencies'] = None return result
def print_view(args): npm2deb_instance = get_npm2deb_instance(args) formatted = "{0:40}{1}" for key in ['name', 'version', 'description', 'homepage', 'license']: attr_key = key if key == 'license' or key == 'version': attr_key = 'upstream_%s' % key print( formatted.format("%s:" % key.capitalize(), getattr(npm2deb_instance, attr_key, None))) mapper = Mapper.get_instance() print( formatted.format( "Debian:", mapper.get_debian_package(npm2deb_instance.name)['repr'])) if mapper.has_warnings(): print("") _show_mapper_warnings()
def search_for_module(args): helper.DO_PRINT = True # enable all by default if not args.bug and not args.debian and not args.repository: args.bug = True args.debian = True args.repository = True node_module = get_npm2deb_instance(args).name if args.debian: print("\nLooking for similiar package:") mapper = Mapper.get_instance() print(" %s" % mapper.get_debian_package(node_module)['repr']) if args.repository: print("") helper.search_for_repository(node_module) if args.bug: print("") helper.search_for_bug(node_module) print("") _show_mapper_warnings()
def search_for_builddep(module): try: if not isinstance(module, Npm2Deb): builddeb = parseJSON(getstatusoutput('npm view %s ' 'devDependencies --json 2>/dev/null' % module)[1]) else: builddeb = module.json['devDependencies'] module = module.name except ValueError: return None mapper = Mapper.get_instance() result = {} for dep in builddeb: result[dep] = {} result[dep]['version'] = builddeb[dep] result[dep]['debian'] = mapper.get_debian_package(dep)['repr'] print_formatted_dependency("%s (%s)" % (dep, result[dep]['version']), result[dep]['debian']) return result
def _get_Depends(self): depends = ["nodejs"] mapper = Mapper.get_instance() if "dependencies" in self.json: dependencies = self.json["dependencies"] for dep in dependencies: name = mapper.get_debian_package(dep)["name"] if not name: name = "node-%s" % dep mapper.append_warning("error", dep, "dependency %s " "not in debian" % (name)) version = dependencies[dep].replace("~", "") if version[0].isdigit(): version = ">= %s" % version elif version == "*" or version == "latest": version = None if version: dep_debian = "%s (%s)" % (name, version) else: dep_debian = name depends.append(dep_debian) return "\n , ".join(depends)
def search_for_dependencies(module, recursive=False, force=False, prefix=u''): try: if not isinstance(module, Npm2Deb): dependencies = parseJSON( getstatusoutput('npm view %s ' 'dependencies --json 2>/dev/null' % module)[1]) else: dependencies = module.json['dependencies'] module = module.name except ValueError: return None mapper = Mapper.get_instance() result = {} keys = dependencies.keys() last_dep = False for dep in keys: if dep == keys[-1]: last_dep = True result[dep] = {} result[dep]['version'] = dependencies[dep] result[dep]['debian'] = mapper.get_debian_package(dep)['repr'] dep_prefix = u'└─' if last_dep else u'├─' print_formatted_dependency( u"%s %s (%s)" % (dep_prefix, dep, result[dep]['version']), result[dep]['debian'], prefix) if recursive: if (result[dep]['debian'] and force) or \ result[dep]['debian'] is None: new_prefix = "%s%s " % (prefix, u" " if last_dep else u"│ ") result[dep]['dependencies'] = search_for_dependencies(dep, \ recursive, force, new_prefix) else: result[dep]['dependencies'] = None return result
def show_dependencies(args): helper.DO_PRINT = True # enable all by default if not args.binary and not args.builddeb: args.binary = True args.builddeb = True npm2deb_instance = get_npm2deb_instance(args) module_name = npm2deb_instance.name json = npm2deb_instance.json if args.binary: if 'dependencies' in json and json['dependencies']: print "Dependencies:" helper.print_formatted_dependency("NPM", "Debian") module_ver = npm2deb_instance.upstream_version module_deb = Mapper.get_instance()\ .get_debian_package(module_name)["repr"] helper.print_formatted_dependency("%s (%s)" % \ (module_name, module_ver), module_deb) helper.search_for_dependencies(npm2deb_instance, args.recursive, args.force) print("") else: print("Module %s has no dependencies." % module_name) if args.builddeb: if 'devDependencies' in json and json['devDependencies']: print "Build dependencies:" helper.print_formatted_dependency("NPM", "Debian") helper.search_for_builddep(module_name) print("") else: print("Module %s has no build dependencies." % module_name) _show_mapper_warnings()
def search_for_dependencies(module, recursive=False, force=False, prefix=u''): try: if not isinstance(module, Npm2Deb): dependencies = parseJSON(getstatusoutput('npm view %s ' 'dependencies --json 2>/dev/null' % module)[1]) else: dependencies = module.json['dependencies'] module = module.name except ValueError: return None mapper = Mapper.get_instance() result = {} keys = dependencies.keys() last_dep = False for dep in keys: if dep == keys[-1]: last_dep = True result[dep] = {} result[dep]['version'] = dependencies[dep] result[dep]['debian'] = mapper.get_debian_package(dep)['repr'] dep_prefix = u'└─' if last_dep else u'├─' print_formatted_dependency(u"%s %s (%s)" % (dep_prefix, dep, result[dep]['version']), result[dep]['debian'], prefix) if recursive: if (result[dep]['debian'] and force) or \ result[dep]['debian'] is None: new_prefix = "%s%s " % (prefix, u" " if last_dep else u"│ ") result[dep]['dependencies'] = search_for_dependencies(dep, \ recursive, force, new_prefix) else: result[dep]['dependencies'] = None return result
def search_for_builddep(module): try: if not isinstance(module, Npm2Deb): builddeb = parseJSON( getstatusoutput('npm view %s ' 'devDependencies --json 2>/dev/null' % module)[1]) else: builddeb = module.json['devDependencies'] module = module.name except ValueError: return None mapper = Mapper.get_instance() result = {} for dep in builddeb: result[dep] = {} result[dep]['version'] = builddeb[dep] result[dep]['debian'] = mapper.get_debian_package(dep)['repr'] print_formatted_dependency("%s (%s)" % (dep, result[dep]['version']), result[dep]['debian']) return result
def _show_mapper_warnings(): mapper = Mapper.get_instance() if mapper.has_warnings(): print("Warnings occured:") mapper.show_warnings() print("")