Пример #1
0
def clin_list(args):
    clin_default_dir = get_default_dir(args)
    packagename = args.packagename
    versionnumber = args.versionnumber
    username = args.username
    allusers = args.allusers
    apiserver = None
    conf_path = u'%s/conf.yml' % clin_default_dir
    if os.path.exists(conf_path):
        with open(conf_path, u'r') as f:
            t = yaml.safe_load(f)
        if u'apiserver' in t:
            apiserver = t[u'apiserver']
    if not apiserver:
        apiserver = default_api_server

    client = ApiV1Client(apiserver)
    if allusers == u'yes':
        ret = client.get_users()
    elif username:
        ret = client.get_packages(username)
    elif packagename:
        ret = client.get_all_packages(packagename)
        username = ret[0][u'username']
        if versionnumber:
            ret = client.get_version(username, packagename, versionnumber)
        else:
            ret = client.get_versions(username, packagename)
    else:
        ret = client.get_all_packages()
    print(ret)
Пример #2
0
def clin_delete(args):
    clin_default_dir = get_default_dir(args)
    packagename = args.packagename
    versionnumber = args.versionnumber
    username = args.username
    password = args.password
    apiserver = None
    conf_path = u'%s/conf.yml' % clin_default_dir
    if os.path.exists(conf_path):
        with open(conf_path, u'r') as f:
            t = yaml.safe_load(f)
        if u'apiserver' in t:
            apiserver = t[u'apiserver']
            if not username:
                if u'username' in t:
                    username = t[u'username']
            if not password:
                if u'password' in t:
                    password = t[u'password']
                elif u'password_base64' in t:
                    password = base64.decodestring(t[u'password_base64'])
    if not apiserver:
        apiserver = default_api_server
    if not username:
        username = raw_input(u'username:'******'Enter password:')

    client = ApiV1Client(apiserver)
    if versionnumber:
        ret = client.delete_version(username, password, packagename,
                                    versionnumber)
    else:
        ret = client.delete_package(username, password, packagename)
    print(ret)
Пример #3
0
def clin_register(args):
    clin_default_dir = get_default_dir(args)
    conf_path = u'%s/conf.yml' % clin_default_dir
    apiserver = None
    if os.path.exists(conf_path):
        with open(conf_path, u'r') as f:
            t = yaml.safe_load(f)
        if u'apiserver' in t:
            apiserver = t[u'apiserver']
    if not apiserver:
        apiserver = default_api_server
    username = args.username
    password = args.password
    if not password:
        while True:
            pw1 = getpass.getpass(u'Enter password:'******'passworld should more than 3 characters')
                continue
            pw2 = getpass.getpass(u'Confirm password:'******'confirm incorrect')
                continue
            password = pw1
            break
    client = ApiV1Client(apiserver)
    ret = client.create_user(username, password)
    print(ret)
    print(base64.encodestring(password))
Пример #4
0
def clin_download(args):
    clin_default_dir = get_default_dir(args)
    packagename = args.packagename
    versionnumber = args.versionnumber
    download_dir = args.path
    if not versionnumber:
        versionnumber = u'last'

    apiserver = None
    conf_path = u'%s/conf.yml' % clin_default_dir
    if os.path.exists(conf_path):
        with open(conf_path, u'r') as f:
            t = yaml.safe_load(f)
        if u'apiserver' in t:
            apiserver = t[u'apiserver']
    if not apiserver:
        apiserver = default_api_server

    client = ApiV1Client(apiserver)
    ret = client.get_all_packages(packagename)
    username = ret[0][u'username']
    ret = client.get_version(username, packagename, versionnumber)
    download_link = ret[u'link']
    r = urllib2.urlopen(download_link)
    if not download_dir:
        download_dir = u'./'
    elif download_dir[-1] != u'/':
        download_dir = download_dir + u'/'
    if not os.path.exists(download_dir):
        os.mkdir(download_dir)
    service_name = u'%s-%s' % (packagename, versionnumber)
    download_name = service_name + u'.zip'
    f = open(download_dir + download_name, u'wb')
    f.write(r.read())
    f.close()
    if os.path.exists(download_dir + service_name):
        shutil.rmtree(download_dir + service_name)
    unzip_file(download_dir + download_name, download_dir + service_name)
    os.remove(download_dir + download_name)
Пример #5
0
def clin_upload(args):
    clin_default_dir = get_default_dir(args)
    packagename = args.packagename
    versionnumber = args.versionnumber
    description = args.description
    path = args.path
    username = args.username
    password = args.password
    apiserver = None
    conf_path = u'%s/conf.yml' % clin_default_dir
    if os.path.exists(conf_path):
        with open(conf_path, u'r') as f:
            t = yaml.safe_load(f)
        if u'apiserver' in t:
            apiserver = t[u'apiserver']
            if not username:
                if u'username' in t:
                    username = t[u'username']
            if not password:
                if u'password' in t:
                    password = t[u'password']
                elif u'password_base64' in t:
                    password = base64.decodestring(t[u'password_base64'])
    if not apiserver:
        apiserver = default_api_server
    if not username:
        username = raw_input(u'username:'******'Enter password:'******'/':
        path = path[0:-1]
    filepath = path + u'.zip'
    zip_dir(path, filepath)
    client = ApiV1Client(apiserver)
    ret = client.create_version(username, password, packagename, versionnumber,
                                description, filepath)
    os.remove(filepath)
    print(ret)
Пример #6
0
def clin_unregister(args):
    clin_default_dir = get_default_dir(args)
    username = args.username
    password = args.password
    apiserver = None
    conf_path = u'%s/conf.yml' % clin_default_dir
    if os.path.exists(conf_path):
        with open(conf_path, u'r') as f:
            t = yaml.safe_load(f)
        if u'apiserver' in t:
            apiserver = t[u'apiserver']
        if not password:
            if u'password' in t:
                password = t[u'password']
            elif u'password_base64' in t:
                password = base64.decodestring(t[u'password_base64'])
    if not apiserver:
        apiserver = default_api_server
    if not password:
        password = getpass.getpass(u'Enter password:')
    client = ApiV1Client(apiserver)
    ret = client.delete_user(username, password)
    print(ret)