Merge lp://qastaging/~liuyq0307/lava-android-test/extract-attachments into lp://qastaging/lava-android-test

Proposed by Yongqin Liu
Status: Merged
Merged at revision: 191
Proposed branch: lp://qastaging/~liuyq0307/lava-android-test/extract-attachments
Merge into: lp://qastaging/lava-android-test
Diff against target: 111 lines (+68/-3)
2 files modified
lava_android_test/commands.py (+67/-3)
setup.py (+1/-0)
To merge this branch: bzr merge lp://qastaging/~liuyq0307/lava-android-test/extract-attachments
Reviewer Review Type Date Requested Status
Andy Doan (community) Approve
Review via email: mp+118463@code.qastaging.launchpad.net

This proposal supersedes a proposal from 2012-08-06.

Description of the change

add extract-attachments sub command to extract the log or image files from the json format result file
updated according to the review comment

To post a comment you must log in.
Revision history for this message
Andy Doan (doanac) wrote : Posted in a previous version of this proposal

On 08/06/2012 02:02 AM, Yongqin Liu wrote:
> === modified file 'lava_android_test/commands.py'
> --- lava_android_test/commands.py 2012-06-28 11:29:49 +0000
> +++ lava_android_test/commands.py 2012-08-06 07:01:28 +0000
<snip>
> + def invoke(self):
> +
> + if not os.path.exists(self.args.result_file):
> + raise LavaCommandError("The specified result file(%s) "
> + "is not existed." % self.args.result_file)

Bad grammar: This should be "The specified file(%s) does not exist"

> + msg = "extract attachment file from result bundle file(%s)" % (
> + self.args.result_file)
> + self.say_begin(msg)
> + badchars = "[^a-zA-Z0-9\._-]"

badchars? looks like these are "good" chars?

> + with open(self.args.result_file) as stream:
> + jobdata = stream.read()
> + result_data = DocumentIO.loads(jobdata)[1]
> + test_runs = result_data.get('test_runs')
> + attachment_dir = mkdtemp(prefix='attachments-', dir=os.path.curdir)
> + for test in test_runs:
> + test_id = test.get('test_id').replace(" ", "_")
> + test_id = re.sub(badchars, "_", test_id)
> + target_dir = mkdtemp(prefix='%s' % test_id, dir=attachment_dir)

maybe this should be a command line option for the user to specify the
output directory?

> + print "The test id is: %s" % test_id
> + attachments = test.get('attachments', [])
> + for attach in attachments:
> + pathname = attach.get('pathname')
> + file_name = os.path.basename(pathname)
> + content_decoded = base64.standard_b64decode(
> + attach.get("content"))
> + with open(os.path.join(target_dir, file_name), 'a') as fd:

you are opening the file in append mode, shouldn't it just be 'w' instead?

Revision history for this message
Yongqin Liu (liuyq0307) wrote : Posted in a previous version of this proposal

> On 08/06/2012 02:02 AM, Yongqin Liu wrote:
> > === modified file 'lava_android_test/commands.py'
> > --- lava_android_test/commands.py 2012-06-28 11:29:49 +0000
> > +++ lava_android_test/commands.py 2012-08-06 07:01:28 +0000
> <snip>
> > + def invoke(self):
> > +
> > + if not os.path.exists(self.args.result_file):
> > + raise LavaCommandError("The specified result file(%s) "
> > + "is not existed." %
> self.args.result_file)
>
> Bad grammar: This should be "The specified file(%s) does not exist"
Thanks, really very very bad:(

> > + msg = "extract attachment file from result bundle file(%s)" % (
> > +
> self.args.result_file)
> > + self.say_begin(msg)
> > + badchars = "[^a-zA-Z0-9\._-]"
>
> badchars? looks like these are "good" chars?
yes, the badchars are the chars that not "a-zA-Z0-9\._-" here.

> > + with open(self.args.result_file) as stream:
> > + jobdata = stream.read()
> > + result_data = DocumentIO.loads(jobdata)[1]
> > + test_runs = result_data.get('test_runs')
> > + attachment_dir = mkdtemp(prefix='attachments-',
> dir=os.path.curdir)
> > + for test in test_runs:
> > + test_id = test.get('test_id').replace(" ", "_")
> > + test_id = re.sub(badchars, "_", test_id)
> > + target_dir = mkdtemp(prefix='%s' % test_id,
> dir=attachment_dir)
>
> maybe this should be a command line option for the user to specify the
> output directory?
I add a directory option to support user specification.

> > + print "The test id is: %s" % test_id
> > + attachments = test.get('attachments', [])
> > + for attach in attachments:
> > + pathname = attach.get('pathname')
> > + file_name = os.path.basename(pathname)
> > + content_decoded = base64.standard_b64decode(
> > +
> attach.get("content"))
> > + with open(os.path.join(target_dir, file_name), 'a') as
> fd:
>
> you are opening the file in append mode, shouldn't it just be 'w' instead?
Thanks, change it to w

Revision history for this message
Andy Doan (doanac) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches