-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplay
executable file
·132 lines (106 loc) · 4.51 KB
/
play
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Play command line script www.playframework.org/
import sys
import os
import os.path
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'framework', 'pym'))
from play.cmdloader import CommandLoader
from play.application import PlayApplication
from play.utils import *
# ~~~~~~~~~
# Main
try:
play_env = dict()
# ~~~~~~~~~~~~~~~~~~~~~~ Where is the framework?
play_env["basedir"] = os.path.normpath(os.path.dirname(os.path.realpath(sys.argv[0])))
# ~~~~~~~~~~~~~~~~~~~~~~ What is the framework id?
play_env["id_file"] = os.path.join(play_env['basedir'], 'id')
if os.path.exists(play_env["id_file"]):
play_env["id"] = open(play_env["id_file"]).readline().strip()
else:
play_env["id"] = ''
# ~~~~~~~~~~~~~~~~~~~~~~ Display logo
print r"~ _ _ "
print r"~ _ __ | | __ _ _ _| |"
print r"~ | '_ \| |/ _' | || |_|"
print r"~ | __/|_|\____|\__ (_)"
print r"~ |_| |__/ "
print r"~"
play_version_file = os.path.join(play_env["basedir"], 'framework', 'src', 'play', 'version')
if not os.path.exists(play_version_file):
print "~ Oops. %s file not found" % os.path.normpath(os.path.join(play_env["basedir"], 'framework', 'src', 'play', 'version'))
print "~ Is the framework compiled? "
print "~"
sys.exit(-1)
play_env["version"] = open(play_version_file).readline().strip()
print "~ play! %s, http://www.playframework.org" % (play_env["version"])
# ~~~~~~~~~~~~~~~~~~~~~~ Where is the application?
application_path = None
remaining_args = []
if len(sys.argv) == 2:
application_path = os.getcwd()
remaining_args = sys.argv[2:]
if len(sys.argv) > 2:
if sys.argv[2].startswith('-'):
application_path = os.getcwd()
remaining_args = sys.argv[2:]
else:
application_path = os.path.normpath(os.path.abspath(sys.argv[2]))
remaining_args = sys.argv[3:]
ignoreMissing = False
if remaining_args.count('--force') == 1:
remaining_args.remove('--force')
ignoreMissing = True
# ~~~~~~~~~~~~~~~~~~~~~~ What is the command?
if len(sys.argv) > 1:
play_command = sys.argv[1]
else:
play_command = 'none'
# ~~~~~~~~~~~~~~~~~ Override id
for a in remaining_args:
if a.find('--%') == 0:
play_env["id"] = a[3:]
if remaining_args.count('--%%%s' % play_env["id"]) == 1:
remaining_args.remove('--%%%s' % play_env["id"])
if play_command == 'test' or play_command == 'auto-test':
play_env["id"] = 'test'
if play_env["id"] is not '':
print "~ framework ID is %s" % play_env["id"]
print "~"
play_app = PlayApplication(application_path, play_env, ignoreMissing)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~ The commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cmdloader = CommandLoader(play_env["basedir"])
# Load module commands
if play_app:
for module in play_app.modules():
cmdloader.load_play_module(module)
for module in getWithModules(remaining_args, play_env):
cmdloader.load_play_module(module)
if play_command in cmdloader.commands:
for name in cmdloader.modules:
module = cmdloader.modules[name]
if 'before' in dir(module):
module.before(command=play_command, app=play_app, args=remaining_args, env=play_env)
cmdloader.commands[play_command].execute(command=play_command, app=play_app, args=remaining_args, env=play_env, cmdloader=cmdloader)
for name in cmdloader.modules:
module = cmdloader.modules[name]
if 'after' in dir(module):
module.after(command=play_command, app=play_app, args=remaining_args, env=play_env)
sys.exit(0)
# ~~~~~~~~~~~~~~~~~~~~~~ Invalid command
print "~ Usage: play cmd [app_path] [--options]"
print "~ "
print "~ with, new Create a new application"
print "~ run Run the application in the current shell"
print "~ help Show play help"
print "~"
if len(sys.argv) > 1:
print "~ Invalid command: %s" % sys.argv[1]
print "~"
sys.exit(-1)
except KeyboardInterrupt:
print '~ ...'
sys.exit(0)