Skip to content

Commit f742562

Browse files
committed
Fixes #39: Added option to removed repeated blank lines.
Also a crude version display using `pip show`
1 parent 4392a61 commit f742562

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ This will install (and update) *ttws* and also all its dependencies.
5858
-h, --help
5959
displays this help message
6060

61+
-v, --version
62+
displays version information
63+
6164
-s, --strip
6265
strips leading or trailing white spaces from info or
6366
revision strings that contain HTML documentation
@@ -78,6 +81,9 @@ This will install (and update) *ttws* and also all its dependencies.
7881
Only use this if your code is under version control
7982
and in combination with a careful code-diff review.
8083

84+
-b, --blanks
85+
suppress repeated empty output lines from *.mo files
86+
(This option should not be run in combination with others.)
8187

8288
## License
8389
See [UNLICENSE](UNLICENSE) file

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
META = {
2525
'name': 'ttws',
2626
'url': 'https://github.com/dietmarw/trimtrailingwhitespaces',
27-
'version': '0.7.0',
27+
'version': '0.8.0',
2828
'description': 'Script to remove trailing whitespaces from textfiles.',
2929
'classifiers': CLASSIFIERS,
3030
'license': 'UNLICENSE',

test/tests.mo

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ annotation (Diagram(coordinateSystem(extent={{-100,-100},{100,100}},
4444

4545
end LargeModel;
4646

47-

ttws/cli.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def main(args=None):
1616

1717
# Look for optional arguments:
1818
try:
19-
opts, dirnames = getopt.getopt(args, "hsc", ["help","strip","clean",
20-
"eol="])
19+
opts, dirnames = getopt.getopt(args, "hvsbc", ["help","version","strip","blanks","clean",
20+
"eol="])
2121
# If unknown option is given trigger the display message:
2222
except getopt.GetoptError:
2323
unknownOption(args)
@@ -35,8 +35,14 @@ def main(args=None):
3535
if opt in ("-h","--help"):
3636
usage(args)
3737
sys.exit(0)
38+
elif opt in ("-v","--version"):
39+
os.system('pip show ttws')
40+
sys.exit(0)
3841
elif opt in ("-c","--clean"):
3942
cleanOpt = True
43+
elif opt in ("-b","--blanks"):
44+
os.system('for fn in `find -name "*.mo"`; do cat -s $fn >$fn.1; mv $fn.1 $fn; done')
45+
sys.exit(0)
4046
elif opt in ("-s","--strip"):
4147
stripOpt = True
4248
elif opt in ("--eol"):
@@ -78,16 +84,15 @@ def main(args=None):
7884
else:
7985
print("skipping file of type %s: %s" % (filetype, filepath))
8086

81-
8287
def usage(script_name):
8388
"""Help message on usage."""
8489
message = """
8590
Usage: ttws [OPTIONS] <directory> [<directory> ...]
8691
87-
This script will recursively scan all text files in a given list of
88-
directories and remove all trailing white space in every line as well
89-
as multiple blank lines at the end of the file. Binary files and files
90-
residing in '.bzr', '.cvs', '.git', '.hg', '.svn' directories are
92+
This script will recursively scan all text files in a given list of
93+
directories and remove all trailing white space in every line as well
94+
as multiple blank lines at the end of the file. Binary files and files
95+
residing in '.bzr', '.cvs', '.git', '.hg', '.svn' directories are
9196
skipped.
9297
9398
Since the main application is for Modelica projects it expects all files
@@ -103,6 +108,9 @@ def usage(script_name):
103108
-h, --help
104109
displays this help message
105110
111+
-v, --version
112+
displays version information
113+
106114
-s, --strip
107115
strips leading or trailing white spaces from info or
108116
revision strings that contain HTML documentation
@@ -124,9 +132,12 @@ def usage(script_name):
124132
Only use this if your code is under version control
125133
and in combination with a careful code-diff review.
126134
135+
-b, --blanks
136+
suppress repeated empty output lines from *.mo files
137+
(This option should not be run in combination with others.)
138+
127139
""" % (extstring, repr(os.linesep))
128140
print(textwrap.dedent(message))
129141

130-
131142
if __name__ == "__main__":
132143
sys.exit(main())

0 commit comments

Comments
 (0)