Exemple #1
0
def parse_args():
    """
    Parse the arguments and check them for correctness

    :return: list of event ids, list of series ids (one of them will be None)
    :rtype: list, list
    """
    parser, optional_args, required_args = get_args_parser()

    optional_args.add_argument("-e",
                               "--events",
                               type=str,
                               nargs='+',
                               help="list of event ids")
    optional_args.add_argument("-s",
                               "--series",
                               type=str,
                               nargs='+',
                               help="list of series ids")

    args = parser.parse_args()

    if args.events and args.series:
        args_error(parser,
                   "You can only provide either events or series, not both")

    if not args.events and not args.series:
        args_error(parser,
                   "You have to provide at least one series or event id")

    return args.events, args.series
def parse_args():
    """
    Parse the arguments, check them, read in the digest password if necessary, and return everything.

    :rtype: str, list, list, bool, DigestLogin, bool, bool, bool, Checks, str
    :return: opencast url, chosen tenants, excluded tenants, whether to use https, the digest user and password,
             whether to print progress statements and whether to print progress bars, whether events without series are
             considered malformed, which data to check and the results directory
    """

    parser, optional_args, required_args = get_args_parser()

    required_args.add_argument("-o", "--opencast", type=str, help="url of the opencast instance without protocol",
                               required=True)
    optional_args.add_argument("-t", "--chosen-tenants", type=str, nargs='+', help="list of tenants to check")
    optional_args.add_argument("-e", "--excluded-tenants", type=str, nargs='+', help="list of tenants to be excluded")
    required_args.add_argument("-u", "--user", type=str, help="digest user", required=True)
    optional_args.add_argument("-p", "--password", type=str, help="digest password")
    optional_args.add_argument("-c", "--check", type=str, help="checks to perform",
                               choices=[Checks.DC, Checks.ACL, Checks.DC_ACL, Checks.OAIPMH, Checks.ALL],
                               default=Checks.ALL)
    optional_args.add_argument('-s', "--silent", action='store_true', help="disables progress output")
    optional_args.add_argument('-l', "--https", action='store_true', help="enables https")
    optional_args.add_argument('-n', "--no-fancy-output", action='store_true',
                               help="disables fancy output including the progress bars")
    optional_args.add_argument('-r', "--no-series-error", action='store_true',
                               help="enables treating events without series as malformed")
    optional_args.add_argument('-d', "--results-dir", type=str, help="directory where results should be stored")

    args = parser.parse_args()

    if not args.opencast and args.user:
        args_error(parser)

    if args.excluded_tenants and args.chosen_tenants:
        args_error(parser, "The options --chosen-tenants and --excluded-tenants can't both be defined.")

    if args.silent and args.no_fancy_output:
        args_error(parser, "The options --silent and --no-fancy-output can't both be defined.")

    if not args.password:
        digest_pw = read_digest_password()
    else:
        digest_pw = args.password

    if args.results_dir:
        results_dir = os.path.abspath(args.results_dir)
        if not os.path.isdir(results_dir):
            args_error(parser, "Directory for results does not exist.")
    else:
        results_dir = os.getcwd()

    return args.opencast, args.chosen_tenants, args.excluded_tenants, args.https, \
        DigestLogin(user=args.user, password=digest_pw), args.silent, args.no_fancy_output, args.no_series_error, \
        args.check, results_dir
Exemple #3
0
def parse_args():
    """
    Parse the arguments and check them for correctness

    :return: amount of groups
    :rtype: int
    """
    parser, optional_args, required_args = get_args_parser()
    optional_args.add_argument("-a",
                               "--amount",
                               type=int,
                               help="amount of groups")
    args = parser.parse_args()

    if args.amount and args.amount <= 0:
        args_error(parser, "Amount has to be positive, non-zero number")

    return args.amount
def parse_args():
    """
    Parse the arguments, check them for correctness, read in the digest password if necessary, and return everything.

    :return: Opencast URL, Whether to use https, digest user and password, path to backup of archive, list of
    media packages to be recovered, tenant id, workflow_id, whether to use the last version of a media package
    :rtype: str, bool, DigestLogin, str, list, str, str, bool
    """

    parser, optional_args, required_args = get_args_parser()

    required_args.add_argument("-o", "--opencast", type=str, help="url of running opencast instance without protocol",
                               required=True)
    optional_args.add_argument('-s', "--https", action='store_true', help="enables https")

    required_args.add_argument("-u", "--user", type=str, help="digest user", required=True)
    optional_args.add_argument("-p", "--password", type=str, help="digest password")

    optional_args.add_argument("-b", "--backup", type=str, help="path to backup")
    optional_args.add_argument("-m", "--media-packages", type=str, nargs='+', help="list of media package ids to be "
                               "restored")
    optional_args.add_argument("-t", "--tenant", type=str, help="tenant id")
    optional_args.add_argument('-w', "--workflow-id", type=str, help="id for workflow on ingest")
    optional_args.add_argument('-l', "--last-version", action='store_true', help="always recover last version of "
                               "media package")
    optional_args.add_argument('-r', "--rsync-history", type=str, help="path to rsync history to be checked as well")
    optional_args.add_argument('-i', "--ignore-errors", action='store_true',
                               help="whether to recover a media package despite errors")

    args = parser.parse_args()

    if not (args.opencast and args.user):
        args_error(parser)

    if args.backup and not os.path.isdir(args.backup):
        args_error(parser, "Backup directory does not exist.")

    if args.rsync_history and not os.path.isdir(args.rsync_history):
        args_error(parser, "Rsync history directory does not exist.")

    if not (args.backup or args.rsync_history):
        args_error(parser, "Either a path to the archive backup or to the rsync history has to be provided")

    if not args.password:
        digest_pw = read_digest_password()
    else:
        digest_pw = args.password

    digest_login = DigestLogin(user=args.user, password=digest_pw)

    return args.opencast, args.https, digest_login, args.backup, args.media_packages, args.tenant, args.workflow_id, \
        args.last_version, args.rsync_history, args.ignore_errors
Exemple #5
0
def parse_args():
    """
    Parse the arguments and check them for correctness

    :return: workflow definition, directory path
    :rtype: str, str
    """
    parser, optional_args, required_args = get_args_parser()
    required_args.add_argument("-w",
                               "--workflow",
                               type=str,
                               help="The workflow to start")
    required_args.add_argument(
        "-d",
        "--dir",
        type=str,
        help="The path to the directory containing the event id files")
    args = parser.parse_args()

    if not os.path.isdir(args.dir):
        args_error(parser, "Provided directory doesn't exist!")

    return args.workflow, args.dir
def parse_args():
    """
    Parse the arguments, check them for correctness, read in the digest password if necessary, and return everything.

    :rtype: str, bool, list, list, DigestLogin, int, int, bool, str
    :return: opencast url, whether to use https, chosen tenants, excluded tenants, the digest user and password,
    the waiting period between batches and the amount of workflows in a batch, whether to print progress statements, and
    the results directory
    """

    parser, optional_args, required_args = get_args_parser()

    required_args.add_argument(
        "-o",
        "--opencast",
        type=str,
        help="url of the opencast instance without protocol",
        required=True)
    optional_args.add_argument("-c",
                               "--chosen-tenants",
                               type=str,
                               nargs='+',
                               help="list of tenants to check")
    optional_args.add_argument("-e",
                               "--excluded-tenants",
                               type=str,
                               nargs='+',
                               help="list of tenants to be excluded")
    required_args.add_argument("-u",
                               "--user",
                               type=str,
                               help="digest user",
                               required=True)
    optional_args.add_argument("-p",
                               "--password",
                               type=str,
                               help="digest password")
    #optional_args.add_argument('-s', "--silent", action='store_true', help="disables progress output")
    optional_args.add_argument('-l',
                               "--https",
                               action='store_true',
                               help="enables https")
    optional_args.add_argument(
        '-n',
        "--no-fancy-output",
        action='store_true',
        help="disables fancy output including the progress bars")
    required_args.add_argument('-d',
                               "--results-dir",
                               type=str,
                               help="directory where results should be stored",
                               required=True)
    optional_args.add_argument('-w',
                               "--waiting-period",
                               type=int,
                               help="time in seconds between the starting of "
                               "workflows of two batches",
                               default=60)
    optional_args.add_argument(
        '-b',
        "--batch-size",
        type=int,
        help="amount of workflows that should be started right "
        "away",
        default=100)

    args = parser.parse_args()

    if not args.opencast and args.user:
        args_error(parser)

    if args.excluded_tenants and args.chosen_tenants:
        args_error(
            parser,
            "The options --chosen-tenants and --excluded-tenants can't both be defined."
        )

    #if args.silent and args.no_fancy_output:
    #    args_error(parser, "The options --silent and --no-fancy-output can't both be defined.")

    if args.batch_size <= 0:
        args_error(parser, "The batch size can't be <= 0.")

    if args.waiting_period < 0:
        args_error(parser, "The waiting period can't be negative.")

    results_dir = os.path.abspath(args.results_dir)
    if not os.path.isdir(results_dir):
        args_error(parser, "Directory for results does not exist")

    if not args.password:
        digest_pw = read_digest_password()
    else:
        digest_pw = args.password

    return args.opencast, args.https, args.chosen_tenants, args.excluded_tenants, \
        DigestLogin(user=args.user, password=digest_pw), args.waiting_period, args.batch_size, False, \
        args.no_fancy_output, results_dir
Exemple #7
0
def parse_args():
    """
    Parse the arguments, check them for correctness, read in the digest password if necessary, and return everything.

    :return: Opencast URL, list of paths to directories with distribution artefacts, whether to use https,
             chosen tenants, excluded tenants, channels, digest user and password, whether to print progress statements,
            whether to print progress bars
    :rtype: str, list, bool, list, list, list, DigestLogin, bool, bool
    """

    parser, optional_args, required_args = get_args_parser()

    required_args.add_argument("-o",
                               "--opencast",
                               type=str,
                               help="url of the opencast instance",
                               required=True)
    required_args.add_argument(
        "-d",
        "--distribution-dirs",
        type=str,
        nargs='+',
        help="list of distribution directories to check",
        required=True)
    optional_args.add_argument("-t",
                               "--chosen-tenants",
                               type=str,
                               nargs='+',
                               help="list of tenants to check")
    optional_args.add_argument("-e",
                               "--excluded-tenants",
                               type=str,
                               nargs='+',
                               help="list of tenants to be excluded")
    optional_args.add_argument("-c",
                               "--channels",
                               type=str,
                               nargs='+',
                               help="list of channels to be considered")
    required_args.add_argument("-u",
                               "--user",
                               type=str,
                               help="digest user",
                               required=True)
    optional_args.add_argument("-p",
                               "--password",
                               type=str,
                               help="digest password")
    optional_args.add_argument('-s',
                               "--silent",
                               action='store_true',
                               help="disables progress output")
    optional_args.add_argument('-l',
                               "--https",
                               action='store_true',
                               help="enables https")
    optional_args.add_argument(
        '-n',
        "--no-fancy-output",
        action='store_true',
        help="disables fancy output including the progress bars")

    args = parser.parse_args()

    if not args.opencast and args.user and args.distribution_dirs:
        args_error(parser)

    if args.excluded_tenants and args.chosen_tenants:
        args_error(
            parser,
            "The options --chosen-tenants and --excluded-tenants can't both be defined."
        )

    if args.silent and args.no_fancy_output:
        args_error(
            parser,
            "The options --silent and --no-fancy-output can't both be defined."
        )

    for dir_path in args.distribution_dirs:
        distribution_dir = os.path.abspath(dir_path)
        if not os.path.isdir(distribution_dir):
            args_error(
                parser,
                "One directory for distribution artefacts does not exist.")

    if not args.password:
        digest_pw = read_digest_password()
    else:
        digest_pw = args.password

    return args.opencast, args.distribution_dirs, args.https, args.chosen_tenants, args.excluded_tenants, \
           args.channels, DigestLogin(user=args.user, password=digest_pw), args.silent, args.no_fancy_output