comparison python/install_config.py @ 584:ed99a36df540

wip
author Jeff Hammel <k0scist@gmail.com>
date Wed, 22 Jan 2014 20:17:12 -0800
parents 0295141d9eeb
children e93b81d8a586
comparison
equal deleted inserted replaced
583:0dee1fcf3292 584:ed99a36df540
46 os.chdir(directory) 46 os.chdir(directory)
47 command = ['../../bin/python', 'setup.py', 'develop'] 47 command = ['../../bin/python', 'setup.py', 'develop']
48 execute(command) 48 execute(command)
49 os.chdir(old_directory) 49 os.chdir(old_directory)
50 50
51 51 ### generic step framework
52 ### process steps
53 52
54 class Step(object): 53 class Step(object):
55 @classmethod 54 @classmethod
56 def check(cls): 55 def check(cls):
57 """checks if the step may be run""" 56 """checks if the step may be run"""
57 @classmethod
58 def name(cls):
59 return cls.__name__
60 __str__ = name
58 def __call__(self): 61 def __call__(self):
59 execute(*self.commands) 62 execute(*self.commands)
63
64 class Command(object):
65 """require a command"""
66
67 ### process steps
60 68
61 class InitializeRepository(Step): 69 class InitializeRepository(Step):
62 """make the home directory a repository""" 70 """make the home directory a repository"""
63 commands = [ 71 commands = [
64 ['hg', 'init'], 72 ['hg', 'init'],
65 ['hg', 'pull', SRC], 73 ['hg', 'pull', SRC],
66 ['hg', 'update', '-C'], 74 ['hg', 'update', '-C'],
67 ] 75 ]
68 @classmethod 76 @classmethod
69 def write_hgrc(self): 77 def write_hgrc(self):
78 """make a (correct) .hg/hgrc file for $HOME"""
79
70 hgrc = """[paths] 80 hgrc = """[paths]
71 default = http://k0s.org/hg/config 81 default = http://k0s.org/hg/config
72 default-push = ssh://k0s.org/hg/config 82 default-push = ssh://k0s.org/hg/config
73 """ 83 """
74 with file('.hg/hgrc', 'w') as f: 84 with file('.hg/hgrc', 'w') as f:
75 f.write(hgrc) 85 f.write(hgrc)
76 def __call__(self): 86 def __call__(self):
77 Step.__call__(self) 87 Step.__call__(self)
78 self.write_hgrc() 88 self.write_hgrc()
79 89
90 # get the which command
91 sys.path.append(os.path.join(HOME, 'python'))
92 from which import which
80 93
81 #@requires(Command('git')) 94 #@requires(Command('git'))
82 #class GitInstall 95 class InstallVirtualenv(Step):
96 commands = [['git', 'clone', 'https://github.com/pypa/virtualenv.git'],
97 ['ln', '-s',
98 os.path.join(HOME, 'virtualenv/virtualenv.py'),
99 os.path.join(HOME, 'bin/')]
100 ]
83 101
84 class DebianPackages(Step): 102 class DebianPackages(Step):
85 """ubuntu packages to install""" 103 """ubuntu packages to install"""
104 # TODO: actually install packages
86 105
87 PACKAGES=["mercurial", 106 PACKAGES=["mercurial",
88 "unison", 107 "unison",
89 "fluxbox", 108 "fluxbox",
90 "antiword", 109 "antiword",
98 "emacs", 117 "emacs",
99 "irssi"] 118 "irssi"]
100 def __call__(self): 119 def __call__(self):
101 print "Ensure the following packages are installed:" 120 print "Ensure the following packages are installed:"
102 print "sudo apt-get install %s" % ' '.join(self.PACKAGES) 121 print "sudo apt-get install %s" % ' '.join(self.PACKAGES)
103 122
104 123
105 ### legacy -v- 124 ### legacy -v-
106 125
107 def legacy(): 126 def legacy():
108 """legacy : TO DEPRECATE!""" 127 """legacy : TO DEPRECATE!"""
109 commands = [
110 ['hg', 'init'],
111 ['hg', 'pull', SRC],
112 ['hg', 'update', '-C'],
113 ]
114 os.chdir(HOME) # go home
115
116 execute(*commands)
117
118 # make a (correct) .hg/hgrc file for $HOME
119 hgrc = """[paths]
120 default = http://k0s.org/hg/config
121 default-push = ssh://k0s.org/hg/config
122 """
123 with file(os.path.join(HOME, '.hg/hgrc', 'w')) as f:
124 f.write(hgrc)
125
126 # get the which command
127 sys.path.append(os.path.join(HOME, 'python'))
128 from which import which
129 128
130 # do git stuff 129 # do git stuff
131 git = which('git') 130 git = which('git')
132 if git: 131 if git:
133 132
134 # get virtual env 133 # get virtual env
135 virtualenv_commands = [['git', 'clone', 'https://github.com/pypa/virtualenv.git'], 134 virtualenv_
136 ['ln', '-s', HOME + '/virtualenv/virtualenv.py', HOME + '/bin/']]
137 execute(*virtualenv_commands) 135 execute(*virtualenv_commands)
138 136
139 # setup git's global ignore, since git is silly about this 137 # setup git's global ignore, since git is silly about this
140 # and doesn't look for the file in the right place 138 # and doesn't look for the file in the right place
141 execute(['git', 'config', '--global', 'core.excludesfile', os.path.join(HOME, '.gitignore')]) 139 execute(['git', 'config', '--global', 'core.excludesfile', os.path.join(HOME, '.gitignore')])
178 steps = [DebianPackages] 176 steps = [DebianPackages]
179 177
180 if options.list_steps: 178 if options.list_steps:
181 # list steps if specified 179 # list steps if specified
182 for step in steps: 180 for step in steps:
183 print step 181 print(step.name())
184 parser.exit() 182 parser.exit()
185 183
186 # execute steps 184 # execute steps
187 for step in steps: 185 for step in steps:
188 instance = step() 186 instance = step()