mirror of
https://git.dn42.dev/dn42/registry.git
synced 2024-11-17 02:48:38 +01:00
add fmt tool
This commit is contained in:
parent
15fcebd4b4
commit
e407b0195c
@ -182,7 +182,20 @@ class FileDOM:
|
|||||||
self.schema = schema
|
self.schema = schema
|
||||||
self.src = src
|
self.src = src
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
length = 13
|
||||||
|
for i in self.dom:
|
||||||
|
if len(i[0]) > length:
|
||||||
|
length = len(i[0]) + 2
|
||||||
|
s = ""
|
||||||
|
for i in self.dom:
|
||||||
|
l = i[1].split("\n")
|
||||||
|
|
||||||
|
s += i[0] + ":" + " " * (length - len(i[0])) + l[0] + "\n"
|
||||||
|
for m in l[1:]:
|
||||||
|
s += " " * (length + 1) + m + "\n"
|
||||||
|
|
||||||
|
return s
|
||||||
def main(infile, schema):
|
def main(infile, schema):
|
||||||
|
|
||||||
log.debug("Check File: %s" % (infile))
|
log.debug("Check File: %s" % (infile))
|
||||||
@ -365,6 +378,12 @@ def get_args():
|
|||||||
parser_scan.add_argument('-m', '--use-mntner', nargs='?',
|
parser_scan.add_argument('-m', '--use-mntner', nargs='?',
|
||||||
help="Only scan files that has a matching MNT [Default None]", action="store")
|
help="Only scan files that has a matching MNT [Default None]", action="store")
|
||||||
|
|
||||||
|
parser_fmt = subparsers.add_parser('fmt', help='Format file')
|
||||||
|
parser_fmt.add_argument(
|
||||||
|
'infile', nargs="?", help="Path for dn42 data file", type=str)
|
||||||
|
parser_fmt.add_argument('-i', '--in-place',
|
||||||
|
help="Format file in place", action="store_true")
|
||||||
|
|
||||||
return vars(parser.parse_args())
|
return vars(parser.parse_args())
|
||||||
|
|
||||||
|
|
||||||
@ -410,3 +429,11 @@ if __name__ == '__main__':
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
elif ck == "FAIL":
|
elif ck == "FAIL":
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
elif args["command"] == "fmt":
|
||||||
|
dom = FileDOM(args["infile"])
|
||||||
|
if args["in_place"]:
|
||||||
|
with open(args["infile"], 'w+') as f:
|
||||||
|
f.write(str(dom))
|
||||||
|
|
||||||
|
print(str(dom))
|
||||||
|
Loading…
Reference in New Issue
Block a user