Beispiel #1
0
class CertPublisher:
    def __init__(self, src_file_csv, ya_dir):
        self.src_file_csv = src_file_csv
        self.ya_dir = ya_dir

        self.ya = YaDisk(conf['ya']['login'], conf['ya']['pass'])
        self.certs = {
            c['displayname'].split(".")[0]: c['path']
            for c in self.ya.ls('/{}'.format(ya_dir))
        }

    def share_cert_for(self, name):
        retries = 0
        while retries <= 5:
            retries += 1
            try:
                cert = self.certs[name]
                return self.ya.publish(cert)
            except Exception as e:
                click.echo(repr(e))
                sleep(1)
        return "###"

    def process_one(self, client, clients_processed):
        name, mail = client[:2]
        name = self._normalize_name(name)
        mail = self._normalize_mail(mail)
        ref = self.share_cert_for(name)
        res = (name.strip(), mail, ref)
        click.echo(res)
        clients_processed.append(res)

    def publish(self):
        # Read & schedule
        executor = ThreadPoolExecutor(max_workers=10)
        tasks = []
        clients_processed = []
        with open(self.src_file_csv) as inp:
            reader = csv.reader(inp, delimiter=',')
            for client in reader:
                tasks.append(
                    executor.submit(self.process_one, client,
                                    clients_processed))
        # Execute
        wait(tasks)
        click.echo("Processed {} certs".format(len(tasks)))
        # Write out
        out_path = os.path.join(
            os.path.dirname(self.src_file_csv),
            os.path.basename(self.src_file_csv).split(".")[0] + "_done.csv")
        with open(out_path, "w") as out:
            writer = csv.writer(out, delimiter=',')
            for p in clients_processed:
                writer.writerow(p)
        return out_path

    def _normalize_name(self, name):
        name = name.strip("'")
        name = name.strip()
        #name = name.split()
        #name = " ".join(part for part in name if part)
        return name

    def _normalize_mail(self, mail):
        mail = mail.strip("'")
        mail = mail.strip()
        return mail
BASE = args.base_dir
print(f'BASE DIR: "{BASE}"')

disk = YaDisk(args.login, args.password)
exe_file = None
for f in glob.glob(BASE + '\*.exe'):
    exe_file = f

if exe_file:
    deployed_exes = [
        x['path'] for x in disk.ls(YaDiskDir) if x['path'][-4:] == '.exe'
    ]
    src = os.path.realpath(exe_file)
    dst = YaDiskDir + '/' + os.path.basename(exe_file)
    disk.upload(src, dst)
    try:
        public_url = disk.publish(dst)
        resp = requests.post(
            URL,
            dict(token=args.secret,
                 version=args.soft_version,
                 download_link=public_url))
        assert resp.json()['success'] is True
    except:
        disk.rm(dst)
    else:
        for f in deployed_exes:
            disk.rm(f)
else:
    raise EnvironmentError('Exe file list is EMPTY!!!')
Beispiel #3
0
from YaDiskClient.YaDiskClient import YaDisk
import os
import sys

f_accounts = open('acc.txt','r')
acc_arr = [account for account in f_accounts]
f_accounts.close()
files_arr = os.listdir('.')
f_urls = open('urls.txt','w')
for files in files_arr:
    for account in acc_arr:
        email = account.split(':')[0]
        password = account.replace('\n','').split(':')[1]
        disk = YaDisk(email, password)
        disk.df()
        if files == 'urls.txt' or files == os.path.basename(__file__) or files == 'acc.txt':
            continue
        print(os.path.join(os.path.dirname(os.path.abspath(__file__)),files) + ' ---> ' + files)
        disk.upload(os.path.join(os.path.dirname(os.path.abspath(__file__)),files), files)
        shared_url = disk.publish('/' + files)
        f_urls.write('{} -->  Filename : {} -->  Shared Url : {}\n'.format(email,files,shared_url))
f_urls.close()
sys.exit()