Пример #1
0
    def _read_groups_from_workbook(self):
        """
        Reads all the groups from the workbook.
        """

        table_sheet = self.workbook.sheet_by_name("Groups")
        indices = self.indices["Groups"]

        for row_count in range(1, table_sheet.nrows):
            row = table_sheet.row_values(rowx=row_count, start_colx=0)

            # Name", "Display Name", "Description", "Groups", "Visibility"
            group_name = row[indices["Name"]]
            display_name = row[indices["Display Name"]]
            description = row[indices["Description"]]
            visibility = row[indices["Visibility"]]

            groups = []
            if row[indices["Groups"]] and row[indices["Groups"]]:
                groups = ast.literal_eval(
                    row[indices["Groups"]]
                )  # assumes a valid list format, e.g. ["a", "b", ...]
            try:
                group = Group(
                    name=group_name,
                    display_name=display_name,
                    description=description,
                    group_names=groups,
                    visibility=visibility,
                )
                # The format should be consistent with only one group per line.
                self.users_and_groups.add_group(
                    group, duplicate=UsersAndGroups.RAISE_ERROR_ON_DUPLICATE)
            except:
                eprint("Error reading group with name %s" % group_name)
def valid_args(args):
    """
    Verifies that the arguments are valid.  Don't quite validate all, so could still fail.
    :param args: List of arguments from the command line and defaults.
    :return:  True if valid.
    :rtype: bool
    """
    is_valid = True
    if args.ts_url is None or args.username is None or args.password is None or args.from_user is None or args.to_user is None:
        eprint("Missing required parameters.")
        is_valid = False

    return is_valid
Пример #3
0
def valid_args(args):
    """
    Verifies that the arguments are valid.
    :param args: List of arguments from the command line and defaults.
    :return:  True if valid.
    :rtype: bool
    """
    is_valid = True
    if args.ts_url is None:
        eprint("Missing TS URL")
        is_valid = False

    # Must provide a filename that exists.  This doesn't check that the file is valid.
    if args.filename is None or not os.path.isfile(args.filename):
        eprint("A valid file path much be specified.")
        is_valid = False

    return is_valid
Пример #4
0
def valid_args(args):
    """
    Verifies that the arguments are valid.
    :param args: List of arguments from the command line and defaults.
    :return:  True if valid.
    :rtype: bool
    """
    is_valid = True
    if args.ts_url is None:
        eprint("Missing TS URL")
        is_valid = False

    # Allow some variation for excel for ease of use.
    if args.output_type not in ["xls", "excel", "json"]:
        eprint("Invalid output_type parameter %s" % args.output_type)
        is_valid = False

    return is_valid
Пример #5
0
def valid_args(args):
    """
    Verifies that the arguments are valid.
    :param args: List of arguments from the command line and defaults.
    :return:  True if valid.
    :rtype: bool
    """
    is_valid = True

    if args.ts_url is None:
        eprint("Missing TS URL")
        is_valid = False

    if args.users is None and args.groups is None and args.user_file is None and args.group_file is None:
        eprint("Must provide a list of users and/or groups to delete.")
        is_valid = False

    return is_valid
Пример #6
0
def valid_args(args):
    """
    Verifies that the arguments are valid.
    :param args: List of arguments from the command line and defaults.
    :return:  True if valid.
    :rtype: bool
    """
    is_valid = True
    if args.ts_url is None:
        eprint("Missing TS URL")
        is_valid = False

    if not args.guids and not args.filename:
        eprint(
            "Must provide a list of GUIDs or a file containing a list of GUIDs"
        )
        is_valid = False

    return is_valid
Пример #7
0
    def _verify_file_format(self):
        """
        :return: True if the format of the workbook is valid.
        :rtype: bool
        """
        is_valid = True
        sheet_names = self.workbook.sheet_names()
        for required_sheet in UGXLSReader.required_sheets:
            if required_sheet not in sheet_names:
                eprint("Error:  missing sheet %s!" % required_sheet)
                is_valid = False
            else:
                sheet = self.workbook.sheet_by_name(required_sheet)
                header_row = sheet.row_values(rowx=0, start_colx=0)
                for required_column in UGXLSReader.required_columns[
                        required_sheet]:
                    if required_column not in header_row:
                        eprint("Error:  missing column %s in sheet %s!" %
                               (required_column, required_sheet))
                        is_valid = False

        return is_valid
Пример #8
0
    def _read_users_from_workbook(self):
        """
        Reads all the users from the workbook.
        """

        table_sheet = self.workbook.sheet_by_name("Users")
        indices = self.indices["Users"]

        for row_count in range(1, table_sheet.nrows):
            row = table_sheet.row_values(rowx=row_count, start_colx=0)

            # "Name", "Password", "Display Name", "Email", "Description", "Groups", "Visibility"
            username = row[indices["Name"]]
            password = row[indices["Password"]]
            display_name = row[indices["Display Name"]]
            email = row[indices["Email"]]
            groups = []
            if row[indices["Groups"]] and row[indices["Groups"]]:
                groups = ast.literal_eval(
                    row[indices["Groups"]]
                )  # assumes a valid list format, e.g. ["a", "b", ...]
            visibility = row[indices["Visibility"]]

            try:
                user = User(
                    name=username,
                    password=password,
                    display_name=display_name,
                    mail=email,
                    group_names=groups,
                    visibility=visibility,
                )
                # The format should be consistent with only one user per line.
                self.users_and_groups.add_user(
                    user, duplicate=UsersAndGroups.RAISE_ERROR_ON_DUPLICATE)
            except:
                eprint("Error reading user with name %s" % username)