????

Your IP : 18.221.160.29


Current Path : /proc/self/root/proc/self/root/lib/Acronis/PyShell/site-tools/
Upload File :
Current File : //proc/self/root/proc/self/root/lib/Acronis/PyShell/site-tools/manage_creds.py

import argparse
import acrort
import acrobind

ANY_ARCHIVE_ID = '_any_archive_'

def parse_arguments():
    parser = argparse.ArgumentParser()
    parser.add_argument('--set-username', dest='username', default='')
    parser.add_argument('--set-password', dest='password')
    parser.add_argument('--list', action='store_true')
    parser.add_argument('--reset', action='store_true')
    parser.add_argument('--connection', nargs=3, metavar=('HOST', 'USERNAME', 'PASSWORD'))
    parser.add_argument('--resource-address', dest='resource', default=ANY_ARCHIVE_ID)
    parser.add_argument('--resource-type', dest='resource_type', default=acrort.access.CATEGORIES[acrort.access.ARCHIVE])
    return parser.parse_args()


def main():
    host = None
    args = parse_arguments()
    if args.connection is not None:
       host = args.connection[0]
       username = args.connection[1]
       password = args.connection[2]

    if host:
        connection = acrort.connectivity.Connection(acrort.connectivity.PROTO_MMS, host, (username, password))
    else:
        connection = acrort.connectivity.Connection(acrort.connectivity.PROTO_MMS)

    if args.password:
        if not args.resource_type or not args.resource:
            print('resource_type and resource arguments are required')
            return

        profile = connection.access.open_system_profile()
        print("Add new entry...")
        profile.add_account(resource_type=args.resource_type, resource_address=args.resource, user_name=args.username, password=args.password)
        print("Done")

    elif args.reset:
        if not args.resource_type or not args.resource:
            print('resource_type and resource arguments are required')
            return

        print("Removing entry...")
        profile = connection.access.open_system_profile()
        profile.delete_account(resource_type=args.resource_type, resource_address=args.resource)
        print("Done")

    elif args.list:
        print("List entries...")
        profile = connection.access.open_system_profile()
        for i in profile.select():
          print(i)
        print("Done")


if __name__ == '__main__':
    exit(acrobind.safe_execute(main))