Personal wiki notebook (not under development)

make_download_link.py 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/python2.4
  2. import os
  3. import os.path
  4. import sys
  5. import cherrypy
  6. from controller.Database import Database
  7. from model.Download_access import Download_access
  8. class Link_maker( object ):
  9. """
  10. Create a product download access record and print the download link for it.
  11. """
  12. def __init__( self, database, settings, item_number, transaction_id = None ):
  13. self.database = database
  14. self.settings = settings
  15. self.item_number = item_number
  16. self.transaction_id = transaction_id
  17. self.grant_access()
  18. self.database.commit()
  19. def grant_access( self ):
  20. access_id = self.database.next_id( Download_access, commit = False )
  21. download_access = Download_access.create( access_id, self.item_number, self.transaction_id )
  22. self.database.save( download_access, commit = False )
  23. https_url = self.settings[ u"global" ][ u"luminotes.https_url" ]
  24. print u"%s/d/%s" % ( https_url, access_id )
  25. def main( args ):
  26. import cherrypy
  27. from config import Common
  28. cherrypy.config.update( Common.settings )
  29. desktop = False
  30. if args and "-d" in args:
  31. from config import Development
  32. settings = Development.settings
  33. args.remove( "-d" )
  34. elif args and "-l" in args:
  35. from config import Desktop
  36. settings = Desktop.settings
  37. desktop = True
  38. args.remove( "-l" )
  39. else:
  40. from config import Production
  41. settings = Production.settings
  42. cherrypy.config.update( settings )
  43. database = Database(
  44. host = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_host" ),
  45. ssl_mode = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_ssl_mode" ),
  46. data_dir = ".",
  47. )
  48. ranker = Link_maker( database, cherrypy.config.configMap, *args )
  49. if __name__ == "__main__":
  50. main( sys.argv[ 1: ] )