Ejemplo n.º 1
0
def create_deletion_request(args):

    gws_root = gws.get_gws_root_from_path(args.directory)
    rm = RequestsManager(gws_root)
    req = rm.create_deletion_request({'orig_path': args.directory})
    print("created request")
    req.dump()
Ejemplo n.º 2
0
def main():

    args = parse_args()

    if args.migrate:
        request_types = ['migration']
    elif args.retrieve:
        request_types = ['retrieval']
    elif args.delete:
        request_types = ['deletion']
    else:
        request_types = None  # no filter

    actions = []
    # monitor before submit (avoids pointlessly checking requests
    # that have only just been submitted)
    if args.monitor:
        actions.append(Monitor)
    elif args.submit:
        actions.append(Submit)
    else:
        actions = [Monitor, Submit]

    for gws_path in args.gws:
        gws_root = gws.get_gws_root_from_path(gws_path)

        if not gws.am_gws_manager(gws_root):
            print(
                "Skipping group workspace {} - it seems you are not the GWS manager"
                .format(gws_root))
            continue

        reqs_mgr = RequestsManager(gws_root)

        for action in actions:

            reqs = reqs_mgr.scan(all_users=True,
                                 statuses=(action.input_status, ),
                                 request_types=request_types)

            reqs.sort(key=lambda req: req.reqid)

            for req in reqs:
                method = getattr(req, action.method)
                try:
                    message = method()
                    if message:
                        print(message)
                except Exception as err:
                    print("{} of request {}: failed with: {}".format(
                        action.name, req.reqid, err))
                    if args.debug:
                        print('=============')
                        print(err)
                        print(get_traceback())
                        print('=============')
Ejemplo n.º 3
0
def create_migration_request(args):

    # using exists rather than isdir - a file will actually work, although the usage
    # message doesn't advertise that migrating a file at a time is possible
    if not os.path.exists(args.directory):
        raise ValueError("path {} does not exist".format(args.directory))

    gws_root = gws.get_gws_root_from_path(args.directory)
    rm = RequestsManager(gws_root)
    req = rm.create_migration_request({'path': args.directory})
    print("created request")
    req.dump()
Ejemplo n.º 4
0
def list_requests(args):

    gws_root = gws.get_gws_root_from_path(args.gws)

    statuses = None
    if args.current:
        statuses = (RequestStatus.NEW, RequestStatus.SUBMITTED)

    mgr = RequestsManager(gws_root)
    for req in mgr.scan(all_users=args.all_users,
                        statuses=statuses,
                        include_archived=args.include_archived):
        req.dump()
Ejemplo n.º 5
0
def main():

    args = parse_args()

    gws_root = gws.get_gws_root_from_path(args.gws)

    if not gws.am_gws_manager(gws_root):
        print("Exiting")
        sys.exit(1)

    mgr = RequestsManager(gws_root)
    try:
        mgr.initialise()
    except (OSError, NotInitialised):
        print("Initialisation failed")
        sys.exit(1)
    print("created control files/directories under {}".format(mgr.base_dir))
Ejemplo n.º 6
0
def main():

    args = parse_args()
    gws_root = gws.get_gws_root_from_path(args.gws)

    statuses = None
    if args.current:
        statuses = (RequestStatus.NEW, RequestStatus.SUBMITTED)

    try:
        mgr = RequestsManager(gws_root)
        for req in mgr.scan(all_users=args.all_users,
                            statuses=statuses):
            req.dump()
    except Exception as exc:
        print(("Listing requests failed with the following error:\n {}"
               ).format(exc))
        raise
        sys.exit(1)
Ejemplo n.º 7
0
def create_retrieval_request(args):

    gws_root = gws.get_gws_root_from_path(args.orig_dir)

    if (args.dest_dir
            and gws.get_gws_root_from_path(args.dest_dir) != gws_root):
        raise Exception("You cannot restore to a different Group Workspace.")

    dest_dir = args.dest_dir or args.orig_dir
    if os.path.exists(dest_dir) and not (os.path.isdir(dest_dir)
                                         and not os.listdir(dest_dir)):
        raise ValueError(
            "destination directory {} exists and is not an empty directory".
            format(dest_dir))

    rm = RequestsManager(gws_root)

    req = rm.create_retrieval_request({
        'orig_path': args.orig_dir,
        'new_path': args.dest_dir
    })
    print("created request")
    req.dump()
Ejemplo n.º 8
0
def main():

    args = parse_args()

    today = datetime.date.today()
    archive_up_to = today - datetime.timedelta(days=args.days)

    for gws_path in args.gws:
        gws_root = gws.get_gws_root_from_path(gws_path)

        if not gws.am_gws_manager(gws_root):
            print(
                "Skipping group workspace {} - it seems you are not the GWS manager"
                .format(gws_root))
            continue

        reqs_mgr = RequestsManager(gws_root)

        for req in reqs_mgr.scan(all_users=True, statuses=finished_statuses):

            if req.date <= archive_up_to:
                print('Archiving {}'.format(req))
                req.archive()
Ejemplo n.º 9
0
def withdraw_request(args):

    gws_root = gws.get_gws_root_from_path(args.gws)
    rm = RequestsManager(gws_root)
    rm.withdraw(args.id)
    print("withdrew request id={}".format(args.id))