|
@@ -0,0 +1,80 @@
|
|
|
+import argparse
|
|
|
+import subprocess
|
|
|
+import sys
|
|
|
+import tempfile
|
|
|
+from pathlib import Path
|
|
|
+
|
|
|
+
|
|
|
+class Fab:
|
|
|
+
|
|
|
+ def __init__(self, dir=None, filename=None):
|
|
|
+ self.dir = Path(dir) if dir else None
|
|
|
+ self.filename = Path(filename) if filename else None
|
|
|
+ if self.dir and self.dir.is_file() and not self.filename and not self.dir.name.lower().endswith(".py"):
|
|
|
+ self.filename = self.dir
|
|
|
+ self.dir = None
|
|
|
+
|
|
|
+ def build(self):
|
|
|
+ if self.dir is None:
|
|
|
+ print(f"Impossible de construire {dir}", sys.stderr)
|
|
|
+ exit(-1)
|
|
|
+
|
|
|
+
|
|
|
+ self._temp_dir_obj = tempfile.TemporaryDirectory()
|
|
|
+ directory = Path(self._temp_dir_obj.name)
|
|
|
+ setup = None
|
|
|
+ if self.dir.is_dir():
|
|
|
+ setup = self.dir / "setup.py"
|
|
|
+ elif self.dir.is_file():
|
|
|
+ setup = self.dir
|
|
|
+
|
|
|
+ self._run(sys.executable, setup, "bdist_wheel", "--dist-dir", directory)
|
|
|
+
|
|
|
+ self.filename = None
|
|
|
+ for file in directory.iterdir():
|
|
|
+ self.filename = file
|
|
|
+
|
|
|
+ def _run(self, *cmd):
|
|
|
+ cmd = [str(x) for x in cmd]
|
|
|
+ print(f"Executing: {' '.join(cmd)}")
|
|
|
+ ret = subprocess.run(cmd)
|
|
|
+ if ret.returncode:
|
|
|
+ print(f"Impossible de continuer, abandon")
|
|
|
+ exit(-1)
|
|
|
+
|
|
|
+
|
|
|
+ def upload(self, user, password):
|
|
|
+ if not self.filename or self.filename.is_file():
|
|
|
+ self.build()
|
|
|
+ if not self.filename:
|
|
|
+ print(f"Impossible de construire {self.dir}", sys.stderr)
|
|
|
+ exit(-1)
|
|
|
+ if not user:
|
|
|
+ user = input("Nom d'utlisateur: ").split("\n")[0]
|
|
|
+ if not password:
|
|
|
+ password = input("Mot de passe: ").split("\n")[0]
|
|
|
+
|
|
|
+
|
|
|
+ self._run("devpi", "login", user, f"--password", password)
|
|
|
+ self._run("devpi", "upload", self.filename)
|
|
|
+ self._run("devpi", "logoff")
|
|
|
+ print("Upload successfull")
|
|
|
+
|
|
|
+
|
|
|
+class Cmdline(argparse.ArgumentParser):
|
|
|
+
|
|
|
+ def __init__(self):
|
|
|
+ super().__init__()
|
|
|
+ self.add_argument("--user", help="Utilisateur", )
|
|
|
+ self.add_argument("--password", help="mot de passe", )
|
|
|
+ self.add_argument("target", help="Dossier, fichier setup ou wheel a fabriquer/uploader", type=Path)
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def parse(cls, args):
|
|
|
+ cmd = cls()
|
|
|
+ ret = cmd.parse_args(args if args is not None else sys.argv[1:0])
|
|
|
+ app = Fab(ret.target)
|
|
|
+ app.upload(ret.user, ret.password)
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ Cmdline.parse(sys.argv[1:])
|