]> git.phdru.name Git - mimedecode.git/commitdiff
Add option -O to set the destination directory
authorOleg Broytman <phd@phdru.name>
Mon, 10 Mar 2014 20:36:47 +0000 (00:36 +0400)
committerOleg Broytman <phd@phdru.name>
Mon, 10 Mar 2014 20:36:47 +0000 (00:36 +0400)
ANNOUNCE
TODO
mimedecode.docbook
mimedecode.py

index 613982dcf240370063a68bc8a21fe3960ae03ab5..c9bb92f49437e33752c7a2f7f26df688a8ece254 100644 (file)
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -33,6 +33,8 @@ level).
 
    Add option -B to skip content-transfer-decoding binary attachments.
 
+   Add option -O to set the destination directory.
+
    Fix a minor bug: if a multipart message (or a subpart) lacks any textual
 content - avoid putting an excessive newline.
 
diff --git a/TODO b/TODO
index 29cc0a713969d91dcbf22e7cf5d752fdc2af0fb8..ec2be24f725bf0566e7db800ffb1b7437b8688cf 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,7 +1,5 @@
-Add option -O to set the destination directory.
-
 Add options --save-headers, --save-body and --save-message to save
-decoded headers/bodies/messages of parts to files.
+decoded headers/bodies/messages to files.
 
 
 Release 2.5.0.
index 401197944585dd8bcc1656d430a7841dbdc3a89d..555c5f2525be9d84e7dcf442bfce9cf585bfe835 100644 (file)
@@ -92,6 +92,9 @@
       <arg choice="opt">
          <option>-Bbeit mask</option>
       </arg>
+      <arg choice="opt">
+         <option>-O dest_dir</option>
+      </arg>
       <arg choice="opt">
          <option>-o output_file</option>
       </arg>
       </listitem>
    </varlistentry>
 
+   <varlistentry>
+      <term>-O dest_dir</term>
+      <listitem>
+         <para>
+           Set destination directory for the output files. Default is current
+           directory.
+          </para>
+      </listitem>
+   </varlistentry>
+
    <varlistentry>
       <term>-o output_file</term>
       <listitem>
          <para>
-            Useful to set the output file in case of redirected stdin:
+            Set the output file. Uses destination directory from option -O.
+            Also useful in case of redirected stdin:
             <programlisting language="sh">mimedecode.py -o output_file &lt; input_file
 cat input_file | mimedecode.py -o output_file</programlisting>
          </para>
index 3a8cbbe533bbd29f4e7589b40ee44d8b635fa8bd..e832017b33670d0cd605c1650eb00c89b21d91a8 100755 (executable)
@@ -18,7 +18,7 @@ Broytman mimedecode.py version %s, %s
 def usage(code=0, errormsg=''):
     version(0)
     sys.stdout.write("""\
-        Usage: %s [-h|--help] [-V|--version] [-cCDP] [-H|--host=hostname] [-f charset] [-d header1[,h2,...]|*[,-h1,...]] [-p header1[,h2,h3,...]:param1[,p2,p3,...]] [-r header1[,h2,...]|*[,-h1,...]] [-R header1[,h2,h3,...]:param1[,p2,p3,...]] [--set-header header:value] [--set-param header:param=value] [-Bbeit mask] [-o output_file] [input_file [output_file]]
+        Usage: %s [-h|--help] [-V|--version] [-cCDP] [-H|--host=hostname] [-f charset] [-d header1[,h2,...]|*[,-h1,...]] [-p header1[,h2,h3,...]:param1[,p2,p3,...]] [-r header1[,h2,...]|*[,-h1,...]] [-R header1[,h2,h3,...]:param1[,p2,p3,...]] [--set-header header:value] [--set-param header:param=value] [-Bbeit mask] [-O dest_dir] [-o output_file] [input_file [output_file]]
 """ % me)
     if errormsg:
         sys.stderr.write(errormsg + '\n')
@@ -394,6 +394,7 @@ class GlobalOptions:
 
     input_filename = None
     output_filename = None
+    destination_dir = os.curdir
 
 g = GlobalOptions
 
@@ -403,7 +404,7 @@ def get_opts():
 
     try:
         options, arguments = getopt(sys.argv[1:],
-            'hVcCDPH:f:d:p:r:R:b:B:e:i:t:o:',
+            'hVcCDPH:f:d:p:r:R:b:B:e:i:t:O:o:',
             ['help', 'version', 'host=', 'set-header=', 'set-param='])
     except GetoptError:
         usage(1)
@@ -454,6 +455,8 @@ def get_opts():
             g.ignore_mask.append(value)
         elif option == '-e':
             g.error_mask.append(value)
+        elif option == '-O':
+            g.destination_dir = value
         elif option == '-o':
             g.output_filename = value
         else:
@@ -470,7 +473,7 @@ if __name__ == "__main__":
         g.input_filename = '-'
         infile = sys.stdin
         if g.output_filename:
-            outfile = open(g.output_filename, 'w')
+            outfile = open(os.path.join(g.destination_dir, g.output_filename), 'w')
         else:
             g.output_filename = '-'
             outfile = sys.stdout
@@ -483,7 +486,7 @@ if __name__ == "__main__":
             infile = open(arguments[0], 'r')
         if la == 1:
             if g.output_filename:
-                outfile = open(g.output_filename, 'w')
+                outfile = open(os.path.join(g.destination_dir, g.output_filename), 'w')
             else:
                 g.output_filename = '-'
                 outfile = sys.stdout
@@ -495,7 +498,7 @@ if __name__ == "__main__":
                 outfile = sys.stdout
             else:
                 g.output_filename = arguments[1]
-                outfile = open(arguments[1], 'w')
+                outfile = open(os.path.join(g.destination_dir, g.output_filename), 'w')
     else:
         usage(1, 'Too many arguments')