Exemple #1
0
    def __init__(self,
                 path,
                 current_yr=None,
                 force_new_download=False,
                 forms=['PF', 'EZ', 'Full'],
                 backfill=2,
                 tolerance=1000,
                 do_validation=True,
                 clear_old=True,
                 partial_validation=True,
                 get_from_sql=True,
                 output_full=True):

        forms = [f.upper() for f in forms]
        self.forms = ['Full' if f == 'FULL' else f for f in forms]
        self.path = path
        self.force_new_download = force_new_download

        self.logger, self.start = self.start_logging(path, current_yr)

        self.data = data.Data(self, clear_old, get_from_sql, current_yr,
                              backfill)
        self.process = process.Process(self)
        self.validate = validate.Validate(self, tolerance, do_validation,
                                          partial_validation)
        self.write = write.Write(self, output_full)
Exemple #2
0
def main():

    validate_obj = validate.Validate()
    validate_obj.verify()

    unzip_obj = unzip.UnzipZip()
    unzip_obj.move_or_delete()
Exemple #3
0
 def __init__(self, filename):
     """
     Setup the connection and initialize the database.
     """
     self.log = logging.getLogger('DATABASE')
     self.valid = validate.Validate()
     self.filename = filename
     self.con = sqlite3.connect(self.filename)
     self.con.row_factory = sqlite3.Row
     self.cur = self.con.cursor()
    def evaluate(self, board, player, opponent):
        #Checking for Rows for X or O victory.
        Valobj = validate.Validate()
        win_p, win_o = self.gameObj.winning_number1, self.gameObj.winning_number2

        if Valobj.evaluate(board, win_p, player)==player:
           return +10
        elif Valobj.evaluate(board, win_o, opponent)==opponent:
           return -10

        #Else if none of them have won then return 0
        return 0
Exemple #5
0
 def post(self):
     data = json.loads(self.request.body)
     num = validate.Validate(data["tag"], data["code"])
     self.log.info("Validate Tag:%s Code:%s Num:%d", data["tag"],
                   data["code"], num)
     self.write({"num": num})
Exemple #6
0
        return json.dumps(False)


@app.route("/ums/changePassword/<netID>/<user>/<hmac>/<time>/")
def chPassword(netID, user, hmac, time):
    if handshake.verify(netID, user, hmac, time):
        password = acctMgr.mkPassword()
        if acctMgr.chPassword(user, password):
            handshake.sendPassword(netID, user, password)
            return "Your password has been emailed to you"
        else:
            return "Your password could not be reset, please try again later"
    else:
        return "An error occured, perhaps you have an old link?"


# ------------- Begin Program Setup --------------
# Perform global config loading
config = init()

# Create core objects
validate = validate.Validate(config)
handshake = handshake.Handshake(config)
acctMgr = accountServices.Manager(config)

# If we're being loaded without uwsgi, configure the internal server
if __name__ == "__main__":
    host = config["SETTINGS"]["serverAddr"].split(":")[0]
    port = int(config["SETTINGS"]["serverAddr"].split(":")[1]) or 5000
    app.run(host, port)
Exemple #7
0
    print("[+] 'input' for inputing the data")
    print("[+] 'list' for listing the blocks")


def inputBlock(chain):
    data_now = input("Enter you data here\n>")
    if (chain.CreateBlock(data_now)):
        print("The Block Successfully added!")


def listBlocks(chain):
    Chain.ShowBlocks()


Chain = blockchain.BlockChain()
validate = validate.Validate()

print("Welcome to BlockChain Based Records Keeping System\n")
print("Enter the command")
command = 'input'
while True:
    command = input("\n>")

    if command == 'input':
        inputBlock(Chain)
        print(validate.isValid(Chain.chain))
    elif command == 'list':
        listBlocks(Chain)
    elif command == 'exit':
        break
    else:
def test_diagonal_win(supply_board_validate):
    import validate
    obj = validate.Validate()
    board, win_num = supply_board_validate
    res = obj.diag_win(board, win_num)
    assert res == True, "Diagonal Win Case Failed"
def test_col_win(supply_board_validate):
    import validate
    obj = validate.Validate()
    board, win_num = supply_board_validate
    res = obj.col_win(board, win_num)
    assert res == True, "Column Win Case Failed"
def test_row_win(supply_board_validate):
    import validate
    obj = validate.Validate()
    board, win_num = supply_board_validate
    res = obj.row_win(board, win_num)
    assert res == True, "Row Win Case Failed"
Exemple #11
0
 def __init__(self, metaObj):
     self.metaObj = metaObj
     self.minimaxObj = minimax.minimax(metaObj)
     self.validateObj = validate.Validate()
     self.ioObj = io_file.io_file(metaObj)
Exemple #12
0
def engulf_existing_cluster(**kwargs):
    """
    Assuming proposals() has already been run to collect hardware profiles and
    all possible role assignments and common configuration, this will generate
    a policy.cfg with roles and assignments reflecting whatever cluster is
    currently deployed.  It will also suck in all the keyrings so that they're
    present when the configure stage is run.

    This assumes your cluster is named "ceph".  If it's not, things will break.
    """
    local = salt.client.LocalClient()
    settings = Settings()
    salt_writer = SaltWriter(**kwargs)

    # Make sure deepsea_minions contains valid minions before proceeding with engulf.
    minions = deepsea_minions.DeepseaMinions()
    search = minions.deepsea_minions
    validator = validate.Validate(
        "ceph", local.cmd(search, 'pillar.items', [], expr_form="compound"),
        [], validate.get_printer())
    validator.deepsea_minions(minions)
    if validator.errors:
        validator.report()
        return False

    policy_cfg = []

    # Check for firewall/apparmor.
    if not ready.check("ceph", True, search):
        return False

    # First, hand apply select Stage 0 functions
    local.cmd(search, "saltutil.sync_all", [], expr_form="compound")
    local.cmd(search, "state.apply", ["ceph.mines"], expr_form="compound")

    # Run proposals gathering directly.
    proposals()

    # Our imported hardware profile proposal path
    imported_profile = "profile-import"
    imported_profile_path = settings.root_dir + "/" + imported_profile

    # Used later on to compute cluster and public networks.
    mon_addrs = {}
    osd_addrs = {}

    ceph_conf = None
    previous_minion = None
    admin_minion = None

    mon_minions = []
    mgr_instances = []
    mds_instances = []
    rgw_instances = []

    for minion, info in local.cmd(search,
                                  "cephinspector.inspect", [],
                                  expr_form="compound").items():

        if type(info) is not dict:
            print("cephinspector.inspect failed on %s: %s" % (minion, info))
            return False

        if info["ceph_conf"] is not None:
            if ceph_conf is None:
                ceph_conf = info["ceph_conf"]
            else:
                if info["ceph_conf"] != ceph_conf:
                    # TODO: what's the best way to report errors from a runner?
                    print("ceph.conf on %s doesn't match ceph.conf on %s" %
                          (minion, previous_minion))
                    return False
            previous_minion = minion

        is_admin = info["has_admin_keyring"]

        if admin_minion is None and is_admin:
            # We'll talk to this minion later to obtain keyrings
            admin_minion = minion

        is_master = local.cmd(minion,
                              "pillar.get", ["master_minion"],
                              expr_form="compound")[minion] == minion

        if not info["running_services"].keys(
        ) and not is_admin and not is_master:
            # No ceph services running, no admin key, not the master_minion,
            # don't assign it to the cluster
            continue

        policy_cfg.append("cluster-ceph/cluster/" + minion + ".sls")

        if is_master:
            policy_cfg.append("role-master/cluster/" + minion + ".sls")
        elif is_admin:
            policy_cfg.append("role-admin/cluster/" + minion + ".sls")

        if "ceph-mon" in info["running_services"].keys():
            mon_minions.append(minion)
            policy_cfg.append("role-mon/cluster/" + minion + ".sls")
            policy_cfg.append("role-mon/stack/default/ceph/minions/" + minion +
                              ".yml")
            for minion, ipaddrs in local.cmd(
                    minion,
                    "cephinspector.get_minion_public_networks", [],
                    expr_form="compound").items():
                mon_addrs[minion] = ipaddrs

        if "ceph-osd" in info["running_services"].keys():
            # Needs a storage profile assigned (which may be different
            # than the proposals deepsea has come up with, depending on
            # how things were deployed)
            ceph_disks = local.cmd(minion,
                                   "cephinspector.get_ceph_disks_yml", [],
                                   expr_form="compound")
            if not ceph_disks:
                log.error("Failed to get list of Ceph OSD disks.")
                return [False]

            for minion, store in ceph_disks.items():
                minion_yml_dir = imported_profile_path + "/stack/default/ceph/minions"
                minion_yml_path = minion_yml_dir + "/" + minion + ".yml"
                _create_dirs(minion_yml_dir, "")
                salt_writer.write(minion_yml_path, store)

                minion_sls_data = {"roles": ["storage"]}
                minion_sls_dir = imported_profile_path + "/cluster"
                minion_sls_path = minion_sls_dir + "/" + minion + ".sls"
                _create_dirs(minion_sls_dir, "")
                salt_writer.write(minion_sls_path, minion_sls_data)

                policy_cfg.append(
                    minion_sls_path[minion_sls_path.find(imported_profile):])
                policy_cfg.append(
                    minion_yml_path[minion_yml_path.find(imported_profile):])

            for minion, ipaddrs in local.cmd(
                    minion,
                    "cephinspector.get_minion_cluster_networks", [],
                    expr_form="compound").items():
                osd_addrs[minion] = ipaddrs

        if "ceph-mgr" in info["running_services"].keys():
            policy_cfg.append("role-mgr/cluster/" + minion + ".sls")
            for i in info["running_services"]["ceph-mgr"]:
                mgr_instances.append(i)

        if "ceph-mds" in info["running_services"].keys():
            policy_cfg.append("role-mds/cluster/" + minion + ".sls")
            for i in info["running_services"]["ceph-mds"]:
                mds_instances.append(i)

        if "ceph-radosgw" in info["running_services"].keys():
            policy_cfg.append("role-rgw/cluster/" + minion + ".sls")
            for i in info["running_services"]["ceph-radosgw"]:
                rgw_instances.append(i)

        # TODO: what else to do for rgw?  Do we need to do something to
        # populate rgw_configurations in pillar data?

    if not admin_minion:
        print("No nodes found with ceph.client.admin.keyring")
        return False

    # TODO: this is really not very DRY...
    admin_keyring = local.cmd(admin_minion,
                              "cephinspector.get_keyring",
                              ["key=client.admin"],
                              expr_form="compound")[admin_minion]
    if not admin_keyring:
        print("Could not obtain client.admin keyring")
        return False

    mon_keyring = local.cmd(admin_minion,
                            "cephinspector.get_keyring", ["key=mon."],
                            expr_form="compound")[admin_minion]
    if not mon_keyring:
        print("Could not obtain mon keyring")
        return False

    osd_bootstrap_keyring = local.cmd(admin_minion,
                                      "cephinspector.get_keyring",
                                      ["key=client.bootstrap-osd"],
                                      expr_form="compound")[admin_minion]
    if not osd_bootstrap_keyring:
        print("Could not obtain osd bootstrap keyring")
        return False

    # If there's no MGR instances, add MGR roles automatically to all the MONs
    # (since Luminous, MGR is a requirement, so it seems reasonable to add this
    # role automatically for imported clusters)
    if not mgr_instances:
        print("No MGRs detected, automatically assigning role-mgr to MONs")
        for minion in mon_minions:
            policy_cfg.append("role-mgr/cluster/" + minion + ".sls")

    with open("/srv/salt/ceph/admin/cache/ceph.client.admin.keyring",
              'w') as keyring:
        keyring.write(admin_keyring)

    with open("/srv/salt/ceph/mon/cache/mon.keyring", 'w') as keyring:
        # following srv/salt/ceph/mon/files/keyring.j2, this includes both mon
        # and admin keyrings
        keyring.write(mon_keyring)
        keyring.write(admin_keyring)

    with open("/srv/salt/ceph/osd/cache/bootstrap.keyring", 'w') as keyring:
        keyring.write(osd_bootstrap_keyring)

    for i in mgr_instances:
        mgr_keyring = local.cmd(admin_minion,
                                "cephinspector.get_keyring", ["key=mgr." + i],
                                expr_form="compound")[admin_minion]
        if not mgr_keyring:
            print("Could not obtain mgr." + i + " keyring")
            return False
        with open("/srv/salt/ceph/mgr/cache/" + i + ".keyring",
                  'w') as keyring:
            keyring.write(mgr_keyring)

    for i in mds_instances:
        mds_keyring = local.cmd(admin_minion,
                                "cephinspector.get_keyring", ["key=mds." + i],
                                expr_form="compound")[admin_minion]
        if not mds_keyring:
            print("Could not obtain mds." + i + " keyring")
            return False
        with open("/srv/salt/ceph/mds/cache/" + i + ".keyring",
                  'w') as keyring:
            keyring.write(mds_keyring)

    for i in rgw_instances:
        rgw_keyring = local.cmd(admin_minion,
                                "cephinspector.get_keyring",
                                ["key=client." + i],
                                expr_form="compound")[admin_minion]
        if not rgw_keyring:
            print("Could not obtain client." + i + " keyring")
            return False
        with open("/srv/salt/ceph/rgw/cache/client." + i + ".keyring",
                  'w') as keyring:
            keyring.write(rgw_keyring)

    # Now policy_cfg reflects the current deployment, make it a bit legible...
    policy_cfg.sort()

    # ...but inject the unassigned line first so it takes precendence,
    # along with the global config bits (because they're prettier early)...
    policy_cfg = [
        "cluster-unassigned/cluster/*.sls",
        "config/stack/default/ceph/cluster.yml",
        "config/stack/default/global.yml"
    ] + policy_cfg

    # ...and write it out (this will fail with EPERM if someone's already
    # created a policy.cfg as root, BTW)
    with open("/srv/pillar/ceph/proposals/policy.cfg", 'w') as policy:
        policy.write("\n".join(policy_cfg) + "\n")

    # We've also got a ceph.conf to play with
    cp = configparser.RawConfigParser()
    # This little bit of natiness strips whitespace from all the lines, as
    # Python's configparser interprets leading whitespace as a line continuation,
    # whereas ceph itself is happy to have leading whitespace.
    cp.readfp(
        StringIO("\n".join([line.strip() for line in ceph_conf.split("\n")])))

    if not cp.has_section("global"):
        print("ceph.conf is missing [global] section")
        return False
    if not cp.has_option("global", "fsid"):
        print("ceph.conf is missing fsid")
        return False

    if not _replace_fsid_with_existing_cluster(cp.get("global", "fsid")):
        log.error(
            "Failed to replace derived fsid with fsid of existing cluster.")
        return [False]

    p_net_dict = _replace_public_network_with_existing_cluster(mon_addrs)
    if not p_net_dict['ret']:
        log.error(
            "Failed to replace derived public_network with public_network of existing cluster."
        )
        return [False]

    c_net_dict = _replace_cluster_network_with_existing_cluster(
        osd_addrs, p_net_dict['public_network'])
    if not c_net_dict['ret']:
        log.error(
            "Failed to replace derived cluster_network with cluster_network of existing cluster."
        )
        return [False]

    # write out the imported ceph.conf
    with open("/srv/salt/ceph/configuration/files/ceph.conf.import",
              'w') as conf:
        conf.write(ceph_conf)

    # ensure the imported config will be used
    _replace_key_in_cluster_yml("configuration_init", "default-import")

    return True
Exemple #13
0
    def __init__(self):
        self.ui = userinput.UserInput()
        self.gameboard = gameboard.Gameboard()
        self.validator = validate.Validate()
        self.color = 'white'

        self.captured_pieces = []
        self.white_pieces = []
        self.black_pieces = []
        for i in 'abcdefgh':
            self.white_pieces.append(
                piece.Piece(i + '2',
                            name='pawn',
                            color='white',
                            name_representation='\u2659'))
            self.black_pieces.append(
                piece.Piece(i + '7',
                            name='pawn',
                            color='black',
                            name_representation='\u265F'))
        for i in 'ah':
            self.white_pieces.append(
                piece.Piece(i + '1',
                            name='rook',
                            color='white',
                            name_representation='\u2656'))
            self.black_pieces.append(
                piece.Piece(i + '8',
                            name='rook',
                            color='black',
                            name_representation='\u265C'))
        for i in 'bg':
            self.white_pieces.append(
                piece.Piece(i + '1',
                            name='knight',
                            color='white',
                            name_representation='\u2658'))
            self.black_pieces.append(
                piece.Piece(i + '8',
                            name='knight',
                            color='black',
                            name_representation='\u265E'))
        for i in 'cf':
            self.white_pieces.append(
                piece.Piece(i + '1',
                            name='bishop',
                            color='white',
                            name_representation='\u2657'))
            self.black_pieces.append(
                piece.Piece(i + '8',
                            name='bishop',
                            color='black',
                            name_representation='\u265D'))

        self.white_pieces.append(
            piece.Piece('d1',
                        name='queen',
                        color='white',
                        name_representation='\u2655'))
        self.black_pieces.append(
            piece.Piece('d8',
                        name='queen',
                        color='black',
                        name_representation='\u265B'))
        self.white_pieces.append(
            piece.Piece('e1',
                        name='king',
                        color='white',
                        name_representation='\u2654'))
        self.black_pieces.append(
            piece.Piece('e8',
                        name='king',
                        color='black',
                        name_representation='\u265A'))