aboutsummaryrefslogtreecommitdiff
path: root/lib/dodai/build/after_install.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dodai/build/after_install.py')
-rw-r--r--lib/dodai/build/after_install.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/dodai/build/after_install.py b/lib/dodai/build/after_install.py
new file mode 100644
index 0000000..16c1ec6
--- /dev/null
+++ b/lib/dodai/build/after_install.py
@@ -0,0 +1,84 @@
1import os
2from collections import namedtuple
3from subprocess import Popen
4from subprocess import call
5from subprocess import PIPE
6
7def build_paths(home_dir):
8
9 obj = namedtuple('Paths', 'wd, home, bin, src, python')
10
11 wd = os.getcwd()
12 if home_dir.startswith(os.sep):
13 home = home_dir
14 else:
15 home = os.path.realpath(os.path.join(wd, home_dir))
16 bin = os.path.join(home, 'bin')
17 src = os.path.join(home, 'src')
18 python = os.path.join(bin, 'python')
19
20 return obj(wd, home, bin, src, python)
21
22
23class EasyInstall(object):
24
25 def __init__(self, paths):
26 self._easy_install = os.path.join(paths.bin, 'easy_install')
27
28 def __call__(self, package):
29 cmd = [self._easy_install, '-Uv', package]
30 call(cmd)
31
32
33class HgClone(object):
34
35 def __init__(self, paths, easy_install=EasyInstall):
36 self._easy_install = easy_install(paths)
37 self._paths = paths
38 self._hg_ = None
39
40 @property
41 def _hg(self):
42 if not self._hg_:
43 cmd = ['which', 'hg']
44 self._hg_ = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()[0]\
45 .strip()
46 if not self._hg_:
47 self._hg_ = os.path.join(self._paths.bin, 'hg')
48 if not os.path.exists(self._hg_):
49 self._easy_install('mercurial')
50 return self._hg_
51
52 def __call__(self, url, dest):
53 if not dest.startswith(os.sep):
54 dest = os.path.join(self._paths.home, dest)
55 cmd = [self._hg, 'clone', url, dest]
56 call(cmd)
57
58
59class SetupPy(object):
60
61 FILE = 'setup.py'
62
63 def __init__(self, paths):
64 self._paths = paths
65
66 def __call__(self, dir, command):
67 path = os.path.join(self._paths.home, dir)
68 name = os.path.join(path, self.FILE)
69 if os.path.exists(name):
70 os.chdir(path)
71 cmd = [self._paths.python, name, command]
72 call(cmd)
73
74class RunPythonProgram(object):
75
76 def __init__(self, paths):
77 self._paths = paths
78
79 def __call__(self, program):
80 path = os.path.join(self._paths.bin, program)
81 if os.path.exists(path):
82 cmd = [self._paths.python, path]
83 call(cmd)
84