def setUp(self):

        if sys.platform == "win32":
            self.schema_file1 = path.join(TESTDIR, "test_schema_vsimple.xml")
            assert (os_file_exists(self.schema_file1))
            self.schema_file2 = path.join(TESTDIR, "test_schema_vsimple2.xml")
            assert (os_file_exists(self.schema_file2))
        else:
            self.schema_file1 = os.path.join(
                os.environ["PYTHONPATH"], "test_misc/test_schema_vsimple.xml")
            self.schema_file2 = os.path.join(
                os.environ["PYTHONPATH"], "test_mis/test_schema_vsimple2.xml")

        schema_execute(self.schema_file1)

        datarows = {'tbl_col_name': [], 'tbl_rows': []}

        schema_data_get(self.schema_file1, 'workout', datarows)

        self.database1 = Database('fitness')

        with self.database1:
            tbl_rows_insert(self.database1, 'workout',
                            datarows['tbl_col_name'], datarows['tbl_rows'])

        schema_execute(self.schema_file2)
        schema_data_get(self.schema_file2, 'food', datarows)

        self.database2 = Database('diet')

        with self.database2:
            tbl_rows_insert(self.database2, 'food', datarows['tbl_col_name'],
                            datarows['tbl_rows'])
 def setUp(self):
     if sys.platform == "win32":
         self.schema_file = path.join(TESTDIR, "test_schema_simple.xml")
         assert (os_file_exists(self.schema_file))
     else:
         self.schema_file = os.path.join(
             os.environ["PYTHONPATH"], "test_misc/test_schema_simple.xml")
Пример #3
0
    def test_(self):

        write_text_to_file(
            self.filename, "database_name:" +
            encode(path.join(TESTDIR, TESTDBNAME), self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "sp_name:" + encode("student_schedule", self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "delete_flag:" + encode("False", self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "header_flag:" + encode("True", self.encoding) + "\n")
        append_text_to_file(
            self.filename, "sp_args:" + encode(
                "<root><students>70</students><days>M</days><periods>1</periods></root>",
                self.encoding) + "\n")

        result = DataStoredProc.stored_proc_by_file(
            self.filename, result_file=self.result_filename)
        self.assertEqual(result, [[
            'sSubjectLongDesc', 'sCourseNm', 'sClassFocusArea',
            'sFacultyFirstNm', 'cdDay', 'idTimePeriod', 'idLocation',
            'idSection', 'cdClassType', 'iFreq', 'idClassLecture'
        ],
                                  [
                                      u'Homeroom', u'Homeroom', None, u'Isaac',
                                      u'M', 1, 9, 165, u'Seminar', 5, 993
                                  ]])

        self.assertTrue(os_file_exists(self.result_filename))
        self.assertEqual(
            "sSubjectLongDesc^sCourseNm^sClassFocusArea^sFacultyFirstNm^cdDay^idTimePeriod^idLocation^idSection^cdClassType^iFreq^idClassLecture$$Homeroom^Homeroom^None^Isaac^M^1^9^165^Seminar^5^993",
            os_file_to_string(self.result_filename))
Пример #4
0
    def test_(self):
        write_text_to_file(
            self.filename, "database_name:" +
            encode(path.join(TESTDIR, TESTDBNAME), self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "sp_name:" + encode("student_schedule", self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "delete_flag:" + encode("False", self.encoding) + "\n")
        append_text_to_file(
            self.filename, "sp_args:" + encode(
                "<root><students>70</students><days>M</days><periods>1</periods></root>",
                self.encoding) + "\n")

        result = DataStoredProc.stored_proc_by_file(
            self.filename, result_file=self.result_filename)
        self.assertEqual(result, [[
            u'Homeroom', u'Homeroom', None, u'Isaac', u'M', 1, 9, 165,
            u'Seminar', 5, 993
        ]])

        self.assertTrue(os_file_exists(self.result_filename))
        self.assertEqual(
            "Homeroom^Homeroom^None^Isaac^M^1^9^165^Seminar^5^993",
            os_file_to_string(self.result_filename))
Пример #5
0
    def test_(self):

        write_text_to_file(
            self.filename, "database_name:" +
            encode(path.join(TESTDIR, TESTDBNAME), self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "sp_name:" + encode("student_schedule", self.encoding) + "\n")
        append_text_to_file(
            self.filename,
            "delete_flag:" + encode("False", self.encoding) + "\n")
        append_text_to_file(
            self.filename, "sp_args:" + encode(
                "<root><students>70</students><students>69</students><days>M</days><days>T</days><periods>1</periods><periods>2</periods></root>",
                self.encoding) + "\n")

        result = DataStoredProc.stored_proc_by_file(
            self.filename, result_file=self.result_filename)

        expected_results = [[
            u'Homeroom', u'Homeroom', None, u'Samantha', u'M', 1, 10, 163,
            u'Seminar', 5, 983
        ],
                            [
                                u'Homeroom', u'Homeroom', None, u'Isaac', u'M',
                                1, 9, 165, u'Seminar', 5, 993
                            ],
                            [
                                u'Movement', u'Movement', None, u'Michael',
                                u'M', 2, 37, 432, u'Seminar', 1, 1196
                            ],
                            [
                                u'Science', u'Science', None, u'John', u'M', 2,
                                4, 162, u'1on1', 1, 143
                            ],
                            [
                                u'Homeroom', u'Homeroom', None, u'Samantha',
                                u'T', 1, 10, 163, u'Seminar', 5, 984
                            ],
                            [
                                u'Homeroom', u'Homeroom', None, u'Isaac', u'T',
                                1, 9, 165, u'Seminar', 5, 994
                            ],
                            [
                                u'Foreign Language', u'Spanish 1', None,
                                u'Jamie', u'T', 2, 6, 451, u'Seminar', 2, 1218
                            ],
                            [
                                u'Work Period', u'Work Period', None,
                                u'Alyssa', u'T', 2, 37, 564, u'Seminar', 1, 713
                            ]]

        self.assertEqual(result, expected_results)

        self.assertTrue(os_file_exists(self.result_filename))
        self.assertEqual(
            os_file_to_string(self.result_filename),
            "Homeroom^Homeroom^None^Samantha^M^1^10^163^Seminar^5^983$$Homeroom^Homeroom^None^Isaac^M^1^9^165^Seminar^5^993$$Movement^Movement^None^Michael^M^2^37^432^Seminar^1^1196$$Science^Science^None^John^M^2^4^162^1on1^1^143$$Homeroom^Homeroom^None^Samantha^T^1^10^163^Seminar^5^984$$Homeroom^Homeroom^None^Isaac^T^1^9^165^Seminar^5^994$$Foreign Language^Spanish 1^None^Jamie^T^2^6^451^Seminar^2^1218$$Work Period^Work Period^None^Alyssa^T^2^37^564^Seminar^1^713"
        )
Пример #6
0
 def __enter__(self):
     dbfilepath = self.name+".sqlite"
     if self.testexists == True:
         if os_file_exists(dbfilepath) == False:
             errmsg = "sqlite database file not found:"+dbfilepath
             log.log(PRIORITY.FAILURE,msg=errmsg)
             raise Exception(errmsg)
     self.open()
Пример #7
0
 def _validate_filename(self,
                        fieldname,
                        encoding="unicode",
                        mustexist=True):
     """ check if filename exists
     :param fieldname:string or list of strings
     :rtype : -1 on failure or None
     """
     filepaths = getattr(self, fieldname).split("$$")
     for i in range(len(filepaths)):
         if os_file_exists(decode(filepaths[i], encoding)) == False:
             if mustexist == True:
                 return ([-1])
         #else:
         filepaths[i] = decode(filepaths[i], encoding)
     setattr(self, fieldname, filepaths)
Пример #8
0
def parse_args(argv):

    mandatory_flags = ['--access_type', '--input_filename']
    access_types = [
        'query', 'create', 'insert', 'table_exists', 'table_list',
        'table_info', 'database_exists'
    ]

    try:
        opts, args = getopt(argv[1:], "aiorf", ["access_type=", "input_filename=","output_filename=",\
                                                "runtime_path=","result_file="])
        for flag in mandatory_flags:
            if flag not in dict(opts).keys():
                raise GetoptError(flag, "needs to be present")

        man_config = {}  # mandatory flaags, hold the resulting, parsed flags
        opt_config = {}  # optional flags

        for flag, value in opts:
            if flag in ("-a", "--access_type"):
                if value not in access_types:
                    raise GetoptError(flag + " value not in " +
                                      str(access_types))
            elif flag in ("-i",
                          "--input_filename") or flag in ("-r",
                                                          "--runtime_path"):
                if os_file_exists(value) == False:
                    raise GetoptError(flag + "cannot find file" + value)
            elif flag in ("-f", "--result_file"):
                pass
            else:
                assert GetoptError(flag + " unhandled option")

            if flag in mandatory_flags:
                man_config[flag.replace("--", "")] = value
            else:
                opt_config[flag.replace("--", "")] = value

    except GetoptError as err:
        print err
        usage()
        sys.exit(2)

    return man_config, opt_config
Пример #9
0
def parse_args(argv):

    mandatory_flags = ['--input_filename']

    try:
        opts, args = getopt(
            argv[1:], "i:r:f:",
            ["input_filename=", "result_file=", "runtime_path=", "="])
        for flag in mandatory_flags:
            if flag not in dict(opts).keys():
                raise GetoptError(flag, "needs to be present")

        man_config = {}  # mandatory flaags, hold the resulting, parsed flags
        opt_config = {}  # optional flags

        for flag, value in opts:
            if flag in ("-i",
                        "--input_filename") or flag in ("-r",
                                                        "--runtime_path"):
                if os_file_exists(value) == False:
                    raise GetoptError(flag + "cannot find file" + value)
            elif flag in ("-f", "--result_file"):
                pass
            else:
                assert GetoptError(flag + " unhandled option")

            if flag in mandatory_flags:
                man_config[flag.replace("--", "")] = value
            else:
                opt_config[flag.replace("--", "")] = value

    except GetoptError as err:
        print err
        usage()
        sys.exit(2)

    return man_config, opt_config
Пример #10
0
    def _parse_input_file(cls,
                          filepath,
                          mandatory_fields,
                          encoding="unicode",
                          runtime_path=".",
                          **kwargs):
        """ take a key,value pair param text file and create class attributes of the name
        key with the value, value
        :param filepath:string, full path of the param text file
        :param encoding: string of member unicode|base64|b64encode
        :param mandatory_fields: list, all the fields that must be present in this file
        rtype : -1 on failure or None
        """
        if os_file_exists(filepath) == False:
            log.log(PRIORITY.FAILURE,
                    msg="filename [" + filepath + "] not found]")
            return ([-1])

        file_str = os_file_to_string(filepath)

        if encoding == "base64":
            # this is just for uuencoding; because encoding can create newline characters
            # we can get around this by converting them to + and then to space; which
            # is treated as the same as a newline
            file_str = file_str.replace("+++", " ")

        lines = file_str.split("\n")

        all_fields = []  # holds all fields detected not just mandatory ones
        try:
            # first load all attributes passed
            for _line in lines:
                _line_split = []

                try:
                    _line_split = _line.split(":")
                except:
                    log.log(PRIORITY.INFO,
                            msg="cannot process line   [" + _line +
                            "] in file [" + filepath + "]")

                if len(_line_split) == 2:
                    setattr(cls, _line_split[0], _line_split[1])
                    all_fields.append(_line_split[0])
                else:
                    log.log(PRIORITY.INFO,
                            msg="cannot process line [" + _line +
                            "] in file [" + filepath + "]")

            # call validate func for each mandatory field
            for _field in mandatory_fields:
                if getattr(cls,
                           "_validate_" + _field)(encoding=encoding) == [-1]:
                    log.log(PRIORITY.FAILURE,
                            msg="mandatory field could not be validated  [" +
                            _field + "]")
                    raise Exception(
                        "mandatory field could not be validated  [" + _field +
                        "]")
                else:
                    log.log(PRIORITY.INFO,
                            msg="parsed mandatory [" + str(_field) + "=" +
                            str(getattr(cls, _field)) + "]")

            # then validate all optional fields
            for _field in all_fields:
                if _field not in mandatory_fields:
                    if getattr(cls, "_validate_" +
                               _field)(encoding=encoding) != [-1]:
                        log.log(PRIORITY.INFO,
                                msg="parsed optional [" + str(_field) + "=" +
                                str(getattr(cls, _field)) + "]")

            # check to see if an explicit runtime path is set for databases and log files
            setattr(cls, "runtime_path", runtime_path)
            log.log(PRIORITY.INFO,
                    msg="setting runtime_path to [" + runtime_path + "]")

        except TypeError, e:
            log.log(PRIORITY.FAILURE,
                    msg="TypeError encoding issues? [" + str(e.message) + "]")
            return ([-1])
 def setUp(self):
     self.schema_file = path.join(TESTDIR, "test_schema_simple.xml")
     assert (os_file_exists(self.schema_file))
Пример #12
0
 def test_(self):
     self.repo = GitExcelHelper.action_type(self.filename,"create_repo",runtime_path="C:\\Users\\burtnolej\\").repo
     self.assertTrue(os_file_exists("C:\\Users\\burtnolej\\python_log.txt"))