|
| 1 | +#!/bin/env python |
| 2 | + |
| 3 | +import os |
| 4 | +import sys |
| 5 | +import uuid |
| 6 | + |
| 7 | +try: |
| 8 | + from hashlib import sha1 |
| 9 | +except: |
| 10 | + import sha1 |
| 11 | + |
| 12 | +if len(sys.argv) < 2 or sys.argv[1] in ('-h', '--help'): |
| 13 | + sys.stderr.write("usage: pyroutes-admin.py projectname\n") |
| 14 | + sys.stderr.flush() |
| 15 | + sys.exit(1) |
| 16 | + |
| 17 | +project = sys.argv[1] |
| 18 | +project_path = os.path.join(os.getcwd(), project) |
| 19 | + |
| 20 | +if os.path.exists(project_path): |
| 21 | + sys.stderr.write("File or folder with the same name as the project exists.. exiting.\n") |
| 22 | + sys.stderr.flush() |
| 23 | + sys.exit(1) |
| 24 | + |
| 25 | +# Create project directories |
| 26 | +os.mkdir(project_path) |
| 27 | +os.mkdir(os.path.join(project_path, project)) |
| 28 | +os.mkdir(os.path.join(project_path, 'templates')) |
| 29 | +os.mkdir(os.path.join(project_path, 'tests')) |
| 30 | + |
| 31 | +# Initialize project module |
| 32 | +f = open(os.path.join(project_path, project, '__init__.py'), 'w') |
| 33 | +f.write("\n") |
| 34 | +f.close() |
| 35 | + |
| 36 | +# Create project settings |
| 37 | +f = open(os.path.join(project_path, 'pyroutes_settings.py'), 'w') |
| 38 | +f.write('import os\n\n') |
| 39 | +f.write('SECRET_KEY = \'%s\'\n' % sha1(str(uuid.uuid4())).hexdigest()) |
| 40 | +f.write('TEMPLATE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), \'templates\')') |
| 41 | +f.flush() |
| 42 | +f.close() |
| 43 | + |
| 44 | +# Create basic handler.py |
| 45 | +f = open(os.path.join(project_path, 'handler.py'), 'w') |
| 46 | +f.write('#!/bin/env python\n\nfrom pyroutes import application\n\n') |
| 47 | +f.write('from %s import *\n\n' % project) |
| 48 | +f.write('if __name__ == \'__main__\':\n from pyroutes.utils import devserver\n') |
| 49 | +f.write(' devserver(application)\n') |
| 50 | +f.flush() |
| 51 | +f.close() |
| 52 | + |
| 53 | +sys.stdout.write("Done. Go hacking!\n") |
| 54 | +sys.stdout.flush() |
| 55 | + |
| 56 | +sys.exit(0) |
0 commit comments