Merge lp:~stylesen/lava-scheduler-tool/add-job-output-cmd into lp:lava-scheduler-tool

Proposed by Senthil Kumaran S
Status: Merged
Merged at revision: 21
Proposed branch: lp:~stylesen/lava-scheduler-tool/add-job-output-cmd
Merge into: lp:lava-scheduler-tool
Diff against target: 70 lines (+45/-0)
2 files modified
lava_scheduler_tool/commands.py (+44/-0)
setup.py (+1/-0)
To merge this branch: bzr merge lp:~stylesen/lava-scheduler-tool/add-job-output-cmd
Reviewer Review Type Date Requested Status
Antonio Terceiro Approve
Review via email: mp+159335@code.launchpad.net

Description of the change

Add new command to lava-scheduler-tool in order to download job output file.

To post a comment you must log in.
Revision history for this message
Antonio Terceiro (terceiro) wrote :

Looks good to me

 review approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lava_scheduler_tool/commands.py'
--- lava_scheduler_tool/commands.py 2012-05-11 04:12:23 +0000
+++ lava_scheduler_tool/commands.py 2013-04-17 09:47:30 +0000
@@ -16,6 +16,9 @@
16# You should have received a copy of the GNU Lesser General Public License16# You should have received a copy of the GNU Lesser General Public License
17# along with lava-scheduler-tool. If not, see <http://www.gnu.org/licenses/>.17# along with lava-scheduler-tool. If not, see <http://www.gnu.org/licenses/>.
1818
19import os
20import sys
21import argparse
19import xmlrpclib22import xmlrpclib
2023
21from lava_tool.authtoken import AuthenticatingServerProxy, KeyringAuthBackend24from lava_tool.authtoken import AuthenticatingServerProxy, KeyringAuthBackend
@@ -88,3 +91,44 @@
88 server = AuthenticatingServerProxy(91 server = AuthenticatingServerProxy(
89 self.args.SERVER, auth_backend=KeyringAuthBackend())92 self.args.SERVER, auth_backend=KeyringAuthBackend())
90 server.scheduler.cancel_job(self.args.JOB_ID)93 server.scheduler.cancel_job(self.args.JOB_ID)
94
95
96class job_output(Command):
97 """
98 Get job output from the scheduler.
99 """
100
101 @classmethod
102 def register_arguments(cls, parser):
103 super(job_output, cls).register_arguments(parser)
104 parser.add_argument("SERVER")
105 parser.add_argument("JOB_ID",
106 type=int,
107 help="Job ID to download output file")
108 parser.add_argument("--overwrite",
109 action="store_true",
110 help="Overwrite files on the local disk")
111 parser.add_argument("--output", "-o",
112 type=argparse.FileType("wb"),
113 default=None,
114 help="Alternate name of the output file")
115
116 def invoke(self):
117 if self.args.output is None:
118 filename = str(self.args.JOB_ID) + '_output.txt'
119 if os.path.exists(filename) and not self.args.overwrite:
120 print >> sys.stderr, "File {filename!r} already exists".format(
121 filename=filename)
122 print >> sys.stderr, "You may pass --overwrite to write over it"
123 return -1
124 stream = open(filename, "wb")
125 else:
126 stream = self.args.output
127 filename = self.args.output.name
128
129 server = AuthenticatingServerProxy(
130 self.args.SERVER, auth_backend=KeyringAuthBackend())
131 stream.write(server.scheduler.job_output(self.args.JOB_ID).data)
132
133 print "Downloaded job output of {0} to file {1!r}".format(
134 self.args.JOB_ID, filename)
91135
=== modified file 'setup.py'
--- setup.py 2012-04-04 05:22:32 +0000
+++ setup.py 2013-04-17 09:47:30 +0000
@@ -38,6 +38,7 @@
38 submit-job = lava_scheduler_tool.commands:submit_job38 submit-job = lava_scheduler_tool.commands:submit_job
39 resubmit-job = lava_scheduler_tool.commands:resubmit_job39 resubmit-job = lava_scheduler_tool.commands:resubmit_job
40 cancel-job = lava_scheduler_tool.commands:cancel_job40 cancel-job = lava_scheduler_tool.commands:cancel_job
41 job-output = lava_scheduler_tool.commands:job_output
41 [lava_tool.commands]42 [lava_tool.commands]
42 submit-job = lava_scheduler_tool.commands:submit_job43 submit-job = lava_scheduler_tool.commands:submit_job
43 resubmit-job = lava_scheduler_tool.commands:resubmit_job44 resubmit-job = lava_scheduler_tool.commands:resubmit_job

Subscribers

People subscribed via source and target branches