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