-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathAlien.py
executable file
·98 lines (83 loc) · 3.24 KB
/
Alien.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env python
# A script and module for manipulating Alien package managers.
# Copyright 2009 Michael Homer. Released under the GNU GPL 2 or later.
import os
import subprocess
import CheckDependencies
from PythonUtils import *
alien_manager_states = {}
alien_package_states = {}
def parse_rule(rule):
alientype, alienpkg = split(rule['program'])
lowerbound = ''
upperbound = ''
for comp, val in rule['versions']:
if comp == '>=':
lowerbound = val
elif comp == '<':
upperbound = val
elif comp == '=' or comp == '==':
lowerbound = val
upperbound = val
return alientype, alienpkg, lowerbound, upperbound
def dependencymet(rule):
"""Return True if rule['program'] is installed and meets the
rule['versions'] requirements (if any). The lowerbound is
inclusive and the upperbound is exclusive, except if lowerbound
and upperbound are equal then that indicates an exact match."""
alientype, alienpkg, lowerbound, upperbound = parse_rule(rule)
if 0 == subprocess.call(['Alien-' + alientype, '--met', alienpkg,
lowerbound, upperbound]):
return True
return False
def getinstallversion(rule):
"""Return version of rule['program'] to install. If rule['versions']
is specified then returned version should meet those
requirements (as described by the dependencymet() function)."""
alientype, alienpkg, lowerbound, upperbound = parse_rule(rule)
p = subprocess.Popen(['Alien-' + alientype, '--getinstallversion',
alienpkg, lowerbound, upperbound], stdout=subprocess.PIPE)
return p.stdout.read().strip()
def split(program):
return program.split(':', 1)
def havealienmanager(alientype):
if alientype in alien_manager_states:
return alien_manager_states[alientype]
res = 0 == subprocess.call(['Alien-' + alientype, '--have-manager'])
alien_manager_states[alientype] = res
return res
def getmanagerrule(alientype):
p = subprocess.Popen(['Alien-' + alientype, '--get-manager-rule'],
stdout=subprocess.PIPE)
rulestr = p.stdout.read().strip()
rule = CheckDependencies.interpret_dependency_line(rulestr)
return rule
if __name__ == '__main__':
if len(sys.argv) < 3:
print "Usage: Alien --<mode> AlienType:alienpkg [...]\n"
print "Valid options for <mode> are:"
print " --get-version"
print " --getinstallversion"
print " --greater-than"
print " --met|--within-range|--interval"
print " --have-manager"
print " --get-manager-rule"
print " --install\n"
print "Valid options for AlienType are:"
print " CPAN"
print " LuaRocks"
print " PIP"
print " RubyGems\n"
print "Example:"
print " Alien --install CPAN:XML::Parser"
print " Alien --install PIP:burn"
exit(1)
mode = sys.argv[1]
prog = sys.argv[2]
try:
alientype, alienpkg = split(prog)
except ValueError:
print "Error: missing program name"
exit(1)
args = ['Alien-' + alientype, mode, alienpkg] + sys.argv[3:]
exit(subprocess.call(args))