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
|
||||
|
||||
|
||||
# __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():
|
||||
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__':
|
||||
main()
|
||||
|
|
|
@ -147,8 +147,13 @@ class Boxes2INX:
|
|||
self.writeINX(name, box, path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
def main() -> None:
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: boxes2inkscape TARGETPATH")
|
||||
return
|
||||
b = Boxes2INX()
|
||||
b.writeAllINX(sys.argv[1])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -138,9 +138,14 @@ msgstr ""
|
|||
f.write('msgstr ""\n')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
def main() -> None:
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: boxes2pot TARGETPATH")
|
||||
return
|
||||
b = Boxes2pot()
|
||||
b.readBoxes()
|
||||
b.writePOT(sys.argv[1])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -74,5 +74,9 @@ class boxesPyWrapper(inkex.GenerateExtension):
|
|||
return group
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main() -> None:
|
||||
boxesPyWrapper().run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -683,7 +683,7 @@ def get_qrcode(url, format):
|
|||
return image_bytes.getvalue()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument("--host", default="")
|
||||
|
@ -707,6 +707,10 @@ if __name__ == "__main__":
|
|||
fc.stop()
|
||||
httpd.server_close()
|
||||
print("BoxesServer stops.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
else:
|
||||
boxserver = BServer(url_prefix='/boxes.py', static_url="https://florianfesti.github.io/boxes/static")
|
||||
application = boxserver.serve
|
||||
|
|
Loading…
Reference in New Issue