Exemple #1
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)
Exemple #2
0
 def _decode_2darray(array, encoding="base64"):
     result = []
     for _row in array:
         result.append([
             ExcelBase._tryint(decode(_field, encoding)) for _field in _row
         ])
     return result
Exemple #3
0
    def _validate_sp_args(self, encoding="unicode"):
        """purpose: parse nvp's that need to be passed to the sp_func_name """
        assert hasattr(self, 'sp_args'), sp_args
        import xml.etree.ElementTree as xmltree
        valid_args = [
            'days', 'periods', 'teachers', 'students', 'classlectures',
            'courses', 'subjects', 'sections', 'sectionschedules',
            'studentlevels', 'idacadperiods'
        ]

        sp_args_dict = xmlstr2dict(decode(self.sp_args, encoding),
                                   doublequote=True)

        for arg in sp_args_dict.keys():
            if arg not in valid_args:
                log.log(PRIORITY.FAILURE,
                        msg="arg is not a valid sp args [" +
                        str(sp_args_dict) + "]")
                return [-1]

        setattr(self, 'sp_args', sp_args_dict)
        log.log(PRIORITY.INFO,
                msg="validated sp args, set member attr sp_arg to [" +
                str(sp_args_dict) + "]")
        return True
Exemple #4
0
    def _validate_flag(self, flagname, encoding="unicode"):
        """ check the a raw flag exists and update attr to be boolean value
        :param flagname:string
        :param encoding: [base64|unicode|b64encode]
        :rtype : -1 on failure or None
        """
        if hasattr(self, flagname) == False:
            log.log(PRIORITY.FAILURE, msg=flagname + " name must be passed")
            return ([-1])

        if decode(getattr(self, flagname), encoding) == "True":
            setattr(self, flagname, True)
        elif decode(getattr(self, flagname), encoding) == "False":
            setattr(self, flagname, False)
        else:
            raise Exception(encoded,
                            " encoded flag needs to be either True|False")
Exemple #5
0
    def _validate_field(self, fieldname, encoding="unicode"):
        """ check the a raw value for the field has been set
        :param filename:string
        :param encoding: [base64|unicode|b64encode]
        :rtype : -1 on failure or None
        """
        if hasattr(self, fieldname) == False:
            log.log(PRIORITY.FAILURE, msg=fieldname + " name must be passed")
            return ([-1])

        setattr(self, fieldname, decode(getattr(self, fieldname), encoding))
Exemple #6
0
    def _validate_rows(self, encoding="unicode"):
        if hasattr(self, "rows") == False:
            log.log(PRIORITY.FAILURE, msg="rows must be passed")
            return ([-1])
        else:
            self.urows = []
            for row in self.rows.split("$$"):
                _row = row.split("^")
                if encoding == "base64":
                    try:
                        tmp = [b64decode(_field) for _field in _row]
                    except TypeError, e:
                        raise Exception("rows are not base64 encoded")

                #self.urows.append(_row)
                self.urows.append(decode(_field, encoding) for _field in _row)
    def _validate_commit_files(self, **kwargs):
        encoding = "unicode"
        if kwargs.has_key("encoding"):
            encoding = kwargs['encoding']

        if hasattr(self, "commit_files") == False:
            log.log(PRIORITY.FAILURE, msg="commit_files must be passed")
            return ([-1])
        else:
            if self._validate_filename("commit_files",
                                       encoding=encoding) != [-1]:
                files = getattr(self, "commit_files")
                files = GitRepoHelper._get_git_rel_filepath(
                    self.reponame, files, decode(self.gitrootpath[0],
                                                 encoding))
                setattr(self, "commit_files", files)
            else:
                raise Exception("could not validate commit_files")