Add conf/profile

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2017-11-18 15:43:49 +01:00
commit 74a27f1c19
4 changed files with 23 additions and 8 deletions

View file

@ -29,16 +29,15 @@ class TrimSourceCmd(jwutils.Cmd):
for path in args.input:
with open(path, 'r+') as infile:
contents = infile.read()
name = os.path.basename(path)
ext = os.path.splitext(path)[1]
# TODO: support other types in this block
mime = magic.detect_from_content(contents).mime_type
if mime != 'text/plain':
raise Exception("unsupported file type", mime, "of", path)
name = os.path.basename(path)
ext = os.path.splitext(path)[1]
if name != 'Makefile' and ext != '.mk':
raise Exception("unsupported file type of", path)
mime = 'text/x-makefile'
if mime in [ 'text/plain', 'application/x-empty' ]:
if name != 'Makefile' and ext != '.mk':
raise Exception("unsupported file type of", path)
mime = 'text/x-makefile'
out = self._run(args, mime, path, contents)
infile.seek(0)
@ -55,6 +54,8 @@ class CmdBeautify(TrimSourceCmd):
return p
def _processTextXMakefile(self, args, mime, path, contents):
# -- assignments
r = ''
indent = args.indent_assignments
for line in contents.splitlines(True):
@ -63,6 +64,12 @@ class CmdBeautify(TrimSourceCmd):
r += line
continue
r += misc.pad(m.group(1), indent - len(m.group(2))) + m.group(2) + m.group(3) + ' ' + m.group(4) + '\n'
# -- trailing white space
contents = r
r = ''
for line in contents.splitlines(False):
r += line.rstrip() + '\n'
return r
def _run(self, args, mime, path, contents):