Permalink
Browse files

Merge pull request #33 from chrisrobak/master

apt wrapper for install script
  • Loading branch information...
2 parents 5c90143 + 7977dab commit 9be5b8b33335d09e18e96016da93982e95afdd3b @chrisrobak chrisrobak committed Apr 22, 2012
View
@@ -0,0 +1,32 @@
+from modules import apt_manager
+import os
+import json
+import datetime
+import sys
+log_file = open(os.path.join(os.path.expanduser('~'),'blackbox_install_log.txt'),'w')
+manifest_file = open('manifest.json','rw')
+
+def log(line_to_log):
+ log_file.write(datetime.datetime.strftime(datetime.datetime.now(),'%y-%M-%d %H:%M:%S')+line_to_log+'\n')
+ print line_to_log
+
+def main(args):
+ log('Opening Manifest')
+ manifest = json.load(manifest_file)
+ apt_packages = manifest['dependencies']:
+ log('Starting Install')
+ log('Instantializing Apt_Manager')
+ apt_man = apt_manager.Apt_Manager()
+ for p2_install in apt_packages:
+ log('Marking [%s] For Install' % (p2_install))
+ apt_man.mark_package_for_install(p2_install)
+ log('Installing All Marked Packages')
+ #apt_man.install_marked_packages()
+ log('Finished Base Install')
+ log('Closing Manifest')
+ manifest_file.close()
+
+if __name__ == "__main__":
+ main(sys.argv)
+else:
+ print "not ready for inheritence, just to run"
View
@@ -0,0 +1 @@
+{"dependencies":["nodejs:v0.4.9","npm:0.2.19"]}
View
No changes.
View
Binary file not shown.
View
@@ -0,0 +1,33 @@
+import apt
+class Apt_Manager(object):
+ def __init__(self):
+ self.cache = apt.Cache()
+
+ def install_package(self,pkg):
+ if type(pkg) == str:
+ pkg = self.get_package(pkg)
+ if type(pkg) == apt.package.Package:
+ pkg.mark_install()
+ self.cache.commit()
+ return 1
+ else:
+ return 0
+
+ def mark_package_for_install(self,pkg):
+ if type(pkg) == str:
+ pkg = self.get_package(pkg)
+ if type(pkg) == apt.package.Package:
+ pkg.mark_install()
+ return 1
+ else:
+ return 0
+
+ def install_marked_packages(self):
+ self.cache.commit()
+
+ def get_package(self,pkg_name):
+ try:
+ pkg = self.cache[pkg_name]
+ except KeyError, e:
+ pkg = 0
+ return pkg
View
Binary file not shown.

0 comments on commit 9be5b8b

Please sign in to comment.