Hi,<br><br>This change adds a new command-line parameter "--outfile" in ovs-bugtool.<br>So users can specify their own final output filename.<br><br>thanks<br>Shih-Hao<br><br><br>diff --git a/debian/ovs-bugtool b/debian/ovs-bugtool<br>
index 09c879b..6556964 100755<br>--- a/debian/ovs-bugtool<br>+++ b/debian/ovs-bugtool<br>@@ -361,6 +361,7 @@ def main(argv = None):<br> print >>sys.stderr, "Error: ovs-bugtool must be run as root"<br>
return 1<br> <br>+ output_file = None<br> output_type = 'tar.bz2'<br> output_fd = -1<br> <br>@@ -370,7 +371,8 @@ def main(argv = None):<br> try:<br> (options, params) = getopt.gnu_getopt(<br>
argv, 'sy', ['capabilities', 'silent', 'yestoall', 'entries=',<br>- 'output=', 'outfd=', 'all', 'unlimited', 'debug'])<br>
+ 'output=', 'outfd=', 'outfile=', 'all', 'unlimited',<br>+ 'debug'])<br> except getopt.GetoptError, opterr:<br> print >>sys.stderr, opterr<br>
return 2<br>@@ -417,6 +419,9 @@ def main(argv = None):<br> print >>sys.stderr, "Invalid output file descriptor", output_fd<br> return 2<br> <br>+ if k == '--outfile':<br>
+ output_file = v<br>+<br> elif k == '--all':<br> entries = caps.keys()<br> elif k == '--unlimited':<br>@@ -433,6 +438,10 @@ def main(argv = None):<br> print >>sys.stderr, "Option '--outfd' only valid with '--output=tar'"<br>
return 2<br> <br>+ if output_fd != -1 and output_file is not None:<br>+ print >>sys.stderr, "Cannot set both '--outfd' and '--outfile'"<br>+ return 2<br>+<br> if ANSWER_YES_TO_ALL:<br>
output("Warning: '--yestoall' argument provided, will not prompt for individual files.")<br> <br>@@ -574,19 +583,24 @@ exclude those logs from the archive.<br> data['inventory.xml'] = {'cap': None, 'output': StringIOmtime(make_inventory(data, subdir))}<br>
<br> # create archive<br>- if output_fd == -1 and not os.path.exists(BUG_DIR):<br>- try:<br>- os.makedirs(BUG_DIR)<br>- except:<br>- pass<br>+ if output_fd == -1:<br>+ if output_file is None:<br>
+ dirname = BUG_DIR<br>+ else:<br>+ dirname = os.path.dirname(output_file)<br>+ if dirname and not os.path.exists(dirname):<br>+ try:<br>+ os.makedirs(dirname)<br>
+ except:<br>+ pass<br> <br> if output_fd == -1:<br> output_ts('Creating output file')<br> <br> if output_type.startswith('tar'):<br>- make_tar(subdir, output_type, output_fd)<br>
+ make_tar(subdir, output_type, output_fd, output_file)<br> else:<br>- make_zip(subdir)<br>+ make_zip(subdir, output_file)<br> <br> clean_tapdisk_logs()<br> <br>@@ -774,7 +788,7 @@ def load_plugins(just_capabilities = False):<br>
if label == '': label = None<br> cmd_output(dir, getText(el.childNodes), label)<br> <br>-def make_tar(subdir, suffix, output_fd):<br>+def make_tar(subdir, suffix, output_fd, output_file):<br>
global SILENT_MODE, data<br> <br> mode = 'w'<br>@@ -782,9 +796,12 @@ def make_tar(subdir, suffix, output_fd):<br> mode = 'w:bz2'<br> elif suffix == 'tar.gz':<br> mode = 'w:gz'<br>
- filename = "%s/%s.%s" % (BUG_DIR, subdir, suffix)<br> <br> if output_fd == -1:<br>+ if output_file is None:<br>+ filename = "%s/%s.%s" % (BUG_DIR, subdir, suffix)<br>+ else:<br>
+ filename = output_file<br> tf = tarfile.open(filename, mode)<br> else:<br> tf = tarfile.open(None, 'w', os.fdopen(output_fd, 'a'))<br>@@ -819,10 +836,13 @@ def make_tar(subdir, suffix, output_fd):<br>
print filename<br><br> <br>-def make_zip(subdir):<br>+def make_zip(subdir, output_file):<br> global SILENT_MODE, data<br> <br>- filename = "%s/%s.zip" % (BUG_DIR, subdir)<br>+ if output_file is None:<br>
+ filename = "%s/%s.zip" % (BUG_DIR, subdir)<br>+ else:<br>+ filename = output_file<br> zf = zipfile.ZipFile(filename, 'w', zipfile.ZIP_DEFLATED)<br> <br> try:<br><br><br>