consolidator
/
makeArc.py
50 строк · 1.9 Кб
1import os2import zipfile3import yaml4import shutil5import paramiko6import getpass7
8repoHost="vsys01775"9repoUser="blokhin_sn"10repoPath="/home/blokhin_sn/repo/"11metafile="metadata.yml"12
13if __name__=="__main__":14try:15print("make distributive archive")16dist_path = os.path.dirname(os.path.realpath(__file__))+"\\dist"17with open(metafile,mode="r",encoding="UTF-8") as f:18metadata = yaml.load(f, Loader=yaml.FullLoader)19version = metadata["Version"]20productName = metadata["ProductName"]21zipName = f"{dist_path}\\{productName}-v.{version}.zip"22print(f"zip name: {zipName}")23zf = zipfile.ZipFile(zipName, "w",zipfile.ZIP_DEFLATED)24for dirname, subdirs, files in os.walk(f"{dist_path}\\{productName}"):25zf.write(dirname,dirname.replace(f"{dist_path}\\",""))26for filename in files:27itemName=os.path.join(dirname, filename)28arcName = itemName.replace(f"{dist_path}\\","")29zf.write(itemName,arcName)30print(arcName)31zf.close()32shutil.copyfile(metafile,f"{dist_path}\\{metafile}")33print("local copy done")34print("copy distributive to repo")35ssh = paramiko.SSHClient()36ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))37passw = getpass.getpass(f"Пароль {repoUser}@{repoHost}:")38ssh.connect(repoHost,username=repoUser,password=passw)39print(f"{repoHost} connected")40sftp = ssh.open_sftp()41remotepath=f"{repoPath}{productName}-v.{version}.zip"42print("sftp opened")43sftp.put(zipName,remotepath)44sftp.put(metafile,f"{repoPath}{metafile}")45print("files puted")46sftp.close()47ssh.close()48print("connection closed")49except Exception as exp:50print(f"archive error: {exp}")