104
109
raise CommandError("'{0}' already exists, and is a "
105
110
"file.".format(self.args.DIR))
107
if not os.path.isdir(full_path):
109
os.makedirs(full_path)
111
raise CommandError("Cannot create directory "
112
"'{0}'.".format(self.args.DIR))
114
test_path = os.path.join(full_path, TESTS_DIR)
115
if not os.path.isdir(test_path):
117
os.makedirs(test_path)
119
raise CommandError("Cannot create directory "
120
"'{0}'.".format(self.args.DIR))
112
create_dir(full_path)
122
114
data = self._update_data()
123
self._create_files(data, full_path, test_path)
116
test_path = create_dir(full_path, TESTS_DIR)
118
self._create_script(test_path)
120
testdef_file = self.create_test_definition(
121
os.path.join(test_path, DEFAULT_TESTDEF_FILE))
123
job = data[JOBFILE_ID]
124
self.create_tar_repo_job(
125
os.path.join(full_path, job), testdef_file, test_path)
125
127
def _update_data(self):
126
128
"""Updates the template and ask values to the user.
138
def _create_files(self, data, full_path, test_path):
140
def _create_script(self, test_path):
139
141
# This is the default script file as defined in the testdef template.
140
142
default_script = os.path.join(test_path, DEFAULT_TESTDEF_SCRIPT)
145
147
print >> sys.stdout, ("\nCreating default test script "
146
148
"'{0}'.".format(DEFAULT_TESTDEF_SCRIPT))
148
with open(default_script, "w") as write_file:
149
write_file.write(DEFAULT_TESTDEF_SCRIPT_CONTENT)
150
write_file(default_script, DEFAULT_TESTDEF_SCRIPT_CONTENT)
151
# Prompt the user to write the script file.
152
self.edit_file(default_script)
152
# Prompt the user to write the script file.
153
edit_file(default_script)
154
155
# Make sure the script is executable.
155
156
os.chmod(default_script,
156
157
stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH)
158
print >> sys.stdout, ("\nCreating test definition "
159
"'{0}':".format(DEFAULT_TESTDEF_FILE))
160
self._create_test_file(os.path.join(test_path,
161
DEFAULT_TESTDEF_FILE))
163
job = data[JOBFILE_ID]
164
print >> sys.stdout, "\nCreating job file '{0}':".format(job)
165
self._create_job_file(os.path.join(full_path, job), test_path)
167
def _create_job_file(self, job_file, test_path=None):
168
"""Creates the job file on the filesystem."""
170
# Invoke the command to create new job files: make a copy of the local
171
# args and add what is necessary for the command.
172
from lava.job.commands import new
174
args = copy.copy(self.args)
177
job_cmd = new(self.parser, args)
178
job_cmd.invoke(tests_dir=test_path)
180
def _create_test_file(self, test_file):
181
"""Creates the test definition file on the filesystem."""
183
# Invoke the command to create new testdef files: make a copy of the
184
# local args and add what is necessary for the command.
185
from lava.testdef.commands import new
187
args = copy.copy(self.args)
188
args.FILE = test_file
190
testdef_cmd = new(self.parser, args)
194
160
class run(BaseCommand):
195
161
"""Runs a job on the local dispatcher."""
209
175
full_path = os.path.abspath(self.args.JOB)
210
176
job_file = retrieve_file(full_path, JOB_FILE_EXTENSIONS)
212
self._run_job(job_file)
214
def _run_job(self, job_file):
215
"""Runs a job on the dispatcher."""
216
from lava.job.commands import run
218
args = copy.copy(self.args)
221
run_cmd = run(self.parser, args)
178
super(run, self).run(job_file)
225
181
class submit(BaseCommand):
240
196
full_path = os.path.abspath(self.args.JOB)
241
197
job_file = self.retrieve_file(full_path, JOB_FILE_EXTENSIONS)
243
self._submit_job(job_file)
245
def _submit_job(self, job_file):
246
"""Submits a job file to LAVA."""
247
from lava.job.commands import submit
249
args = copy.copy(self.args)
252
submit_cmd = submit(self.parser, args)
199
super(submit, self).submit(job_file)
256
202
class update(BaseCommand):
285
232
raise CommandError("Cannot read job file '{0}'.".format(
288
with open(job_file, "w") as write_file:
290
write_file.write(json.dumps(json_data, indent=4))
292
raise CommandError("Cannot update job file "
293
"'{0}'.".format(json_file))
235
content = json.dumps(json_data, indent=4)
236
write_file(job_file, content)
294
238
print >> sys.stdout, "Job definition updated."
296
240
raise CommandError("Cannot find tests directory.")