Example #1
0
 def GET(self, group="", start_time="", end_time="", summary="", user_id="", product_id="", type_id="", query_all="false", r=None):
     enable_crossdomain();
     
     if query_all == True or query_all == "true" or str(query_all) == "1":
         query_all = True
     else:
         query_all = False
         
     # if not null, must be a digit.
     if group != "" and str(group) != "-1" and not str(group).isdigit():
         error("group must be digit, actual is %s"%(group));
         raise cherrypy.HTTPError(400, "group must be digit");
     
     trace('group=%s, start_time=%s, end_time=%s, summary=%s, user_id=%s, product_id=%s, type_id=%s, query_all=%s'%(group, start_time, end_time, summary, user_id, product_id, type_id, query_all));
     if user_id != "":
         authorize_user(user_id);
     
     if group == "" or str(group) == "-1":
         if summary == "1":
             return self.query_summary(start_time, end_time, user_id, product_id, type_id, query_all);
         else:
             return self.query_detail(start_time, end_time, user_id, product_id, type_id, query_all);
     else:
         if summary == "1":
             return self.query_summary_group(group, start_time, end_time, user_id, product_id, type_id, query_all);
         else:
             return self.query_detail_group(group, start_time, end_time, user_id, product_id, type_id, query_all);
Example #2
0
 def GET(self, group="", start_time="", end_time="", summary="", user_id="", product_id="", type_id="", query_all="false", r=None):
     enable_crossdomain();
     
     if query_all == True or query_all == "true" or str(query_all) == "1":
         query_all = True
     else:
         query_all = False
         
     # if not null, must be a digit.
     if group != "" and str(group) != "-1" and not str(group).isdigit():
         error("group must be digit, actual is %s"%(group));
         raise cherrypy.HTTPError(400, "group must be digit");
     
     trace('group=%s, start_time=%s, end_time=%s, summary=%s, user_id=%s, product_id=%s, type_id=%s, query_all=%s'%(group, start_time, end_time, summary, user_id, product_id, type_id, query_all));
     if user_id != "":
         authorize_user(user_id);
     
     if group == "" or str(group) == "-1":
         if summary == "1":
             return self.query_summary(start_time, end_time, user_id, product_id, type_id, query_all);
         else:
             return self.query_detail(start_time, end_time, user_id, product_id, type_id, query_all);
     else:
         if summary == "1":
             return self.query_summary_group(group, start_time, end_time, user_id, product_id, type_id, query_all);
         else:
             return self.query_detail_group(group, start_time, end_time, user_id, product_id, type_id, query_all);
Example #3
0
    def __func(self, tcontext):
        '''
        func = "int" ident "(" ("int" ident)* ")" "{" stmt* "}"
        '''
        tcontext.expect_type()
        funcname = tcontext.expect_ident().text
        tcontext.expect_symbol('(')
        args_order_type = []
        while not tcontext.consume_symbol(')'):
            type_token = tcontext.expect_type()
            ptr_level = 0
            while tcontext.consume_symbol('*'):
                ptr_level += 1
            vtype = self.__get_type_from_typename(type_token.text)
            typeinfo = TypeInfo(vtype, ptr_level)

            arg_token = tcontext.expect_ident()
            order = self.__regist_varname(arg_token.text, funcname, typeinfo)
            args_order_type.append((order, typeinfo))
            if not tcontext.consume_symbol(','):
                tcontext.expect_symbol(')')
                break
        if tcontext.current.text != '{':
            error('関数の"{"がありません')
        return NodeFactory.create_func_node(funcname, args_order_type,
                                            self.__stmt(tcontext, funcname))
Example #4
0
def authorize_user(request_user_id):
    auth = _config["auth"];
    if not auth["on"]:
        return;
        
    # method donot require check.
    conditions = cherrypy.request.config.get('auth.require', None)
    if conditions is None:
        return;
        
    # QQ-OAuth not enabled.
    if auth["strategy"] == "qq_oauth":
        # check QQ-OAuth session.
        user_id = cherrypy.session.get(SESSION_KEY);
        if user_id is None:
            error("authorize_user invalid, no session.");
            enable_crossdomain();
            raise cherrypy.HTTPError(401, "You are not authorized, login please.");
            return;
        if request_user_id in authorize_get_exception_user_id(user_id):
            error("authorize_user(id=%s) requires user id=%s invalid, check authorization failed."%(user_id, request_user_id));
            enable_crossdomain();
            raise cherrypy.HTTPError(403, "You(id=%s) are not authorized as %s, login please."%(user_id, request_user_id));
            return;
        trace("authorize success, user_id=%s requires id=%s"%(user_id, request_user_id));
            
    return;
Example #5
0
    def qq_oauth_access(self, access_token):
        auth = _config["auth"]

        # https://graph.qq.com/oauth2.0/me?access_token=QE9894RYY787767676G8G87G90980D0D
        api = "%s?access_token=%s" % (auth["qq_oauth_api_me"], access_token)
        trace("validate access_token from %s" % (api))

        # query qq_oauth_openid
        url = urllib.urlopen(api)
        data = url.read()
        url.close()

        json_data = data.strip().strip("callback").strip("(").strip(";").strip(
            ")").strip()
        trace("trim me data to %s" % (json_data))

        try:
            res_json = json.loads(json_data)
        except Exception, e:
            error(sys.exc_info)
            return json.dumps({
                "code":
                ErrorCode.Failed,
                "error":
                ErrorCode.Failed,
                "error_description":
                "qq_oauth_openid to json error"
            })
Example #6
0
def save_letter(letter, filename, folder):
    """
    Write letter to txt file

    Parameters
    ----------
    letter : String
        trimmed text ready for writing to file
    filename : String
        filename without ".txt"
    folder : String
        name of existing folder

    Returns
    -------
    int
        1 in case of success, 0 in case of failure

    """
    file = f'{folder}/{filename}.txt'
    if exists(file):
        ut.error(f"Target file {filename} already exists.")
        return 0
    try:
        f = open(file, 'w')
    except:
        ut.error(f"Cannot create or open {filename}.")
    else:
        f.write(letter)
        f.close()
        ut.progress(f"Successfully written letter to {filename}.")
    return 1
Example #7
0
def get_letter_list(db_connection, year, office):
    """
    Load data of letters from database to dataframe.

    Parameters
    ----------
    db_connection
    year: list
        a list of years to include in the query
    office: list
        a list of offices to include in the query

    Returns
    -------
    Dataframe with all letters loaded from database

    """
    # compose query
    query = f"WHERE YEAR(issued) IN ({', '.join(year)}) AND office REGEXP '{'|'.join(office)}'"
    
    # execute query and load to dataframe
    try:
        connection = db_connection.connect()
        df = pd.read_sql(f"SELECT * FROM list {query};", connection)
    except Exception as e:
        ut.error("Failed to retrieve dataframe from database.")
        ut.progress(f"Detailed error:\n{e}")
        return 0
    else:
        #ut.progress("Data retrieved from database.")
        return df
Example #8
0
def process_letter(url, filename, folder):
    """
    Driver function to retrieve, process and write letter to file

    Parameters
    ----------
    url : String
        URL
    filename : String
        filename without ".txt"
    folder : String
        name of existing folder

    Returns
    -------
    int
        1 in case of success, 0 in case of failure

    """
    letter = get_letter(url)
    if letter:
        text = strip_letter(
            letter_to_text(letter), 'Recipient', 'Content current as of'
            )
        save_letter(text, filename, folder)
        return 1
    else:
        ut.error(f"Processing of letter {filename} failed.")
        return 0
Example #9
0
    def qq_oauth_auto_register(self, access_token, qq_oauth_openid):
        auth = _config["auth"]

        # https://graph.qq.com/user/get_user_info?access_token=71871H1H3187I31EQJK3197J3JWQ8Q0D&appid=8373636744&openid=87JDD73KH32W3983JIUDS92198DS5B32
        # get user nickname as user_name, email empty
        api = "%s?access_token=%s&appid=%s&openid=%s" % (
            auth["qq_oauth_api_get_user_info"], access_token,
            auth["qq_oauth_api_app_id"], qq_oauth_openid)
        trace("auto register get user_info from %s" % (api))

        # query qq_oauth_openid
        url = urllib.urlopen(api)
        data = url.read()
        url.close()

        json_data = data.strip().strip("callback").strip("(").strip(";").strip(
            ")").strip()
        trace("trim get_user_info data to %s" % (json_data))

        try:
            res_json = json.loads(json_data)
        except Exception, e:
            error("ex=%s, info=%s" % (e, traceback.format_exc()))
            return json.dumps({
                "code": ErrorCode.Failed,
                "error": ErrorCode.Failed,
                "error_description": "userinfo to json error"
            })
Example #10
0
def executeSQLite(command, conn = None, daemon = False):
    if not daemon: utility.info("############### " + Fore.YELLOW + "Connecting and Executing SQLite Query" + Style.RESET_ALL+ " ###############")
    if conn is None: conn = __init(None, daemon)
    try:
        c = conn.cursor()
        if not daemon: utility.info("Executing query: " + command)
        result = c.execute(command).fetchall()
        if not daemon:
            for row in result:
                i = 0
                utility.info("======= Entry " + str(i+1) + " =======")
                for name in names:
                    utility.info(name + ': ' + str(row[i]))
                    i += 1

        conn.commit()
        conn.close()
    except sqlite3.Error as e:
        utility.error(str(e) + "\n    Query " + command + " executeion failed")
        return None
    if not result:
        return None
    else:
        names = list(map(lambda x:x[0], c.description))
        return buildJson(names, result)
Example #11
0
 def __regist_varname(self, varname, funcname, typeinfo):
     name = f'{funcname}::{varname}'
     if name in [n for n, t in self.__varinfos]:
         error(f'既に変数が宣言されています {name}')
     self.__varinfos.append((name, typeinfo))
     order, _ = self.__get_order_and_type_from_varname(varname, funcname)
     return order
Example #12
0
def connectMXA(command, delayTime=5, daemon=False):
    if not daemon:
        utility.info("##################### " + Fore.YELLOW + "MXA Control" +
                     Style.RESET_ALL + " ######################")
    try:
        if not daemon:
            utility.info('Send command: [' + command +
                         '] to the MXA box at [' + str(TCP_IP) + ':' +
                         str(TELNET_PORT) + ']')
        tn = Telnet(TCP_IP, int(TELNET_PORT))
        ##tn.write(('\r\n').encode('ascii'))
        tn.read_until(b'SCPI>')
        tn.write((command + '\r\n').encode('ascii'))
        utility.sleep(delayTime, True)
        result = (utility.regexParser(tn.read_very_eager().decode('ascii'),
                                      ' (.*)\r\nSCPI.*',
                                      daemon)).replace('SCPI> ', '').replace(
                                          command, '').replace('\r\n', '')
        if result:
            if not daemon: utility.info('Response:\n' + result)
        else:
            result = ''
    except OSError:
        utility.error('Connection to ' + str(TCP_IP) + ':' + str(TELNET_PORT) +
                      ' Failed!')
        exit(1)
    tn.close()
    return result
Example #13
0
def save_data(df, db_connection):
    """
    Write dataframe to SQL database
    Parameters
    ----------
    df : dataframe
    db_connection : database connection

    """
    try:
        connection = db_connection.connect()
        # empty transition 'temptable' table
        connection.execute("TRUNCATE temptable")
        # write result to 'temptable' table
        df.to_sql('temptable',
                  db_connection,
                  if_exists='append',
                  index_label='id')
        # use INSERT IGNORE to just skip already existing letters in the 'list' table
        connection.execute("INSERT IGNORE INTO list SELECT * FROM temptable")
        connection.close()
    except Exception as e:
        ut.error("Failed to write dataframe to database.")
        ut.progress(f"Detailed error:\n{e}")
        return 0
    else:
        ut.progress("Dataframe written to database.")
        return 1
Example #14
0
def authorize_user(request_user_id):
    auth = _config["auth"];
    if not auth["on"]:
        return;
        
    # method donot require check.
    conditions = cherrypy.request.config.get('auth.require', None)
    if conditions is None:
        return;
        
    # QQ-OAuth not enabled.
    if auth["strategy"] == "qq_oauth":
        # check QQ-OAuth session.
        user_id = cherrypy.session.get(SESSION_KEY);
        if user_id is None:
            error("authorize_user invalid, no session.");
            enable_crossdomain();
            raise cherrypy.HTTPError(401, "You are not authorized, login please.");
            return;
        if request_user_id in authorize_get_exception_user_id(user_id):
            error("authorize_user(id=%s) requires user id=%s invalid, check authorization failed."%(user_id, request_user_id));
            enable_crossdomain();
            raise cherrypy.HTTPError(403, "You(id=%s) are not authorized as %s, login please."%(user_id, request_user_id));
            return;
        trace("authorize success, user_id=%s requires id=%s"%(user_id, request_user_id));
            
    return;
Example #15
0
def check_auth(*args, **kwargs):
    # auth not enabled in config.
    auth = _config["auth"];
    if not auth["on"]:
        return;
        
    # method donot require check.
    conditions = cherrypy.request.config.get('auth.require', None)
    if conditions is None:
        return;
        
    # QQ-OAuth not enabled.
    if auth["strategy"] == "qq_oauth":
        trace("check session, session_id=%s"%(cherrypy.session.id));
        # check QQ-OAuth session.
        user_id = cherrypy.session.get(SESSION_KEY);
        if user_id is None:
            error("session invalid, check auth failed.");
            enable_crossdomain();
            raise cherrypy.HTTPError(401, "You are not authorized, login please.");
            return;
    
    # check condition.
    for condition in conditions:
        if not condition():
            error("codition check invalid, check auth failed.");
            enable_crossdomain();
            raise cherrypy.HTTPError(401, "You are not authorized for specified condition");
            return;
            
    trace("check auth success. user_id=%s"%(user_id));
Example #16
0
 def __get_order_and_type_from_varname(self, varname, funcname):
     name = f'{funcname}::{varname}'
     if name not in [n for n, t in self.__varinfos]:
         error(f'未宣言の変数が使われています {name}')
     name_type = [(n, t) for n, t in self.__varinfos
                  if n.startswith(f'{funcname}:')]
     index = [n for n, t in name_type].index(name)
     return index + 1, name_type[index][1]
Example #17
0
    def _gen_lval(self, node, output):
        from node import NodeTypes

        if node.type != NodeTypes.IDENT:
            error(f'代入の左辺値が変数ではありません {node.type}')
        output.append('  mov rax, rbp')
        output.append(f'  sub rax, {node.order * 8}')
        output.append('  push rax')
Example #18
0
    def add_declaration(self, typedec, name, val, line):
        if name in self.places:
            error("Declaration `%s` is already defined.", line)

        plc = Place(name, line)
        plc.content = val
        plc.kind = typedec
        self.places[name] = plc        
 def testNetwork(self, filePath=None):
     if filePath:
         NetFile = SaveObj(filePath)
         TrainedNetwork = NetFile.load()  # deserialize NeuralNetwork
         log(filePath)
         self.networkTest(TrainedNetwork)
     else:
         error("File path doesn't specified!")
Example #20
0
 def expect_ident(self):
     token = self.consume_ident()
     if not token:
         if self.__tokens:
             error_at(self.__c_code, self.__tokens[0].code, '変数,関数ではありません')
         else:
             error('変数,関数がありません')
     return token
Example #21
0
 def expect_num(self):
     token = self.consume_num()
     if not token:
         if self.__tokens:
             error_at(self.__c_code, self.__tokens[0].code, '数ではありません')
         else:
             error('数がありません')
     return token
Example #22
0
 def expect_type(self):
     token = self.consume_type()
     if not token:
         if self.__tokens:
             error_at(self.__c_code, self.__tokens[0].code, '型ではありません')
         else:
             error('型ではありません')
     return token
Example #23
0
 def expect_symbol(self, symbol):
     token = self.consume_symbol(symbol)
     if not token:
         if self.__tokens:
             error_at(self.__c_code, self.__tokens[0].code,
                      f'{symbol}ではありません')
         else:
             error(f'{symbol}がありません')
     return token
Example #24
0
    def POST(self):
        enable_crossdomain();
        req_json_str = cherrypy.request.body.read();

        try:
            req_json = json.loads(req_json_str);
        except Exception,e:
            error(sys.exc_info);
            return json.dumps({"code":ErrorCode.Failed, "error":ErrorCode.Failed, "error_description":"to json error"});
Example #25
0
    def POST(self):
        enable_crossdomain();
        req_json_str = cherrypy.request.body.read();

        try:
            req_json = json.loads(req_json_str);
        except Exception,e:
            error(sys.exc_info);
            return json.dumps({"code":ErrorCode.Failed, "error":ErrorCode.Failed, "error_description":"to json error"});
Example #26
0
    def add_param(self, typedec, name, line):
        param = Parameter(typedec, name, line)
        msg = "Parameter name: `%s`, is already defined."

        if name in self.places:
            error(msg % name, line)
            
        self.places[name] = Place(name, line)
        self.places[name].kind = typedec
Example #27
0
 def __getConfigFile(self, confFile="this_device_conf.json"):
     try:
         with open('/var/www/html/sauto/rootpath.conf', 'r') as conf_file:
             path = conf_file.read()
             if path: return path + '/confif_files/' + confFile
             else: return 'this_device_conf.json'
     except Exception as e:
         utility.error(str(e), False)
         return None
Example #28
0
def connectSQLite(db_path, daemon = False):
    global sqlite_file
    if db_path is None: db_path = sqlite_file
    try:
        if not daemon: utility.info("Connecting to DB: " + db_path)
        conn = sqlite3.connect(db_path)
        return conn
    except sqlite3.Error:
        utility.error("Connection to " + db_path + " failed")
        exit(1)
Example #29
0
    def start_workers(self):
        with self.glock:
            if util.file_exists(self.pidfile):
                util.error("pidfile already exists: " + self.pidfile)
                sys.exit(-1)

        for pname in self.workers.keys():
            util.info("{}: worker starting...".format(pname))
            self.workers[pname].start()
        pass
Example #30
0
def addm(a, b):
    if len(a) != len(b) or len(a[0]) != len(b[0]):
        utility.error('dimensions do not match')
    x = len(a[0])
    y = len(a)
    ret = zerosm(x, y)
    for i in range(x):
        for j in range(y):
            ret[j][i] = a[j][i] + b[j][i]
    return ret
Example #31
0
def multiplym(a, b):
    if len(a[0]) != len(b): utility.error('dimensions do not match')
    x = len(b[0])
    y = len(a)
    ret = zerosm(x, y)
    for i in range(x):
        for j in range(y):
            for k in range(len(b)):
                ret[j][i] += a[j][k] * b[k][i]
    return ret
 def testMultipleNetworks(self, dirPath=None):
     if dirPath:
         filesList = ls(dirPath)
         for i in filesList:
             log(dirPath + "/" + i)
             NetFile = SaveObj(dirPath + "/" + i)
             TrainedNetwork = NetFile.load()  # deserialize NeuralNetwork
             self.networkTest(TrainedNetwork)
             print()  # empty line visual divide
     else:
         error("Dir path doesn't specified!")  # bug: "wrong path is showed"
Example #33
0
def eul2r(phi, theta=None, psi=None):
    """
    Rotation from Euler angles.
    
    Two call forms:
        - R = eul2r(S{theta}, S{phi}, S{psi})
        - R = eul2r([S{theta}, S{phi}, S{psi}])
    These correspond to rotations about the Z, Y, Z axes respectively.

    @type phi: number or list/array/matrix of angles
    @param phi: the first Euler angle, or a list/array/matrix of angles
    @type theta: number
    @param theta: the second Euler angle
    @type psi: number
    @param psi: the third Euler angle
    @rtype: 3x3 orthonormal matrix
    @return: R([S{theta} S{phi} S{psi}])

    @see:  L{tr2eul}, L{eul2tr}, L{tr2rpy}

    """
    from numpy import int32, float64
    n = 1
    if theta == None and psi == None:
        # list/array/matrix argument
        phi = mat(phi)
        if numcols(phi) != 3:
            error('bad arguments')
        else:
            n = numrows(phi)
            psi = phi[:, 2]
            theta = phi[:, 1]
            phi = phi[:, 0]
    elif (theta != None and psi == None) or (theta == None and psi != None):
        error('bad arguments')
    elif not isinstance(phi, (int, int32, float, float64)):
        # all args are vectors
        phi = mat(phi)
        n = numrows(phi)
        theta = mat(theta)
        psi = mat(psi)

    if n > 1:
        R = []
        for i in range(0, n):
            r = rotz(phi[i, 0]) * roty(theta[i, 0]) * rotz(psi[i, 0])
            R.append(r)
        return R
    try:
        r = rotz(phi[0, 0]) * roty(theta[0, 0]) * rotz(psi[0, 0])
        return r
    except:
        r = rotz(phi) * roty(theta) * rotz(psi)
        return r
Example #34
0
def t2r(T):
    """
    Return rotational submatrix of a homogeneous transformation.
    @type T: 4x4 homogeneous transformation
    @param T: the transform matrix to convert
    @rtype: 3x3 orthonormal rotation matrix
    @return: rotation submatrix
    """

    if ishomog(T) == False:
        error('input must be a homogeneous transform')
    return T[0:3, 0:3]
Example #35
0
    def register_worker(self, pname, wp):
        # According to multiprocess daemon documentation by setting daemon=True
        #  when your script ends its job will try to kill all subprocess.
        # That occurs before they can start to write so no output will be produced.
        wp.daemon = True

        if self.workers.has_key(pname):
            util.error("duplicated worker process name: %s", pname)
            sys.exit(-1)

        self.workers[pname] = wp
        pass
Example #36
0
 def GET(self, group="", query_all="false", r=None):
     enable_crossdomain();
     
     if query_all == True or query_all == "true" or str(query_all) == "1":
         query_all = True
     else:
         query_all = False
     
     # if not null, must be a digit.
     if group != "" and str(group) != "-1" and not str(group).isdigit():
         error("group must be digit, actual is %s"%(group));
         raise cherrypy.HTTPError(400, "group must be digit");
     
     records = [];
     if query_all:
         if group == "" or str(group) == "-1":
             records = sql_exec("select user_id,user_name from dr_user");
         else:
             records = sql_exec("select u.user_id,u.user_name "
                 "from dr_user u,dr_group g,dr_rs_group_user rs "
                 "where rs.user_id = u.user_id and g.group_id = rs.group_id and g.group_id = %s", (group));
     else:
         if group == "" or str(group) == "-1":
             records = sql_exec("select user_id,user_name from dr_user where enabled=true");
         else:
             records = sql_exec("select u.user_id,u.user_name "
                 "from dr_user u,dr_group g,dr_rs_group_user rs "
                 "where u.enabled=true "
                     "and rs.user_id = u.user_id and g.group_id = rs.group_id and g.group_id = %s", (group));
     
     user_id = None;
     auth = _config["auth"];
     if auth["on"]:
         # QQ-OAuth not enabled.
         if auth["strategy"] == "qq_oauth":
             # check QQ-OAuth session.
             user_id = cherrypy.session.get(SESSION_KEY);
             
     # the user cannot authorize by specified user.
     exception_users = authorize_get_exception_user_id(user_id);
     trace("get users while group=%s for user_id=%s exception_users=%s"%(group, user_id, exception_users));
         
     ret = [];
     for record in records:
         returned_user_id = record["user_id"];
         if returned_user_id in exception_users:
             continue;
         ret.append({
             "id":returned_user_id, "value":record["user_name"]
         });
         
     return json.dumps({"code":ErrorCode.Success, "auth":user_id, "users":ret});
Example #37
0
 def GET(self, group="", query_all="false", r=None):
     enable_crossdomain();
     
     if query_all == True or query_all == "true" or str(query_all) == "1":
         query_all = True
     else:
         query_all = False
     
     # if not null, must be a digit.
     if group != "" and str(group) != "-1" and not str(group).isdigit():
         error("group must be digit, actual is %s"%(group));
         raise cherrypy.HTTPError(400, "group must be digit");
     
     records = [];
     if query_all:
         if group == "" or str(group) == "-1":
             records = sql_exec("select user_id,user_name from dr_user");
         else:
             records = sql_exec("select u.user_id,u.user_name "
                 "from dr_user u,dr_group g,dr_rs_group_user rs "
                 "where rs.user_id = u.user_id and g.group_id = rs.group_id and g.group_id = %s", (group));
     else:
         if group == "" or str(group) == "-1":
             records = sql_exec("select user_id,user_name from dr_user where enabled=true");
         else:
             records = sql_exec("select u.user_id,u.user_name "
                 "from dr_user u,dr_group g,dr_rs_group_user rs "
                 "where u.enabled=true "
                     "and rs.user_id = u.user_id and g.group_id = rs.group_id and g.group_id = %s", (group));
     
     user_id = None;
     auth = _config["auth"];
     if auth["on"]:
         # QQ-OAuth not enabled.
         if auth["strategy"] == "qq_oauth":
             # check QQ-OAuth session.
             user_id = cherrypy.session.get(SESSION_KEY);
             
     # the user cannot authorize by specified user.
     exception_users = authorize_get_exception_user_id(user_id);
     trace("get users while group=%s for user_id=%s exception_users=%s"%(group, user_id, exception_users));
         
     ret = [];
     for record in records:
         returned_user_id = record["user_id"];
         if returned_user_id in exception_users:
             continue;
         ret.append({
             "id":returned_user_id, "value":record["user_name"]
         });
         
     return json.dumps({"code":ErrorCode.Success, "auth":user_id, "users":ret});
Example #38
0
 def POST(self):
     enable_crossdomain()
     (code, ret) = (ErrorCode.Success, [])
     req_str = cherrypy.request.body.read()
     try:
         req = json.loads(req_str)
     except Exception, e:
         error(sys.exc_info)
         return json.dumps({
             "code": ErrorCode.Failed,
             "error": ErrorCode.Failed,
             "error_description": "to json error"
         })
Example #39
0
    def POST(self):
        enable_crossdomain();
        
        auth = _config["auth"];
        if not auth["on"]:
            raise cherrypy.HTTPError(405, "auth is off");
            return;
            
        req_json_str = cherrypy.request.body.read();

        try:
            req_json = json.loads(req_json_str);
        except Exception,e:
            error(sys.exc_info);
            return json.dumps({"code":ErrorCode.Failed, "error":ErrorCode.Failed, "error_description":"to json error"});
Example #40
0
    def POST(self):
        enable_crossdomain();
        
        auth = _config["auth"];
        if not auth["on"]:
            raise cherrypy.HTTPError(405, "auth is off");
            return;
            
        req_json_str = cherrypy.request.body.read();

        try:
            req_json = json.loads(req_json_str);
        except Exception,e:
            error(sys.exc_info);
            return json.dumps({"code":ErrorCode.Failed, "error":ErrorCode.Failed, "error_description":"to json error"});
Example #41
0
 def do_email_to(self, user_id, user_name, email, date):
     if email is None:
         error("ignore the empty email for user %s(%s)"%(user_name, user_id));
         return True;
         
     mail = _config["mail"];
     # generate subject
     subject = mail["subject"];
     content = mail["content"];
     # generate content
     subject = subject.replace("{user_name}", user_name).replace("{date}", date);
     content = content.replace("{user_id}", str(user_id));
     # do email.
     if not send_mail(mail["smtp_server"], mail["username"], mail["password"], [email], mail["cc_user"], subject, content):
         trace("email to %s(%s) id=%s failed"%(user_name, email, user_id));
         return False;
     trace("email to %s(%s) id=%s success"%(user_name, email, user_id));
     return True;
Example #42
0
    def qq_oauth_access(self, access_token):
        auth = _config["auth"];
        
        # https://graph.qq.com/oauth2.0/me?access_token=QE9894RYY787767676G8G87G90980D0D
        api = "%s?access_token=%s"%(auth["qq_oauth_api_me"], access_token);
        trace("validate access_token from %s"%(api));
        
        # query qq_oauth_openid
        url = urllib.urlopen(api);
        data = url.read();
        url.close();
        
        json_data = data.strip().strip("callback").strip("(").strip(";").strip(")").strip();
        trace("trim me data to %s"%(json_data));

        try:
            res_json = json.loads(json_data);
        except Exception,e:
            error(sys.exc_info);
            return json.dumps({"code":ErrorCode.Failed, "error":ErrorCode.Failed, "error_description":"qq_oauth_openid to json error"});
Example #43
0
    def qq_oauth_auto_register(self, access_token, qq_oauth_openid):
        auth = _config["auth"];
        
        # https://graph.qq.com/user/get_user_info?access_token=71871H1H3187I31EQJK3197J3JWQ8Q0D&appid=8373636744&openid=87JDD73KH32W3983JIUDS92198DS5B32
        # get user nickname as user_name, email empty
        api = "%s?access_token=%s&appid=%s&openid=%s"%(auth["qq_oauth_api_get_user_info"], access_token, auth["qq_oauth_api_app_id"], qq_oauth_openid);
        trace("auto register get user_info from %s"%(api));
        
        # query qq_oauth_openid
        url = urllib.urlopen(api);
        data = url.read();
        url.close();
        
        json_data = data.strip().strip("callback").strip("(").strip(";").strip(")").strip();
        trace("trim get_user_info data to %s"%(json_data));

        try:
            res_json = json.loads(json_data);
        except Exception,e:
            error("ex=%s, info=%s"%(e, traceback.format_exc()));
            return json.dumps({"code":ErrorCode.Failed, "error":ErrorCode.Failed, "error_description":"userinfo to json error"});
Example #44
0
def det(m):
    sz = len(m)
    if sz != len(m[0]):
        utility.error('not a square matrix')
    
    # base condition
    if sz == 2:
        return (m[0][0] * m[1][1]) - (m[0][1] * m[1][0])
    
    # recursive condition (bigger than 2x2)
    # - make sure to alternate signs
    sign = '+'
    ct = 0
    # iterate over the first row only
    for i in range(sz):
        res = m[0][i] * det(__rest_of_matrix(m, i))
        if sign == '+':
            ct += res
            sign = '-'
        else:
            ct -= res
            sign = '+'

    return ct
Example #45
0
 def check_has_return(self):
     for a in self.arrows:            
         if a.tgt == "return":
             return True
     error("Function: `%s`, has no return" % self.name, self.line)
Example #46
0
 def name_exists(self, name):
     if ( has_function(prelude, name) or
          name in self.places ):                    
         return True
     error("Name: `%s`, not found", name)
Example #47
0
def dotv(x1, x2):
    if len(x1) != len(x2): utility.error('dimensions do not match')
    return sum([a * b for a, b in zip(x1, x2)])
Example #48
0
def trace(m):
    if len(m) != len(m[0]):
        utility.error('not a square matrix')

    tr = sum([ m[i][i] for i in range(len(m))])
    return tr
Example #49
0
def check_dimensions(a, b):
    if len(a) != len(b) or len(a[0]) != len(b[0]):
        utility.error('dimensions do not match')
Example #50
0
        migration.import_issues_for_project
    ]

    ow2_subcommands = [
        migration.clone_repositories,
        migration.gc_repositories,
        migration.prune_repositories
    ]

    parser = argparse.ArgumentParser()
    argh.add_commands(parser, github_subcommands, namespace='github')
    argh.add_commands(parser, ow2_subcommands, namespace='ow2')
    argh.dispatch(parser)


if __name__ == "__main__":
    from requests.packages import urllib3

    urllib3.disable_warnings()

    try:
        bfg_jar_path = utility.get_env_var("BFG_JAR_PATH")
        github_authentication_token = utility.get_env_var("GITHUB_TOKEN")
        github_organization_name = utility.get_env_var("GITHUB_ORGANIZATION")
        ow2_organization_name = utility.get_env_var("OW2_ORGANIZATION")

        migration = Migration()
        main()
    except utility.UndefinedEnvironmentVariable as e:
        utility.error("Undefined environment variable: {}".format(e.var_name))
Example #51
0
def addv(a, b):
    if len(a) != len(b): utility.error('dimensions do not match')
    ret = zerosv(len(a))
    for i in range(len(a)):
        ret[i] = a[i] + b[i]
    return ret