diff --git a/tools/initdb.py b/tools/initdb.py index fa23d32..be8a717 100644 --- a/tools/initdb.py +++ b/tools/initdb.py @@ -130,7 +130,7 @@ def main( args = None ): return print "Initializing the database with default data." - host = settings[ u"global" ].get( u"luminotes.db_host" ) + host = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_host" ) database = Database( host = host, ssl_mode = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_ssl_mode" ), diff --git a/tools/make_download_link.py b/tools/make_download_link.py new file mode 100755 index 0000000..ab45821 --- /dev/null +++ b/tools/make_download_link.py @@ -0,0 +1,64 @@ +#!/usr/bin/python2.4 + +import os +import os.path +import sys +import cherrypy +from controller.Database import Database +from model.Download_access import Download_access + + +class Link_maker( object ): + """ + Create a product download access record and print the download link for it. + """ + def __init__( self, database, settings, item_number, transaction_id = None ): + self.database = database + self.settings = settings + self.item_number = item_number + self.transaction_id = transaction_id + + self.grant_access() + self.database.commit() + + def grant_access( self ): + access_id = self.database.next_id( Download_access, commit = False ) + download_access = Download_access.create( access_id, self.item_number, self.transaction_id ) + self.database.save( download_access, commit = False ) + + https_url = self.settings[ u"global" ][ u"luminotes.https_url" ] + print u"%s/d/%s" % ( https_url, access_id ) + + +def main( args ): + import cherrypy + from config import Common + + cherrypy.config.update( Common.settings ) + desktop = False + + if args and "-d" in args: + from config import Development + settings = Development.settings + args.remove( "-d" ) + elif args and "-l" in args: + from config import Desktop + settings = Desktop.settings + desktop = True + args.remove( "-l" ) + else: + from config import Production + settings = Production.settings + + cherrypy.config.update( settings ) + + database = Database( + host = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_host" ), + ssl_mode = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_ssl_mode" ), + data_dir = ".", + ) + ranker = Link_maker( database, cherrypy.config.configMap, *args ) + + +if __name__ == "__main__": + main( sys.argv[ 1: ] ) diff --git a/tools/set_plan.py b/tools/set_plan.py index f5cd183..6d10fd2 100755 --- a/tools/set_plan.py +++ b/tools/set_plan.py @@ -3,25 +3,23 @@ import os import os.path import sys -import cherrypy from controller.Database import Database from controller.Users import Users from model.Notebook import Notebook from model.User import User -from config import Common class Plan_setter( object ): """ Set the rate plan for a particular user. """ - def __init__( self, database, user_id, rate_plan ): + def __init__( self, database, settings, user_id, rate_plan ): self.database = database self.user_id = user_id self.rate_plan = int( rate_plan ) - rate_plans = Common.settings[ u"global" ][ u"luminotes.rate_plans" ] - self.users = Users( database, None, None, None, None, rate_plans ) + rate_plans = settings[ u"global" ][ u"luminotes.rate_plans" ] + self.users = Users( database, None, None, None, None, rate_plans, [] ) self.set_plan() self.database.commit() @@ -40,15 +38,33 @@ class Plan_setter( object ): self.users.update_groups( user ) def main( args ): - database = Database() - ranker = Plan_setter( database, *args ) + import cherrypy + from config import Common + + cherrypy.config.update( Common.settings ) + desktop = False + + if args and "-d" in args: + from config import Development + settings = Development.settings + args.remove( "-d" ) + elif args and "-l" in args: + from config import Desktop + settings = Desktop.settings + desktop = True + args.remove( "-l" ) + else: + from config import Production + settings = Production.settings + + cherrypy.config.update( settings ) + database = Database( + host = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_host" ), + ssl_mode = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_ssl_mode" ), + data_dir = ".", + ) + ranker = Plan_setter( database, cherrypy.config.configMap, *args ) if __name__ == "__main__": - args = sys.argv[ 1: ] - - if len( args ) != 2: - print "usage: %s user_id rate_plan_index" % sys.argv[ 0 ] - sys.exit( 1 ) - - main( args ) + main( sys.argv[ 1: ] )