~milo/lava-tool/lava-165

« back to all changes in this revision

Viewing changes to lava/helper/command.py

  • Committer: Milo Casagrande
  • Date: 2013-07-25 15:24:00 UTC
  • Revision ID: milo@ubuntu.com-20130725152400-cdd1gd2gtc3st25n
Refactored the lava init command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
from lava_tool.utils import (
38
38
    has_command,
39
39
    verify_and_create_url,
 
40
    create_tar,
 
41
    base64_encode,
 
42
)
 
43
from lava.job import Job
 
44
from lava.job.templates import (
 
45
    LAVA_TEST_SHELL_TAR_REPO,
 
46
    LAVA_TEST_SHELL_TAR_REPO_KEY,
 
47
    LAVA_TEST_SHELL_TESDEF_KEY,
40
48
)
41
49
 
 
50
from lava.testdef import TestDefinition
 
51
from lava.testdef.templates import (
 
52
    TESTDEF_TEMPLATE,
 
53
)
42
54
CONFIG = InteractiveConfig()
43
55
 
44
56
 
121
133
        else:
122
134
            raise CommandError("Job file '{0}' does not exists, or it is not "
123
135
                               "a file.".format(job_file))
 
136
 
 
137
    def create_tar_repo_job(self, job_file, testdef_file, tar_content):
 
138
        """Creates a job file based on the tar-repo template.
 
139
 
 
140
        The tar repo is not kept on the file system.
 
141
 
 
142
        :param job_file: The path of the job file to create.
 
143
        :param testdef_file: The path of the test definition file.
 
144
        :param tar_content: What should go into the tarball repository.
 
145
        :return The path of the job file created.
 
146
        """
 
147
        try:
 
148
            tar_repo = create_tar(tar_content)
 
149
 
 
150
            job_instance = Job(LAVA_TEST_SHELL_TAR_REPO, job_file)
 
151
            job_instance.update(self.config)
 
152
 
 
153
            job_instance.set(LAVA_TEST_SHELL_TAR_REPO_KEY,
 
154
                             base64_encode(tar_repo))
 
155
            job_instance.set(LAVA_TEST_SHELL_TESDEF_KEY,
 
156
                             os.path.basename(testdef_file))
 
157
 
 
158
            job_instance.write()
 
159
 
 
160
            return job_instance.file_name
 
161
        finally:
 
162
            if os.path.isfile(tar_repo):
 
163
                os.unlink(tar_repo)
 
164
 
 
165
    def create_test_definition(self, testdef_file, template=TESTDEF_TEMPLATE):
 
166
        """Creates a test definition YAML file.
 
167
 
 
168
        :param testdef_file: The file to create.
 
169
        :return The path of the file created.
 
170
        """
 
171
        testdef = TestDefinition(template, testdef_file)
 
172
        testdef.update(self.config)
 
173
        testdef.write()
 
174
 
 
175
        print >> sys.stdout, ("Create test definition "
 
176
                              "'{0}'.".format(testdef.file_name))
 
177
 
 
178
        return testdef.file_name