-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyard
executable file
·162 lines (136 loc) · 4.93 KB
/
yard
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#! env/bin/python
"""
yard
author: erich@emfeld.com
========================
This file is the main file that binds all the functions in the
gardener directory.
The file handles all generator and database operations from the command line.
Running the server is performed by this file.
The file depends on the gardener module.
"""
import sys
import os.path
from gardener import help, db_create, db_migrate
from gardener import db_upgrade, db_downgrade, db_version
from gardener import install_package
from gardener import add_controller, add_model, generate_controller
from gardener import run_tornado, run_testrun
from builder import Config
from config import UserConfig
user_config = UserConfig()
config = Config(user_config.BASEDIR)
if len(sys.argv) > 1:
sysinput = sys.argv[1].lower()
# this handles the option to run tornado web server
if sysinput == 'blow' or sysinput == 'b':
run_tornado()
#this handles the option to tun db downgrade operation
elif sysinput == 'downgrade' or sysinput == 'd':
if len(sys.argv) > 2 and sys.argv[2].isdigit():
db_downgrade(sys.argv[2])
else:
db_downgrade()
# this handles the generator for controller
# both with model or the stub only
elif sysinput == 'grow' or sysinput == 'g':
if len(sys.argv) > 3:
# this handles controllers that are attached to models
if sys.argv[2].lower() == 'tree':
model_name = sys.argv[3].title()
raw_component = sys.argv[4:]
model_components = []
if raw_component:
for component in raw_component:
raw_field = component.split(':')
field_name = raw_field[0]
detail_components = raw_field[1].split('--')
if detail_components[0].lower() == 'string':
if len(detail_components) < 2:
detail_components.append('50')
insert_components = {
'field_name': field_name,
'field_property': detail_components
}
elif detail_components[0].lower() in Config.valid_data_types:
insert_components = {
'field_name': field_name,
'field_property': detail_components
}
else:
print '\n' + detail_components[0].lower() + ' is not a valid data type.'
sys.exit()
model_components.append(insert_components)
add_model(model_name, model_components)
generate_controller(model_name, model_components)
# this handles model without controllers
elif sys.argv[2].lower() == 'seed':
model_name = sys.argv[3].title()
raw_component = sys.argv[4:]
model_components = []
if raw_component:
for component in raw_component:
raw_field = component.split(':')
field_name = raw_field[0]
detail_components = raw_field[1].split('--')
if detail_components[0].lower() == 'string':
if len(detail_components) < 2:
detail_components.append('50')
insert_components = {
'field_name': field_name,
'field_property': detail_components
}
elif detail_components[0].lower() in VALID_DATA_TYPES:
insert_components = {
'field_name': field_name,
'field_property': detail_components
}
else:
print '\n' + detail_components[0].lower() + ' is not a valid data type.'
sys.exit()
model_components.append(insert_components)
add_model(model_name, model_components)
# this handles controller stubs not attached to model
elif sys.argv[2].lower() == 'stub':
if len(sys.argv) > 3 and not sys.argv[3].isdigit():
add_controller(sys.argv[3])
else:
print 'Option item not found, please run yard help to see available options'
sys.exit()
else:
print 'Not enough parameters provided, please run yard help to see available options'
sys.exit()
# this handles the option to display help text
elif sysinput == 'help' or sysinput == 'h':
help()
# this handles the oprion to install package to the backyard
elif sysinput == 'place' or sysinput == 'p':
if sys.argv[2]:
install_package(sys.argv[2])
else:
print "You need to specify a valid package name"
sys.exit()
# this handles the option to perform database creation
elif sysinput == 'shove' or sysinput == 's':
if not os.path.exists(user_config.SQLALCHEMY_MIGRATE_REPO):
db_create()
else:
print '\nPrevious database version found. Please use water or w option\n'
sys.exit()
# this handles the option to run the test server
elif sysinput == 'try' or sysinput == 't':
run_testrun()
# this handles the option to upgrade the database version
elif sysinput == 'upgrade' or sysinput == 'u':
db_upgrade()
# this handles the option to display current database version
elif sysinput == 'version' or sysinput == 'v':
db_version()
# this handles the option to perform database migration
elif sysinput == 'water' or sysinput == 'w':
db_migrate()
else:
print '\nCommand not found. Please use help for command options\n'
else:
print '\nNot enough parameters found. Please run yard help for complete explanations\n'
# end of file