Example #1
0
    def delete(self, team, lang, task):
        if team != self.current_user:
            logger.warn("Team %s said to be %s while deleting translation of %s in %s." % (self.current_user, team, task, lang))
            raise HTTPError(403)

        if lang not in teams[team]["tasks"].get(task, []):
            logger.warn("Team %s tried to delete a translation that doesn't exists (%s in %s)" % (team, task, lang))
            raise HTTPError(404)

        logger.info("Team %s deleted translation of task %s into %s" % (team, task, lang))

        # Update the task and team data

        task_path = os.path.join(os.path.dirname(__file__),
                                 "tasks", "%s.json" % task)

        tasks[task]["teams"][team].remove(lang)
        tasks[task]["langs"][lang].remove(team)

        try:
            json.dump(tasks[task], open(task_path, "w"), indent=4)
        except IOError:
            logger.error("Couldn't write data for task %s" % task)
            raise HTTPError(500)
        except ValueError:
            logger.error("Couldn't dump data for task %s" % task)
            raise HTTPError(500)

        team_path = os.path.join(os.path.dirname(__file__),
                                 "teams", "%s.json" % team)

        teams[team]["tasks"][task].remove(lang)
        teams[team]["langs"][lang].remove(task)

        try:
            json.dump(teams[team], open(team_path, "w"), indent=4)
        except IOError:
            logger.error("Couldn't write data for team %s" % team)
            raise HTTPError(500)
        except ValueError:
            logger.error("Couldn't dump data for team %s" % team)
            raise HTTPError(500)


        # Remove the symlinks

        links = [os.path.join(os.path.dirname(__file__),
                              "data", task, "by_lang", "%s (%s).pdf" % (lang, team)),
                 os.path.join(os.path.dirname(__file__),
                              "data", task, "by_team", "%s (%s).pdf" % (team, lang))]

        for link in links:
            os.remove(link)

        proxy.send("delete", "%s %s %s" % (team, lang, task), '*')
Example #2
0
    def put(self, team, lang, task):
        if team != self.current_user:
            logger.warn("Team %s said to be %s while updating translation of %s in %s." % (self.current_user, team, task, lang))
            raise HTTPError(403)

        if lang not in teams[team]["tasks"].get(task, []):
            logger.warn("Team %s tried to update a translation that doesn't exists (%s in %s)" % (team, task, lang))
            raise HTTPError(404)

        self._save(team, lang, task)

        proxy.send("update", "%s %s %s" % (team, lang, task), '*')
Example #3
0
def routineDispatch(name, sock_list):
    queue = queDic[name]
    print("ok3")
    while True:
        packdata = queue.get()
        print("ok4")
        for sock in sock_list:
            try:
                sock.sendall(packdata)
            except Exception as e:
                logger.warn(str(e))
                lock.acquire()
                sock_list.remove(sock)
                lock.release()
Example #4
0
    def post(self, team, lang, task):
        if team != self.current_user:
            logger.warn(
                "Team %s said to be %s while creating translation of %s in %s."
                % (self.current_user, team, task, lang))
            raise HTTPError(403)

        if lang not in lang_names:
            logger.warn("Team %s tried to create a translation in %s" %
                        (team, lang))
            raise HTTPError(404)

        if task not in tasks:
            logger.warn("Team %s tried to create a translation of %s" %
                        (team, task))
            raise HTTPError(404)

        if lang in teams[team]["tasks"].get(task, []):
            logger.warn(
                "Team %s tried to create a translation that already exists (%s into %s)"
                % (team, task, lang))
            raise HTTPError(405)

        self._save(team, lang, task)

        proxy.send("create", "%s %s %s" % (team, lang, task), '*')
Example #5
0
    def post(self):
        username = self.get_argument("username", "")
        password = self.get_argument("password", "")

        if username not in teams:
            logger.warn("Wrong username (%s / %s)." % (username, password))
            self.redirect("/?login_error=1")
            return

        if teams[username]["password"] != password:
            logger.warn("Wrong password (%s / %s)." % (username, password))
            self.redirect("/?login_error=1")
            return

        self.set_secure_cookie("login", username, expires_days=None)
        self.redirect("/")
Example #6
0
    def put(self, team, lang, task):
        if team != self.current_user:
            logger.warn(
                "Team %s said to be %s while updating translation of %s in %s."
                % (self.current_user, team, task, lang))
            raise HTTPError(403)

        if lang not in teams[team]["tasks"].get(task, []):
            logger.warn(
                "Team %s tried to update a translation that doesn't exists (%s in %s)"
                % (team, task, lang))
            raise HTTPError(404)

        self._save(team, lang, task)

        proxy.send("update", "%s %s %s" % (team, lang, task), '*')
Example #7
0
    def post(self):
        username = self.get_argument("username", "")
        password = self.get_argument("password", "")

        if username not in teams:
            logger.warn("Wrong username (%s / %s)." % (username, password))
            self.redirect("/?login_error=1")
            return

        if teams[username]["password"] != password:
            logger.warn("Wrong password (%s / %s)." % (username, password))
            self.redirect("/?login_error=1")
            return

        self.set_secure_cookie("login", username, expires_days=None)
        self.redirect("/")
Example #8
0
def routineWorker(sock):
    try:
        dumpf = open(DUMP_FILE, 'rb')

        while True:
            packdata = readPackage(dumpf)
            if None == packdata:  #已经到文件结尾
                logger.info("maybe end of the dumpfile, reloading now...")
                dumpf.seek(0, 0)  #从第二帧开始读数据帧
                logger.info("seeking offset in dumpfile: " + str(0))
                continue

            sock.sendall(packdata)
            time.sleep(0.032)
    except Exception as e:
        logger.warn("conn maybe broken: " + str(e))
    finally:
        sock.close()
        dumpf.close()
Example #9
0
    async def send_intro_qn(self, ctx, msg):
        if is_brioche_bun(ctx.message.author.roles):
            about_us = self.bot.get_channel(Constants.ID_CHN_ABOUT_US)
            try:
                member = await self.bot.fetch_user(msg[3:-1])
                logger.info("{0} invoked intro for {1}".format(
                    ctx.message.author.display_name, member.display_name))
            except NotFound:
                logger.info(
                    "Unknown user fetched by {0}, setting member to empty string and sending generic welcome message instead"
                    .format(ctx.message.author.display_name))
                member = None
            finally:
                await ctx.message.delete()
                await ctx.send(file=discord.File(Constants.ASSET_POSTER))
                await ctx.send(Constants.MSG_REC_OPEN_MSG.format(member.mention, about_us)) \
                if member else await ctx.send(Constants.MSG_REC_OPEN_MSG.format('', about_us))

        else:
            logger.warn("Member %s tried to call intro",
                        ctx.message.author.display_name)
    def register_ethernet_device(self,
                                 protocol,
                                 id,
                                 ip,
                                 port,
                                 description=None):
        try:
            device_info = dict()
            device_info['type'] = "Ethernet"
            device_info['protocol'] = protocol
            device_info['description'] = description
            device_info['id'] = id
            device_prop = dict()
            device_prop['status'] = "down"
            device_prop['ip'] = ip
            device_prop['port'] = port
            if description is None:
                device_prop['description'] = ""
            else:
                device_prop['description'] = description
            device_info['property'] = device_prop

            ri = RouterInfo(self.base)
            conn_sites = json.loads(ri.get_connect_device())
            if len(conn_sites):
                for conn_site in conn_sites:
                    if conn_site['ip'] == device_info['property']['ip']:
                        device_info['property']['status'] = "up"
                        if device_info['property'][
                                'description'] is None and conn_site[
                                    'hostname'] != "":
                            device_info['property']['description'] = conn_site[
                                'hostname']
            self.siteinfo.append(device_info)
            return True
        except Exception as e:
            logger.warn("register ethernet device error %s, payload %s" %
                        (e.__str__(), device_info))
            return False
 def register_serial_device(self,
                            protocol,
                            id,
                            description,
                            dev,
                            speed=9600,
                            databit=8,
                            stopbit=1,
                            parity="N",
                            xonxoff="off"):
     logger.debug('*** Running register_serial_device ***')
     try:
         if dev == '/dev/ttyO1':
             type = 'RS232'
         elif dev == '/dev/ttyO3':
             type = 'RS485'
         else:
             logger.info("serial dev is incorrect, %s", dev)
             return False
         device_info = dict()
         device_info['type'] = type
         device_info['protocol'] = protocol
         device_info['description'] = description
         device_info['id'] = id
         device_prop = dict()
         device_prop['databit'] = databit
         device_prop['stopbit'] = stopbit
         device_prop['parity'] = parity
         device_prop['xonxoff'] = xonxoff
         device_prop['speed'] = speed
         device_prop['dev'] = dev
         device_info['property'] = device_prop
         self.siteinfo.append(device_info)
         return True
     except Exception as e:
         logger.warn("register serial device error %s, payload %s" %
                     (e.__str__(), device_info))
         return False
Example #12
0
    def post(self, team, lang, task):
        if team != self.current_user:
            logger.warn("Team %s said to be %s while creating translation of %s in %s." % (self.current_user, team, task, lang))
            raise HTTPError(403)

        if lang not in lang_names:
            logger.warn("Team %s tried to create a translation in %s" % (team, lang))
            raise HTTPError(404)

        if task not in tasks:
            logger.warn("Team %s tried to create a translation of %s" % (team, task))
            raise HTTPError(404)

        if lang in teams[team]["tasks"].get(task, []):
            logger.warn("Team %s tried to create a translation that already exists (%s into %s)" % (team, task, lang))
            raise HTTPError(405)

        self._save(team, lang, task)

        proxy.send("create", "%s %s %s" % (team, lang, task), '*')
Example #13
0
    def delete(self, team, lang, task):
        if team != self.current_user:
            logger.warn(
                "Team %s said to be %s while deleting translation of %s in %s."
                % (self.current_user, team, task, lang))
            raise HTTPError(403)

        if lang not in teams[team]["tasks"].get(task, []):
            logger.warn(
                "Team %s tried to delete a translation that doesn't exists (%s in %s)"
                % (team, task, lang))
            raise HTTPError(404)

        logger.info("Team %s deleted translation of task %s into %s" %
                    (team, task, lang))

        # Update the task and team data

        task_path = os.path.join(os.path.dirname(__file__), "tasks",
                                 "%s.json" % task)

        tasks[task]["teams"][team].remove(lang)
        tasks[task]["langs"][lang].remove(team)

        try:
            json.dump(tasks[task], open(task_path, "w"), indent=4)
        except IOError:
            logger.error("Couldn't write data for task %s" % task)
            raise HTTPError(500)
        except ValueError:
            logger.error("Couldn't dump data for task %s" % task)
            raise HTTPError(500)

        team_path = os.path.join(os.path.dirname(__file__), "teams",
                                 "%s.json" % team)

        teams[team]["tasks"][task].remove(lang)
        teams[team]["langs"][lang].remove(task)

        try:
            json.dump(teams[team], open(team_path, "w"), indent=4)
        except IOError:
            logger.error("Couldn't write data for team %s" % team)
            raise HTTPError(500)
        except ValueError:
            logger.error("Couldn't dump data for team %s" % team)
            raise HTTPError(500)

        # Remove the symlinks

        links = [
            os.path.join(os.path.dirname(__file__), "data", task, "by_lang",
                         "%s (%s).pdf" % (lang, team)),
            os.path.join(os.path.dirname(__file__), "data", task, "by_team",
                         "%s (%s).pdf" % (team, lang))
        ]

        for link in links:
            os.remove(link)

        proxy.send("delete", "%s %s %s" % (team, lang, task), '*')
Example #14
0
def printWarning(content):
    logger.warn(content)
Example #15
0
def get(request):
    data = copy.copy(return_data)

    ##############################################################################
    # url parser
    url= request.get_full_path()
    logger.info("[REQUEST_URL]: {0}".format(url))
    url_tuple = urlparse.urlparse(url)
    # scheme='http', netloc='192.168.0.136:14001', path='/name_parser/', params='',
    # query='name=%E6%BD%98%E5%B0%91%E5%AE%81&birthday=1990-12-01&sex=1', fragment='
    (_scheme, _netloc, _path, _params, _query, _fragment) = (
        url_tuple.scheme, url_tuple.netloc, url_tuple.path, url_tuple.params,
        url_tuple.query, url_tuple.fragment)

    # 获得相关的参数,并生成id
    get_params_list = dict_to_order_list(request.GET)
    post_params_list = dict_to_order_list(request.POST)
    id_dict = dict(get=get_params_list, post=post_params_list, path=_path)
    id_json = json.dumps(id_dict)
    id = get_hash_id(id_json)

    ###############################################################################
    # 2, first check the mysql and return data if existed
    try:
        logger.info("[PARSE_ID]: {0}".format(id))
        # obj = CacheTable.objects.get(id=id)
        # obj_data = obj.data
        obj_data = db_server.get(id)
        data['data'] = json.loads(obj_data)

        data = json.dumps(data)
        logger.info("get old data and return")
        return HttpResponse(data,  content_type="application/json")
    except :
        msg = traceback.format_exc()
        logger.warn(msg)

    ################################################################################
    if not _scheme: _scheme = DEFAULT_SCHEME
    new_url = urlparse.urlunparse([_scheme, data_api, _path, _params, _query, _fragment])
    logger.info("[TRANSFER URL]: {0}".format(new_url))

    # 4, 根据或的url通过数据接口获得数据
    try:
        # resp = requests.post(new_url, data=request.POST), # TODO
        # '<html><title>405: Method Not Allowed</title><body>405: Method Not Allowed</body></html>'
        # resp = urllib2.urlopen(new_url, data=urllib.urlencode(request.POST), timeout=1)
        resp = urllib2.urlopen(new_url, data=urllib.urlencode(request.POST), timeout=1)
        result = extract_data(resp.read())
        data['data'] = result

        # save the data
        try:
            result = json.dumps(result)
            logger.info("insert new item [id: {0}]".format(id))
            db_server.insert(id, data_dict=dict(id=id, path=_path, info=id_json, data=result))
            # created, obj = CacheTable.objects.update_or_create(id=id,
            #         defaults=dict(id=id, path=_path, info=id_json, data=result))
        except:
            msg = traceback.format_exc()
            logger.error(msg)
    except Exception, ex:
        msg = traceback.format_exc()
        print msg
        data['code'] = -1
        data['msg'] = ex.message