mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Start adding fmtwidth helper
This commit is contained in:
parent
6929bec4e6
commit
10c1831aad
2 changed files with 38 additions and 1 deletions
38
docs/pylib/fmtwidth.py
Normal file
38
docs/pylib/fmtwidth.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Format given files to a max width.
|
||||
|
||||
"""
|
||||
import glob
|
||||
import textwrap
|
||||
import argparse
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument("files")
|
||||
parser.add_argument("-w", '--width', dest="width", type=int, default=79)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
filepaths = glob.glob(args.files)
|
||||
|
||||
wrapper = textwrap.TextWrapper(
|
||||
width=args.width,
|
||||
break_long_words=False,
|
||||
expand_tabs=True,
|
||||
)
|
||||
|
||||
count = 0
|
||||
for filepath in filepaths:
|
||||
with open(filepath, 'r') as fil:
|
||||
txt = fil.read()
|
||||
txt = "\n".join(wrapper.wrap(txt))
|
||||
with open(filepath, 'w') as fil:
|
||||
fil.write(txt)
|
||||
count += 1
|
||||
|
||||
print(f"Wrapped {count} files.")
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
sphinx==2.4.4
|
||||
sphinx-multiversion==0.1.1
|
||||
lunr==0.5.8
|
||||
|
||||
# recommonmark custom branch with evennia-specific fixes
|
||||
git+https://github.com/evennia/recommonmark.git@evennia-mods#egg=recommonmark
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue