distil/puppet_generate.py
Aurynn Shaw bf671c0210 Moves the artifice web API into the artifice package. Updates the build
system to create a working .deb, based on the makefile.
Adds a new script to start up the web daemon.
Adds a new script to test if the database is provisioned
Adds a new script used by Puppet to provision the database
Adds puppet manifests (mirrored in main puppet)
Moves api/ to artifice/api
Alters some of the relative imports
Moves artifice.py to why_is_this_called_artifice.py, as it was causing
import issues.

Change-Id: Id8a909f7ffcc64a5c4e3281c6b5ba83cef73b596
2014-04-01 16:08:49 +13:00

53 lines
1.2 KiB
Python

import sys
# pip install requirements-parser
import requirements
class Requirements(object):
def __init__(self):
self.reqs = []
def parse(self, stream):
self.reqs = requirements.parse(stream)
def package_list(self):
final = """"""
for req in self.reqs:
final += """
package {"%(package)s":
ensure => "%(version)s",
provider => pip
}
""" % {"package": req.name, "version": req.specs[0][1] }
return final
def requirement_list(self):
return ",\n".join( [ """Package[%(package)s]""" %
{"package": req.name } for req in self.reqs ] )
if __name__ == '__main__':
import argparse
a = argparse.ArgumentParser()
a.add_argument("-f", dest="filename")
a.add_argument("-l", dest="list_", action="store_true")
args = a.parse_args()
if args.filename == "-":
# We're following standardized posix thing
fh = sys.stdin
else:
try:
fh = open(args.filename)
except IOError as e:
print "Couldn't open %s" % args.filename
sys.exit(1)
r = Requirements()
r.parse(fh)
if args.list_:
print r.requirement_list()
sys.exit(0)
print r.package_list()