Mercurial > hgrepos > Python > apps > py-cutils
comparison dos2unix.py @ 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 |
comparison
equal
deleted
inserted
replaced
| 43:d856432a1cbb | 44:26a8d4e7c8ee |
|---|---|
| 57 opts = aparser.parse_args(args=argv) | 57 opts = aparser.parse_args(args=argv) |
| 58 | 58 |
| 59 if opts.keepdate: | 59 if opts.keepdate: |
| 60 raise NotImplementedError("--keepdate, -k") | 60 raise NotImplementedError("--keepdate, -k") |
| 61 | 61 |
| 62 return dos2unix(opts) | |
| 63 | |
| 64 | |
| 65 def gen_opts(files=[], newfile=False, keepdate=False, quiet=True): | |
| 66 if keepdate: | |
| 67 raise NotImplementedError("--keepdate, -k") | |
| 68 | |
| 69 if newfile and (len(files) % 2): | |
| 70 raise ValueError("need pairs of files") | |
| 71 | |
| 72 opts = argparse.Namespace(files=files, | |
| 73 newfile=newfile, | |
| 74 keepdate=keepdate, | |
| 75 quiet=quiet) | |
| 76 return opts | |
| 77 | |
| 78 | |
| 79 def dos2unix(opts): | |
| 62 if opts.newfile: | 80 if opts.newfile: |
| 63 return(_convert_copy(opts)) | 81 return _convert_copy(opts) |
| 64 else: | 82 else: |
| 65 return(_convert_inplace(opts)) | 83 return _convert_inplace(opts) |
| 66 | 84 |
| 67 | 85 |
| 68 def _convert_inplace(opts): | 86 def _convert_inplace(opts): |
| 69 lines = [] | 87 lines = [] |
| 70 for filename in opts.files: | 88 for filename in opts.files: |
