changeset 44:26a8d4e7c8ee

Enhance dos2unix to allow it more easily to be used as module from within other Python programs
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 19 Jan 2022 00:40:34 +0100
parents d856432a1cbb
children b25ef7293bf2
files dos2unix.py
diffstat 1 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/dos2unix.py	Wed Jan 19 00:16:43 2022 +0100
+++ b/dos2unix.py	Wed Jan 19 00:40:34 2022 +0100
@@ -59,10 +59,28 @@
     if opts.keepdate:
         raise NotImplementedError("--keepdate, -k")
 
+    return dos2unix(opts)
+
+
+def gen_opts(files=[], newfile=False, keepdate=False, quiet=True):
+    if keepdate:
+        raise NotImplementedError("--keepdate, -k")
+
+    if newfile and (len(files) % 2):
+        raise ValueError("need pairs of files")
+
+    opts = argparse.Namespace(files=files,
+                              newfile=newfile,
+                              keepdate=keepdate,
+                              quiet=quiet)
+    return opts
+
+
+def dos2unix(opts):
     if opts.newfile:
-        return(_convert_copy(opts))
+        return _convert_copy(opts)
     else:
-        return(_convert_inplace(opts))
+        return _convert_inplace(opts)
 
 
 def _convert_inplace(opts):