Refactor main to callable function
Preparation for `pyproject.toml` entry-point
This commit is contained in:
parent
8a62293a47
commit
3c45bfed80
|
@ -28,25 +28,6 @@ except ImportError:
|
||||||
import boxes.generators
|
import boxes.generators
|
||||||
|
|
||||||
|
|
||||||
# __version__ = get_distribution('boxes').version
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# version = 'boxes.py v{}'.format(__version__)
|
|
||||||
|
|
||||||
if len(sys.argv) > 1 and sys.argv[1].startswith("--id="):
|
|
||||||
del sys.argv[1]
|
|
||||||
if len(sys.argv) == 1:
|
|
||||||
print_usage()
|
|
||||||
elif sys.argv[1] == '--list':
|
|
||||||
list_grouped_generators()
|
|
||||||
else:
|
|
||||||
name = sys.argv[1].lower()
|
|
||||||
if name.startswith("--generator="):
|
|
||||||
name = name[12:]
|
|
||||||
run_generator(name, sys.argv[2:])
|
|
||||||
|
|
||||||
|
|
||||||
def print_usage():
|
def print_usage():
|
||||||
print(__doc__)
|
print(__doc__)
|
||||||
|
|
||||||
|
@ -113,5 +94,19 @@ def generators_by_name():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
if len(sys.argv) > 1 and sys.argv[1].startswith("--id="):
|
||||||
|
del sys.argv[1]
|
||||||
|
if len(sys.argv) == 1:
|
||||||
|
print_usage()
|
||||||
|
elif sys.argv[1] == '--list':
|
||||||
|
list_grouped_generators()
|
||||||
|
else:
|
||||||
|
name = sys.argv[1].lower()
|
||||||
|
if name.startswith("--generator="):
|
||||||
|
name = name[12:]
|
||||||
|
run_generator(name, sys.argv[2:])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -147,8 +147,13 @@ class Boxes2INX:
|
||||||
self.writeINX(name, box, path)
|
self.writeINX(name, box, path)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main() -> None:
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
print("Usage: boxes2inkscape TARGETPATH")
|
print("Usage: boxes2inkscape TARGETPATH")
|
||||||
|
return
|
||||||
b = Boxes2INX()
|
b = Boxes2INX()
|
||||||
b.writeAllINX(sys.argv[1])
|
b.writeAllINX(sys.argv[1])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
@ -138,9 +138,14 @@ msgstr ""
|
||||||
f.write('msgstr ""\n')
|
f.write('msgstr ""\n')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main() -> None:
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
print("Usage: boxes2pot TARGETPATH")
|
print("Usage: boxes2pot TARGETPATH")
|
||||||
|
return
|
||||||
b = Boxes2pot()
|
b = Boxes2pot()
|
||||||
b.readBoxes()
|
b.readBoxes()
|
||||||
b.writePOT(sys.argv[1])
|
b.writePOT(sys.argv[1])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
@ -74,5 +74,9 @@ class boxesPyWrapper(inkex.GenerateExtension):
|
||||||
return group
|
return group
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def main() -> None:
|
||||||
boxesPyWrapper().run()
|
boxesPyWrapper().run()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
|
@ -683,7 +683,7 @@ def get_qrcode(url, format):
|
||||||
return image_bytes.getvalue()
|
return image_bytes.getvalue()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def main() -> None:
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
parser.add_argument("--host", default="")
|
parser.add_argument("--host", default="")
|
||||||
|
@ -707,6 +707,10 @@ if __name__ == "__main__":
|
||||||
fc.stop()
|
fc.stop()
|
||||||
httpd.server_close()
|
httpd.server_close()
|
||||||
print("BoxesServer stops.")
|
print("BoxesServer stops.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
else:
|
else:
|
||||||
boxserver = BServer(url_prefix='/boxes.py', static_url="https://florianfesti.github.io/boxes/static")
|
boxserver = BServer(url_prefix='/boxes.py', static_url="https://florianfesti.github.io/boxes/static")
|
||||||
application = boxserver.serve
|
application = boxserver.serve
|
||||||
|
|
Loading…
Reference in New Issue