2015-05-13 38 views
2

有没有办法只列出所有的新的软件包及其依赖port将为给定的命令安装?如何列出将在Macports中安装的软件包和依赖关系?

例如,考虑安装SciPy的,用建议的叠加:

sudo port install py27-numpy py27-scipy py27-matplotlib py27-ipython +notebook py27-pandas py27-sympy py27-nose

,它安装一吨的包和依赖没有在上面的命令中列出。

另外,其中一些我已经有了。

我已经意识到-y交换机,但它提供了一切的详细输出,包括我已经安装的软件包。

我感兴趣有port告诉我包(无论是相关性或不)将被安装的。

有没有一种已知的方法,或者只是解析命令的输出-y,将每个报告的包与现有的已安装包进行比较?

干杯

p.s.我是相当新的和MacPorts的MacOSX的(在Linux中,易于得到总是告诉你新的软件包将被安装的)

回答

2

您可以使用一个端口表达式打印的内容将被安装:

port echo rdepof:$yourport and not installed 

或针对多个端口

port echo \(rdepof:$yourport rdepof:$yourport2 ... \) and not installed 

由于涉及到的Portfiles的数量以及如何执行set操作,这将会非常慢。话虽如此,我们也在努力改进这一点,并在安装之前提供反馈,比如未来的MacPorts版本中的apt-get。

0

虽然已经给出了答案,但似乎无法处理变体(如+notebook)和命令行选项(如configure.compiler=macports-clang-3.7)。我有一个单独的解决方案。下面的Python脚本可以递归显示新的依赖:

#!/usr/bin/env python 
#coding: utf-8 

import re 
import sys 
import subprocess 

# Gets command output as a list of lines 
def popen_readlines(cmd): 
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE) 
    p.wait() 
    if p.returncode != 0: 
     raise subprocess.CalledProcessError(p.returncode, cmd) 
    else: 
     return map(lambda line: line.rstrip('\n'), p.stdout.readlines()) 

# Gets the port name from a line like " gcc6 @6.1.0_0 (active)" 
def get_port_name(port_line): 
    return re.sub(r'^ (\S+).*', r'\1', port_line) 

# Gets installed ports as a set 
def get_installed(): 
    installed_ports_lines = popen_readlines(['port', 'installed'])[1:] 
    installed_ports = set(map(get_port_name, installed_ports_lines)) 
    return installed_ports 

# Gets port names from items that may contain version specifications, 
# variants, or options 
def get_ports(ports_and_specs): 
    requested_ports = set() 
    for item in ports_and_specs: 
     if not (re.search(r'^[[email protected]]', item) or re.search(r'=', item)): 
      requested_ports.add(item) 
    return requested_ports 

# Gets dependencies for the given port list (which may contain options 
# etc.), as a list of tuples (combining with level), excluding items in 
# ignored_ports 
def get_deps(ports, ignored_ports, level): 
    if ports == []: 
     return [] 

    deps_raw = popen_readlines(['port', 'deps'] + ports) 
    uninstalled_ports = [] 
    for line in deps_raw: 
     if re.search(r'Dependencies:', line): 
      deps = re.sub(r'.*Dependencies:\s*', '', line).split(', ') 
      uninstalled_ports += [x for x in deps if x not in ignored_ports] 
      ignored_ports |= set(deps) 

    port_level_pairs = [] 
    for port in uninstalled_ports: 
     port_level_pairs += [(port, level)] 
     port_level_pairs += get_deps([port], ignored_ports, level + 1) 
    return port_level_pairs 

def main(): 
    if sys.argv[1:]: 
     ports_and_specs = sys.argv[1:] 
     ignored_ports = get_installed() | get_ports(ports_and_specs) 
     uninstalled_ports = get_deps(ports_and_specs, ignored_ports, 0) 
     for (port, level) in uninstalled_ports: 
      print ' ' * (level * 2) + port 

if __name__ == '__main__': 
    main() 

,它可以像port_rdeps.py libomp configure.compiler=macports-clang-3.7被调用。作为奖励,它可以将卸载的依赖项显示为一棵树。

相关问题