예제 #1
0
async def app_server(q):
    s = SERVER(q)
    app = web.Application()
    aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader(
        'templates'))  # Add template to search path
    app.router.add_static(
        f'{getConfig("context")}/static',
        path=os.path.join(os.path.dirname(os.path.abspath(__file__)),
                          'static'),
        append_version=True)  # Add static files to the search path

    app.router.add_route('GET', f'{getConfig("context")}', s.home)
    app.router.add_route('GET', f'{getConfig("context")}/course', s.course)
    app.router.add_route('POST', f'{getConfig("context")}/isRun', s.isRun)
    app.router.add_route('GET', f'{getConfig("context")}/delete/{{Id}}',
                         s.delete)
    app.router.add_route('GET', f'{getConfig("context")}/edit/{{Id}}', s.edit)
    app.router.add_route('POST', f'{getConfig("context")}/update', s.update)
    app.router.add_route('GET', f'{getConfig("context")}/reload', s.reload)
    app.router.add_route('POST', f'{getConfig("context")}/save', s.save)

    runner = web.AppRunner(app)
    await runner.setup()
    site = web.TCPSite(runner, getConfig('host'), getConfig('port'))
    await site.start()
예제 #2
0
    def __init__(self):
        self.requ_date = {}
        self.search_url = "http://music.163.com/api/search/get/web?csrf_token="
        # 通过歌曲名称获得歌曲的ID信息(GET请求)
        self.play_url = "http://music.163.com/weapi/song/enhance/player/url?csrf_token="
        # 通过加密数据POST请求得到播放地址
        # https://api.imjad.cn/cloudmusic/?type=song&id=%s&br=320000
        self.url_ = "http://music.163.com/song/media/outer/url?id=%s.mp3"
        # 网易根据api直接请求到下载音乐地址(%s均为歌曲id)
        self.comment_url = "https://music.163.com/weapi/v1/resource/comments/R_SO_4_%s?csrf_token="
        # 通过加密数据POST请求得到评论内容
        self.lyric_url = "http://music.163.com/api/song/lyric?id=%s&lv=1&kv=1&tv=-1"
        # 通过id获得歌曲的歌词信息(json包) 只需要(GET请求)
        self.session = requests.session()
        self.headers = {
            'User-Agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:57.0) Gecko/20100101 Firefox/57.0',
            'Referer': 'http://music.163.com/',
            'Content-Type': 'application/x-www-form-urlencoded'
        }
        self.play_default = "{\"ids\":\"[%s]\",\"br\":%s\
        ,\"csrf_token\":\"\"}"

        host = config.getConfig("database", "dbhost")
        port = config.getConfig("database", "dbport")
        self.r = redis.Redis(host=host, port=int(port), decode_responses=True)
        self.br = "128000"
예제 #3
0
    def _loadConf(self):
        self.url = config.getConfig("twitter", "url")

        self.dh = config.getConfig("html", "divh")
        self.dt = config.getConfig("html", "divt")
        self.ah = config.getConfig("html", "ah")
        self.at = config.getConfig("html", "at")
예제 #4
0
 def _server_init(self, client_info=None):
     if self.server_manager is None:
         import manager
         import config
         config.getConfig()
         self.server_manager = manager.ServerManager()
         self.server_manager.init(client_info)
예제 #5
0
def notify(recipient, job, message="Notification from Boru"):

  # ===================
  msg = MIMEMultipart()
  sendr = config.getConfig("awsSMTPSender")
  # =======================================


  # ========================================
  msg['Subject'] = "Weekly Labs Status Report"
  body = getLabStatus()

  print(body)
  return
  msg['From'] = sendr
  if(isinstance(recipient, list)):
    msg['To'] = ", ".join(recipient)
  else:
    msg['To'] = recipient

  msg.attach(MIMEText(body))
  # ========================

  # send email ===================================================
  server = smtplib.SMTP('email-smtp.us-east-1.amazonaws.com', 587)
  server.starttls()
  awsSMTPuser = config.getConfig("awsSMTPuser")
  awsSMTPpassword = config.getConfig("awsSMTPpassword")
  server.login(awsSMTPuser, awsSMTPpassword)
  server.sendmail(sendr, recipient, msg.as_string())
  server.quit()
  # ===========
  print("Done.")
예제 #6
0
def cartesian_move_to(robot,constraints,
    delta=1e-2,
    method='any',
    solver=None,
    feasibilityTest=None,
    numSamples=1000,
    maximize=False):
    """A convenience function that generates a path that performs a linear cartesian interpolation
    starting from the robot's current configuration and ending at the desired IK constraints.
    This is a bit more convenient than cartesian_interpolate_linear since you only need to pass in
    the target objective, rather than the start and end Cartesian parameters as well. Typical calling
    is path = cartesian_move_to(robot,goal). 

    Other arguments are equivalent to those in cartesian_interpolate_linear.
    """
    if not hasattr(constraints,'__iter__'):
        constraints = [constraints]
    for c in constraints:
        assert isinstance(c,IKObjective)
    #extract the task space coordinates of the constraints
    taskEnd = config.getConfig(constraints)
    #extract the task space coordinates of the current robot
    for c in constraints:
        xforml = robot.link(c.link()).getTransform()
        xformr = robot.link(c.destLink()).getTransform() if c.destLink() >= 0 else se3.identity()
        c.matchDestination(se3.mul(se3.inv(xformr),xforml))
    taskStart = config.getConfig(constraints)
    #just call the solver
    return cartesian_interpolate_linear(robot,taskStart,taskEnd,
        delta=delta,method=method,solver=solver,feasibilityTest=feasibilityTest,
        numSamples=numSamples,maximize=maximize)
예제 #7
0
    def __init__(self):

        self.headers = {
            'x-api-key': C.getConfig("key"),
            'x-api-user': C.getConfig("uuid")
        }
        self.ClearQueues()
예제 #8
0
 def requests_play_url(self, music_id, proxies=''):
     self.post_data = AES.encrypted_request(self.play_default %
                                            (music_id, self.br))
     if proxies == '':
         resp = self.session.post(url=self.play_url,
                                  data=self.post_data,
                                  headers=self.headers)
     else:
         resp = self.session.post(url=self.play_url,
                                  data=self.post_data,
                                  headers=self.headers,
                                  proxies=proxies)
     try:
         resp = resp.json()
     except:
         host = config.getConfig("database", "dbhost")
         port = config.getConfig("database", "dbport")
         self.r = redis.Redis(host=str(host), port=int(port), db=4)
         random_int = random.sample(range(0, self.r.dbsize()), 1)
         proxies = self.r.get(str(random_int[0]))
         self.requests_play_url(music_id, eval(proxies))
     play_url = resp["data"][0]['url']
     if play_url == None:
         play_url = self.url_ % (music_id)
     self.requ_date['0'] = {}
     self.requ_date['0'].update({"play_url": play_url})
예제 #9
0
    def music_detail(self, music_id, _update="0", proxies=''):
        url = "http://music.163.com/api/song/detail?ids=[%s]"
        if proxies == '':
            resp = self.session.get(url=url % music_id, headers=self.headers)
        else:
            resp = self.session.get(url=url % music_id,
                                    headers=self.headers,
                                    proxies=proxies)
        try:
            content = resp.json()
        except:
            host = config.getConfig("database", "dbhost")
            port = config.getConfig("database", "dbport")
            self.r = redis.Redis(host=str(host), port=int(port), db=4)
            random_int = random.sample(range(0, self.r.dbsize()), 1)
            proxies = self.r.get(str(random_int[0]))
            self.music_detail(music_id, eval(proxies))

        name = content['songs'][0]["name"]
        artists = content['songs'][0]["artists"][0]["name"]
        image_url = content['songs'][0]["album"]["picUrl"]
        music_data = {}
        music_data.update({
            "image_url": image_url,
            "music_name": name,
            "artists": artists
        })
        try:
            self.requ_date[_update].update(music_data)
        except:
            self.requ_date[_update] = {}
            self.requ_date[_update].update(music_data)

        return self.requ_date
예제 #10
0
def cartesian_move_to(robot,constraints,
	delta=1e-2,
	method='any',
	solver=None,
	feasibilityTest=None,
	numSamples=1000,
	maximize=False):
	"""A convenience function that generates a path that performs a linear cartesian interpolation
	starting from the robot's current configuration and ending at the desired IK constraints.
	This is a bit more convenient than cartesian_interpolate_linear since you only need to pass in
	the target objective, rather than the start and end Cartesian parameters as well. Typical calling
	is path = cartesian_move_to(robot,goal). 

	Other arguments are equivalent to those in cartesian_interpolate_linear.
	"""
	if not hasattr(constraints,'__iter__'):
		constraints = [constraints]
	for c in constraints:
		assert isinstance(c,IKObjective)
	#extract the task space coordinates of the constraints
	taskEnd = config.getConfig(constraints)
	#extract the task space coordinates of the current robot
	for c in constraints:
		xforml = robot.link(c.link()).getTransform()
		xformr = robot.link(c.destLink()).getTransform() if c.destLink() >= 0 else se3.identity()
		c.matchDestination(se3.mul(se3.inv(xformr),xforml))
	taskStart = config.getConfig(constraints)
	#just call the solver
	return cartesian_interpolate_linear(robot,taskStart,taskEnd,
		delta=delta,method=method,solver=solver,feasibilityTest=feasibilityTest,
		numSamples=numSamples,maximize=maximize)
예제 #11
0
	def __init__(self, width, height):
		self.width = width
		self.height = height
		self.taille_case = config.getConfig()["taille_case"] # Taille des cases du niveau
		self.nb_case = config.getConfig()["nb_case"] # Nombre de case par ligne

		self.niveau = niveau = dongeon.Niveau("../niveau/exemple/blank_level.txt") # on génère un niveau vide
		self.type_case = "mur" # Type de case d'édition par défaut
		self.type_mode = "selection" # Type de clique par défaut
		self.case_selection = None
		self.case_selection_cible = []

		''' on crée un carré qui servira à montrer la selection d'une case. '''
		self._selection_rect = pygame.Surface((self.taille_case, self.taille_case)).convert_alpha()
		self._selection_rect.fill((0, 0, 0, 0))
		self._selection_cible_rect = self._selection_rect.copy()
		pygame.draw.rect(self._selection_rect, (255, 0, 0), Rect((0, 0), (self.taille_case, self.taille_case)), 1)
		pygame.draw.rect(self._selection_cible_rect, (0, 0, 255), Rect((0, 0), (self.taille_case, self.taille_case)), 1)

		''' variables contenant les widget à mettre à jour '''
		self.widg_entry = None 
		self.widg_select_mode = None
		self.widg_label_param = None 
		self.widg_button_cible = None
		self.widg_button_mode = None
		self.widg_button_test = None # Bouton permettant de tester le niveau en cours
		self.frame1 = None
		self.frame2 = None
		self.frame3 = None

		''' Variable pour le personnage, seulement en mode test '''
		self.perso = None 

		self._init_editeur() # On initalise l'éditeur
예제 #12
0
def main():

    args = get_args()

    recipients = args.recipient
    msg = MIMEMultipart()
    msg['From'] = sendr
    msg['To'] = ", ".join(recipients)
    msg['Subject'] = args.subject
    msg.attach(MIMEText(args.body, 'html'))

    if args.attachment:
        filename = os.path.basename(args.attachment)
        attachment = open(args.attachment, "rb")

        part = MIMEBase('application', 'octet-stream')
        part.set_payload((attachment).read())
        encoders.encode_base64(part)
        part.add_header('Content-Disposition',
                        "attachment; filename= %s" % filename)

        msg.attach(part)

    server = smtplib.SMTP('email-smtp.us-east-1.amazonaws.com', 587)
    server.starttls()
    #server.set_debuglevel(1)
    awsSMTPuser = config.getConfig("awsSMTPuser")
    awsSMTPpassword = config.getConfig("awsSMTPpassword")
    server.login(str(awsSMTPuser), str(awsSMTPpassword))
    server.sendmail(sendr, args.recipient, msg.as_string())
    server.quit()
예제 #13
0
    def __init__(self):
        """
        预处理包括连接mongodb数据库(利用config方法),设置用户代理等信息
        以及self.Sync_NEM_Url 是获得用户歌单的网易API具体地址
        连接的数据表时mydb, 然后选择mydb中的test_set集合
        """
        host = config.getConfig("database", "dbhost")
        port = config.getConfig("database", "dbport")
        self.r = redis.Redis(host=host,
                             port=int(port),
                             decode_responses=True,
                             db=2)

        host = config.getConfig("mongodb", "mongodbhost")
        port = config.getConfig("mongodb", "mongodbport")
        self.conn = MongoClient(str(host), int(port))
        self.db = self.conn.mydb
        self.my_set = self.db.test_set
        self.session = requests.session()
        self.headers = {
            'User-Agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13;rv:57.0) Gecko/20100101 Firefox/57.0',
            'Referer':
            "http://music.163.com/api/user/playlist/?offset=0&limit=100&uid=%s"
        }
        self.Sync_NEM_Url = "http://music.163.com/api/user/playlist/?offset=0&limit=100&uid=%s"
예제 #14
0
 def __init__(self):
     self.config = getConfig(GLOBALCONFIGFILE)
     print self.config
     self.config.update(getConfig(CONFIGFILE))
     print self.config
     self.moduleconfig = getModuleConfig(MODULE_CONFIG_FILE)
     evaluator_name = self.config.get('EVALUATOR',"Deny")
     self.evaluatorconfig = getModuleConfig(join(DAEMON_ROOT,evaluator_name+".conf"))
     self.modules = {}
     for modulename in [f.strip(".py") for f in os.listdir(METRICSPATH) if (f[-3:] == ".py" and f[:8] != "__init__")]:
         with open(USERLOGFILE,"a") as fout:
             fout.write("loading {}\n".format(modulename))
         try:
             self.modules[modulename] = __import__("metrics."+modulename,globals(),locals(),['Metric'], -1).Metric(self.moduleconfig[modulename])
         except Exception as e:
             with open(USERLOGFILE,"a") as fout:
                 fout.write("{} unable to load: {}\n".format(modulename,traceback.format_exc()))
                 fout.write("{} \n".format(str(e)))  
                 #fout.write(str(sys.exc_info()[0])) 
                 traceback.print_exc(file = fout)
     self.config["modules"] = self.modules.keys()
     self.evaluator = __import__("evaluators."+evaluator_name,globals(),locals(),['Evaluator'],-1).Evaluator(self.moduleconfig)
     bus = dbus.SystemBus()
     proxy = bus.get_object('org.lovi9573.sleepyboxservice', '/org/lovi9573/sleepyboxservice',False)
     proxy.connect_to_signal('signal', self.check, 'org.lovi9573.sleepyboxservice')
     proxy.connect_to_signal('signalsleeptime', self.handle_signalsleeptime, 'org.lovi9573.sleepyboxservice')
     self.serviceIface = dbus.Interface(proxy,'org.lovi9573.sleepyboxservice')
     bus = dbus.SessionBus()
     proxy = bus.get_object('org.gnome.ScreenSaver', '/org/gnome/ScreenSaver')
     self.screenIface = dbus.Interface(proxy,'org.gnome.ScreenSaver')
예제 #15
0
    def __init__(self):
        self.sqlite_path = getConfig('sqlite_path')
        self.table_name = getConfig('table_name')
        self.con = None
        self.cur = None

        self.connect()
        self.initialize()
예제 #16
0
def fetchFreeBeautyTry(user):
    config.getConfig(user)
    prodList, shopList = getFreeBeautyTryList(user)
    for prod in prodList:
        signFreeBeautyTry(prod, user)

    for shop in shopList:
        getShopDetail(shop, user)
        signFreeBeautyTry(shop, user)
예제 #17
0
def fetchFreeDine(user):
    # 1: 美食, 2:美容, 3:婚嫁 4:亲子  6:玩乐 10:生活服务 99:其他
    for stype in [3, 1, 2, 6, 10, 99]:
        config.getConfig(user)
        dineList = getAllFreeDineList(user, stype)
        for dine in dineList:
            signUpFreeDine(dine, user, stype)

    getSuccessSaveFreeDine(user)
예제 #18
0
 def __init__(self):
     db_config = config.getConfig('db')
     weibo_config = config.getConfig('weibo')
     app_config = config.getConfig('app')
     
     self.db = Mysql(db_config['host'], db_config['user'], db_config['passwd'], db_config['db'], db_config['charset'])
     self.user = User()
     self.wb = Weibo(weibo_config['username'], weibo_config['password'], weibo_config['appkey'])
     self.config = app_config
예제 #19
0
 def __initDBConnection(self):
     dbSectionName = "MONGODB"
     __host = config.getConfig().get(dbSectionName, "Host")
     __port = config.getConfig().getint(dbSectionName, "Port")
     try:
         client = MongoClient(host=__host, port=__port)
     except ConnectionFailure, e:
         sys.stderr.write("Could not connect to MongoDB: %s" % e)
         sys.exit(1)
    def __init__(self,
                 schema=None,
                 name=None,
                 defaults=None,
                 connected_plugin=None):

        if name:
            self.NAME = name
        if self.NAME:
            self.schema_name = self.NAME
        else:
            self.schema_name = 'UNKNOWN'
        if schema:
            constructor_logger.debug(self.__class__.__name__ + " " +
                                     self.NAME + " getting input schema " +
                                     str(schema))
            self.schema = schema
        else:
            self.schema = config.getConfig()['schema', self.NAME]
            constructor_logger.debug(self.__class__.__name__ + " " +
                                     self.NAME + " getting yaml schema " +
                                     str(self.schema))

        if defaults:
            constructor_logger.debug(self.__class__.__name__ + " " +
                                     self.NAME + " getting input defaults " +
                                     str(defaults))
            self.defaults = defaults
        else:
            self.defaults = config.getConfig()['defaults', self.NAME]
            constructor_logger.debug(self.__class__.__name__ + " " +
                                     self.NAME + " getting yaml defaults " +
                                     str(self.defaults))
        self.connected_plugin = connected_plugin
        module_logger.debug(self.__class__.__name__ + ": " + str(self.NAME))

        self.templates = copy.deepcopy(
            self.schema.get('substitutions', OrderedDict()))
        constructor_logger.debug(self.__class__.__name__ + " " + self.NAME +
                                 " templates schema  " + str(self.templates))
        # needed to prevent crash when key susbstitutions has no following substitutions
        if self.templates is None:
            self.templates = OrderedDict()
        if hasattr(self.defaults, 'get'):
            default_subst = copy.deepcopy(
                self.defaults.get('substitutions', OrderedDict()))
            constructor_logger.debug(self.__class__.__name__ + " " +
                                     self.NAME + " templates defaults " +
                                     str(default_subst))
            # needed to prevent crash when key susbstitutions has no following substitutions
            if hasattr(default_subst, '__getitem__'):
                for key in default_subst:
                    self.templates[key] = default_subst[key]

        constructor_logger.debug(self.__class__.__name__ + " " + self.NAME +
                                 " templates merged " + str(self.templates))
예제 #21
0
def checkin(user):
    config.getConfig(user)

    url = 'https://m.dianping.com/mobile/event/arro/checkin'
    setQueryHeader(user)
    response = request.openUrl(url, user, {})
    content = response.read()
    content = str(content, 'utf-8')

    logger.info("霸王餐签到结果:{0}".format(content))
    checkLoginStatus(user, content)
예제 #22
0
def main():
    process_1 = Process(target=main_server, args=(q, ))
    process_1.daemon = True
    process_1.start()

    options = Options(listen_host=getConfig('proxy_host'),
                      listen_port=int(getConfig('proxy_port')),
                      http2=True)
    proxy = ProxyMaster(options, with_termlog=False, with_dumper=False)
    r_e = RequestEvent(q)
    proxy.addons.add(r_e)
    proxy.start_run()
예제 #23
0
파일: paths.py 프로젝트: Sepero/subuser
def getProgramHomeDirOnHost(programName):
  """ Each program has it's own home directory(or perhaps a shared one).
          This directory has two absolute paths:
            The path to the directory as it appears on the host machine,
            and the path to the directory in the docker container.
          Return the path to the directory as it appears on the host macine. """
  programPermissions = permissions.getPermissions(programName)
  sharedHome = permissions.getSharedHome(programPermissions)
  if sharedHome:
    return os.path.join(config.getConfig()["program-home-dirs-dir"],sharedHome)
  else:
    return os.path.join(config.getConfig()["program-home-dirs-dir"],programName)
예제 #24
0
def saveArtifacts(day):
    log("Saving artifacts")

    for node in getConfig()["activeCams"]:
        mkdir(f"../data/timelapse/{node}")

    # Only works with `os.system` *shrug*
    for node in getConfig()["activeCams"]:
        os.system(f"mv ../data/processed/{node}/* ../data/timelapse/{node}")
    
    run(['aws', 's3', 'sync', '../data/timelapse',
         's3://atlas-timelapse', '--only-show-errors'])
예제 #25
0
    def pre_request(self, url, proxies=''):
        """
        这个类用于维护redis-1更新
        更新的内容为热门歌单数据
        储存格式范例已经在类的说明中说明
        """
        global Page_Start_Url, Page_Start, Raw_Page_Sum
        if proxies == '':
            resp = self.session.get(url=self.NEMurl + url,
                                    headers=self.headers)
        else:
            resp = self.session.get(url=self.NEMurl + url,
                                    headers=self.headers,
                                    proxies=proxies)
        try:
            regex = re.compile(
                r"\<img class=\"[\w0-9\-]+\" src=\"(.+)\"\/>\n<a title=\"([\|\✞\♪\(\)\?\?\♡\【\¼\】\/\[\]\丨\s\「\」\|\『\』\——\•\★\"\u4e00-\u9fa5\w\d\s\,\.]+)\" href=\"(.+)\" class="
            )
            result = regex.findall(resp.text)
            regex = re.compile(r"<a href=\"(.+)\" class=\"zpgi\">\d{1,3}</a>")
            Page_Url = regex.findall(resp.text)

            Limit_Max_Page = int(
                re.findall(r'offset=(\d{2,5})', Page_Url[-1])[0])
        except:
            host = config.getConfig("database", "dbhost")
            port = config.getConfig("database", "dbport")
            self.r = redis.Redis(host=str(host), port=int(port), db=4)
            random_int = random.sample(range(0, self.r.dbsize()), 1)
            proxies = self.r.get(str(random_int[0]))
            self.pre_request(url, eval(proxies))

        Raw_Page_Sum = 0
        for i in range(Raw_Page_Sum, Raw_Page_Sum + len(result)):
            self.r.set(
                str(i), result[i - Raw_Page_Sum][0] + "user_song_list" +
                result[i - Raw_Page_Sum][1] + "user_song_list" +
                result[i - Raw_Page_Sum][2])
        print("Update")
        Raw_Page_Sum += len(result)
        print(Raw_Page_Sum)
        regex = re.compile(r"<a href=\"(.+)\" class=\"zpgi\">\d{1,3}</a>")
        Page_Url = regex.findall(resp.text)

        Limit_Max_Page = int(re.findall(r'offset=(\d{2,5})', Page_Url[-1])[0])
        if Page_Start <= Limit_Max_Page:
            Page_Start += 35
            url = Page_Start_Url + str(Page_Start)
            time.sleep(5)
            test.pre_request(url)
        else:
            return 1
예제 #26
0
def archive(day):
    log("Archiving raw images")
    for node in getConfig()["activeCams"]:
        run(['aws', 's3', 'sync', f's3://atlascampi/{node}/{day}',
            f's3://atlascampi-archive/{node}/{day}', '--only-show-errors'])

    log("Clear raw images from S3 (exclude today)")
    if day != getToday():
        for node in getConfig()["activeCams"]:
            os.system(
                f'aws s3 rm s3://atlascampi/{node}/{day} --recursive --exclude "*/{getToday()}/*"')
    
    clearArchive()
예제 #27
0
 def stop(self):
     """
     halt flag is set and one last connect made locally
     in order get listen method out of loop 
     """
     self.halt = 1
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     server_address = (config.getConfig().get(self.configSectionName,
                                              "Url"),
                       config.getConfig().getint(self.configSectionName,
                                                 "Port"))
     sock.connect(server_address)
     sock.close()
예제 #28
0
 def __initSocket(self):
     # Create a TCP/IP socket
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     # Bind the socket to the port
     server_address = (config.getConfig().get(self.configSectionName,
                                              "Url"),
                       config.getConfig().getint(self.configSectionName,
                                                 "Port"))
     print >> sys.stderr, "Server socket for incomming ", self.configSectionName, " data: starting up on %s port %s" % server_address
     sock.bind(server_address)
     # Listen for incoming connections
     sock.listen(1)
     return sock
예제 #29
0
    def __init__(self):
        """
        Initializes serverhost ip and port numbers & the sensors
        """
        self.serverHostIP = config.getConfig().get("SERVER", "IP")
        self.serverHostPort = config.getConfig().getint("SERVER", "Port")
        ################################################################################
        #initialize scheduler here by calling initScheduler method that will do the job
        ################################################################################
        self.initScheduler()

        #initialize sensors----------------------------------------------------
        self.initTobiiEyeTracker()
예제 #30
0
def notify(recipient, job, message="Notification from Boru"):

    # ===================
    msg = MIMEMultipart()
    sendr = config.getConfig("awsSMTPSender")
    # =======================================

    # info for output file ================
    tag = str(job['tag'])
    courseName = str(job['courseName'])
    failedLabs = str(job['failedLabs'])
    errorInfo = str(job['errorInfo'])
    # =======================================

    # =================================================
    # Only send email when failedLabs actually exist
    # =================================================
    if (list(job['failedLabs'])):
        # ========================================================================
        msg['Subject'] = "{} : {} - Failed Labs".format(
            str(courseName), str(tag))
        body = "Here is a list of all labs that failed to start when starting the {}: {} class:\n".format(
            str(courseName), str(tag), str(failedLabs), str(errorInfo))

        for i in job['failedLabs']:
            body = body + "\n{}".format(str(i))

        body = body + "\n\nError Information:\n\n{}\n\n// Boru".format(
            str(errorInfo))

        msg['From'] = sendr

        if (isinstance(recipient, list)):
            msg['To'] = ", ".join(recipient)
        else:
            msg['To'] = recipient
        msg.attach(MIMEText(body))
        # ========================

        # send email ===================================================
        server = smtplib.SMTP('server.com', 587)
        server.starttls()
        awsSMTPuser = config.getConfig("awsSMTPuser")
        awsSMTPpassword = config.getConfig("awsSMTPpassword")
        server.login(awsSMTPuser, awsSMTPpassword)
        server.sendmail(sendr, recipient, msg.as_string())
        server.quit()
        # ===========
    else:
        return
예제 #31
0
파일: paths.py 프로젝트: rnauber/subuser
def getProgramHomeDirOnHost(programName):
    """ Each program has it's own home directory(or perhaps a shared one).
          This directory has two absolute paths:
            The path to the directory as it appears on the host machine,
            and the path to the directory in the docker container.
          Return the path to the directory as it appears on the host macine. """
    programPermissions = permissions.getPermissions(programName)
    sharedHome = permissions.getSharedHome(programPermissions)
    if sharedHome:
        return os.path.join(config.getConfig()["program-home-dirs-dir"],
                            sharedHome)
    else:
        return os.path.join(config.getConfig()["program-home-dirs-dir"],
                            programName)
예제 #32
0
async def run(args, client, message: discord.Message):
    await message.channel.send('Discordサーバーをもとに戻しています')

    if not message.guild:
        raise exception.VemtCommandError("ギルドの取得に失敗しました", detail=f"message.guild={str(message.guild)}")

    guild: discord.Guild = message.guild

    # 作成済みのチャンネルを削除
    # あえて名前一致で削除する
    current_channels: List[discord.TextChannel] = guild.channels
    def_channels: List[str] = [
        config.getConfig().categoryName.bot,
        config.getConfig().categoryName.contact,
        config.getConfig().channelName.botControl,
        config.getConfig().channelName.entry,
        config.getConfig().channelName.status,
        config.getConfig().channelName.query
    ]

    for ch in current_channels:
        for dc in def_channels:
            if ch.name == dc:
                await ch.delete()

    # コンタクトチャンネル
    entries_list = entries.getAll(guild.id)
    for ch in current_channels:
        for entry in entries_list:
            if ch.id == entry.contactChannelId:
                await ch.delete()

    # 作成済みのロールを削除
    current_roles: List[discord.Role] = guild.roles
    def_roles: List[str] = [
        config.getConfig().roleName.botAdmin,
        config.getConfig().roleName.preExhibitor,
        config.getConfig().roleName.exhibitor,
        config.getConfig().roleName.manager
    ]

    for rl in current_roles:
        for drl in def_roles:
            if rl.name == drl:
                await rl.delete()

    # ニックネーム戻す
    await guild.me.edit(nick=None)
    await message.channel.send("**成功** サーバーをもとに戻しました\n")
    def initializeBottleServer(self):
        app = bottle.app()
        app.install(EnableCors.EnableCors())

        __serverHostIP = config.getConfig().get("SERVER", "IP")
        __serverHostPort = config.getConfig().getint("SERVER", "Port")
        print "Starting http server on http://", __serverHostIP, ':', __serverHostPort

        self.server = StoppableWSGIRefServer.StoppableWSGIRefServer(
            host=__serverHostIP, port=__serverHostPort)

        self.appThread = threading.Thread(target=app.run,
                                          kwargs=dict(server=self.server))
        self.appThread.daemon = True
        self.appThread.start()
예제 #34
0
 def __init__(self):
     self.session = requests.session()
     self.headers = {
         'User-Agent':
         'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:57.0) Gecko/20100101 Firefox/57.0',
         'Referer': 'http://www.66ip.cn/areaindex_11/1.html'
     }
     self.flag = 1
     if int(config.getConfig("open_database", "redis")) == 1:
         host = config.getConfig("database", "dbhost")
         port = config.getConfig("database", "dbport")
         self.r = redis.Redis(host=host,
                              port=int(port),
                              decode_responses=True,
                              db=4)
예제 #35
0
def init():
	status,data,update_date=cron.check()
	if status:
		#download index changed
		dic=parseIndex(data)#fetch json of data
		if dic is None:
			sys.exit(0)
		updateFiles(dic)
		stats={}
		stats['lastUpdated']=update_date.strip()
		stats["files"]={}
		for key in dic:
			if key in config.getConfig("tracking_files"):
				stats["files"][key]=dic[key].strip()
		try:
			del stats["files"]["../"] #remove parent index
		except KeyError:
			pass
		try:
			open("stats.json","w").write(json.dumps(stats, indent=4, sort_keys=True))
			log.put("Stats updated","SUCCESS")
		except:
			log.put("Cannot update stats","FAIL")
		
		log.headPut("Finished cron-dbpedia","SUCCESS")
	else:
		#No change exit silently
		sys.exit(0)
def find_reduction(rname):
    modlist = config.getConfig()["reductions"]
    for mod in modlist:
        mod = __import__(mod, fromlist=['getReduction'])
        f = getattr(mod, 'getReduction')
        return f(rname)
    return None
예제 #37
0
 def __init__(self,game,language,servername,ip=None,port=22):
     logging.basicConfig(level=logging.INFO,
             format='%(asctime)s %(levelname)s %(message)s',
             datefmt='%Y-%m-%d %H:%M:%S',
             )
     self.game = game
     self.language = language
     self.servername = servername
     self.ip = ip
     mainConfig = config.getConfig("main")
     self.rootDir = mainConfig.get("main","rootdir").replace("${game}",game)
     self.commonPath = "newserver/%s/common"%language
     self.templatePath = "newserver/%s/template"%language
     self.propertiesPath = "newserver/%s/properties"%language
     self.wwwPath = "newserver/%s/www"%language
     self.yx,self.quhao = getYxNum(servername)
     if not check.checkServer(str(servername)):
         print "请输入正确的游戏服名称"
         logging.error("请输入正确的游戏服名称")
         sys.exit(1)
     gameConfig = config.getConfig(game)
     #if not check.checkIp(str(ip)):
     if ip == None:
         backstage_db = getOption(gameConfig,language,"backstage_db")
         backstage_tag = getOption(gameConfig,language,"backstage_tag")
         is_mobile = getOption(gameConfig,language,"is_mobile",type="bool")
         if is_mobile:
             partnersType = 2
         else:
             partnersType = 1
         backstage_ip = getOption(gameConfig,language,"backstage")
         print backstage_db,backstage_tag,partnersType,"mix",backstage_ip,servername
         serverList = serverlist.serverRange(backstage_db,backstage_tag,partnersType,"mix",backstage_ip,serverlist=servername)
         if len(serverList) != 1:
             print "ERROR: 获取服务器ip失败或者不唯一",serverList
             sys.exit(1)
         else:
             self.ip = serverList[0][1]
     self.ssh = ssh.ssh(self.ip,port=port)
     self.www_dir_type = getOption(gameConfig,language,"www_dir_type")
     www_ip = getOption(gameConfig,language,"www_ip")
     www_port = getOption(gameConfig,language,"www_port")
     www_ssh_port = getOption(gameConfig,language,"www_ssh_port")
     self.www_root = getOption(gameConfig,language,"www_root")
     self.template_tar_dir = getOption(gameConfig,language,"template_tar_dir").replace(" ","").split(",")
     self.template_exclude_dir = getOption(gameConfig,language,"template_exclude_dir").replace(" ","").split(",")
     self.www_ssh = ssh.ssh(www_ip,port=int(www_ssh_port))
def makeHeader():
    cfg = getConfig()
    header = ""
    for entry in cfg["frameworks"]:
        header_dir = os.path.dirname(os.path.realpath(__file__))
        header_file = "%s/%s.header" % (header_dir, entry)
        header += open(header_file, "r").read()
    return header
def find_metacomp(fname):
    modlist = config.getConfig()["metacomps"]
    for mod in modlist:
        mod = __import__(mod, fromlist=['getMetacomp'])
        f = getattr(mod, 'getMetacomp')
        if f(fname):
            return f(fname)
        return None
def find_composition(fname):
    modlist = config.getConfig()["compositions"]
    for mod in modlist:
        mod = __import__(mod, fromlist=['getComposition'])
        f = getattr(mod, 'getComposition')
        if f(fname):
            return f(fname)
    return None
def get_function_parameter(fname, parameter):
    modlist = config.getConfig()["functions"]
    for mod in modlist:
        mod = __import__(mod, fromlist=['getFunctionEntry'])
        f = getattr(mod, 'getFunctionEntry')
        if f(fname):
            return f(fname)[parameter]
    return None
def list_compositions():
    modlist = config.getConfig()["compositions"]
    comp_list = []
    for mod in modlist:
        mod = __import__(mod, fromlist=['getCompositionNames'])
        f = getattr(mod, 'getCompositionNames')
        comp_list.extend(f())
    return comp_list
def list_functions():
    modlist = config.getConfig()["functions"]
    f_list = []
    for mod in modlist:
        mod = __import__(mod, fromlist=['table'])
        t = getattr(mod, 'table')
        fs = list(map(lambda x: x["name"], t))
        f_list.extend(fs)
    return f_list
def list_reductions():
    modlist = config.getConfig()["reductions"]
    red_list = []
    for mod in modlist:
        mod = __import__(mod, fromlist=['table'])
        t = getattr(mod, 'table')
        reds = list(map(lambda x: x["name"], t))
        red_list.extend(reds)
    return red_list
def getRepo(repoId):
    # :rtype: Repository
    cfg = getConfig()['repositories']
    if repoId is None or not repoId in cfg:
        raise HTTPResponse(400, "Invalid repoId value")
    repocfg = cfg[repoId]
    if not '_object' in repocfg:
        repo = Repository(repocfg)
    else:
        repo = repocfg['_object']
    return repo
예제 #46
0
파일: mounter.py 프로젝트: vimfan/Cachefs
    def __init__(self, cmdline, mountpoint=None):
        if mountpoint:
            self._mountpoint = mountpoint
        else:
            self._mountpoint = cmdline[1]
        self._cmdline = cmdline
        print(self._mountpoint)
        assert(os.path.isdir(self._mountpoint))

        self._processHandle = None
        self._cfg = config.getConfig()
예제 #47
0
def run_mms():
    config = mms_config.getConfig()
    init_locale()
    
    interface = config.get( 'mms', 'interface' )
    #initiate one of the webservice interfaces, REST is going to be the default
    if interface == 'soap':
        from mms.interfaces.soap import soap
        soap.run( config )
    elif interface == 'rest':
        from mms.interfaces.rest import rest
        rest.run( config )
def compile(function):
    cfg = getConfig()
    main_decl = ""
    main_defs = ""
    for file in function.src:
        main_decl += extractDeclarations(file[1])
        main_defs += extractDefinitions(file[1])
    if "output_folder" in cfg.keys():
        path = cfg["output_folder"]
        f = open(path + "/" + "main.c", "w")
        f.write(makeHeader() + main_decl + main_defs)
        f.close()
    return main_decl + main_defs
예제 #49
0
def getConfig():

    test_config                      = config.getConfig()

    test_config.ut_tests_root        = os.path.join(config.getCommonPrefix(), 'tests', 'test_workspace')
    test_config.ut_current_tc        = os.path.join(test_config.ut_tests_root, 'current')

    test_config.cache_manager.cache_root_dir = os.path.join(test_config.ut_current_tc, 'cache')
    test_config.cache_manager.source_dir     = os.path.join(test_config.ut_current_tc, 'cache_fs_source')

    test_config.cache_fs.cache_fs_mountpoint = os.path.join(test_config.ut_current_tc, 'cache_fs_mountpoint')

    return test_config
예제 #50
0
파일: paths.py 프로젝트: Sepero/subuser
def getPermissionsFilePath(programName):
  """ Return the path to the given programs permissions file.
Returns None if no permission file is found.
 """
  userPermissionsPath = os.path.join(config.getConfig()["user-set-permissions-dir"],programName,"permissions.json")
  if os.path.exists(userPermissionsPath):
    return userPermissionsPath
  else:
    sourceDir = getProgramSrcDir(programName)
    if not sourceDir == None:
      return os.path.join(sourceDir,"permissions.json")
    else:
      return None
 def __init__(self, repo, prId):
     self.repo = repo
     self.prId = prId
     self.assignee = None
     self.lastApproval = None
     self.lastApprovalReviews = None
     # GitHub API objects
     cfg = getConfig()
     self.apiClientPullrequest = GitHub(userAgent=cfg['userAgent'], reuseETag=True, access_token=cfg['githubAccessToken'])
     self.apiClientComments = GitHub(userAgent=cfg['userAgent'], reuseETag=True, access_token=cfg['githubAccessToken'])
     self.apiClientReviews = GitHub(userAgent=cfg['userAgent'], reuseETag=True, access_token=cfg['githubAccessToken'])
     self.apiClientExtraBranch = GitHub(userAgent=cfg['userAgent'], reuseETag=True, access_token=cfg['githubAccessToken'])
     self.apiClientExtraPullRequest = GitHub(userAgent=cfg['userAgent'], reuseETag=True, access_token=cfg['githubAccessToken'])
     self.extra = None
예제 #52
0
 def run(self):
     print u"creating client..."
     
     gtalk_config = config.getConfig('gtalk')
     c=Client(JID(gtalk_config['username']), gtalk_config['password'])
     
     print u"connecting..."
     c.connect()
     
     print u"looping..."
     try:
         c.loop(1)
     except KeyboardInterrupt:
         print u"disconnecting..."
         c.disconnect()
     
     print u"exiting..."
예제 #53
0
파일: cachefs.py 프로젝트: vimfan/Cachefs
    def parse(self, *args, **kw):
        '''This method shall be moved somewhere in config module'''
        fuse_args = super(CacheFs, self).parse(*args, **kw)
        if fuse_args.modifiers['showhelp']:
            # not beautiful, but works
            sys.exit(0) 

        self.cfg = config_canonical.getConfig()

        options, arguments =  self.cmdline

        loclogger.initialize(options.log_path)
        
        if options.debug:
            loclogger.enableDebug()

        self.cfg.parse(options, arguments, self.fuse_args.mountpoint)
예제 #54
0
파일: cron.py 프로젝트: SRMSE/cron-dbpedia
def downloadPage():
	global stats
	url=config.getConfig("base_url")
	html_data=None
	try:
		response=u.urlopen(url)
		response_headers = response.info().dict
		html_data=response.read()
		log.put("Index page downloaded","SUCCESS")
		last_update_date=response_headers["date"].strip()
		if stats['lastUpdated']!=last_update_date:
			log.put("New version available","INFO")
			return True,html_data,last_update_date
		else:
			log.put("New version not available","INFO")
			return False,None,None
	except Exception as e:
			log.put("Index page failed to download","FAIL")
			return False,None,None
예제 #55
0
 def __init__(self):
     logger = logging.getLogger('sleepybox daemon')
     fh = logging.FileHandler(ERRORLOG)
     formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
     fh.setFormatter(formatter)
     logger.addHandler(fh)
     self.vetos = False
     self.responses = 0
     self.fallasleeptime = datetime.datetime.now()
     self.config = getConfig(CONFIGFILE)
     self.cutoffs = getModuleConfig(CUTOFFSFILE)
     self.modules = {}
     for modulename in [f.strip(".py") for f in os.listdir("/usr/share/sleepybox/metrics") if (f[-3:] == ".py" and f[:8] != "__init__")]:
         with open(LOGFILE,"a") as fout:
             fout.write("loading {} \n".format(modulename))
         try:
             self.modules[modulename] = __import__("metrics."+modulename,globals(),locals(),['Metric'], -1).Metric(self.cutoffs[modulename])
         except Exception, e:
             logging.exception(e)
             with open(LOGFILE,"a") as fout:
                fout.write("{} unable to load: {}\n".format(modulename,traceback.format_exc())) 
예제 #56
0
def updateFiles(dic):
	log.put("Downloading tracked files","INFO")
	li=config.getConfig("tracking_files") #list of files to be updated
	for l in li:
		try:
			if(cron.stats["files"][l]!=dic[l]):
				#file changed
				dlfile(config.getConfig("base_url")+l)
				log.put("Parsing "+config.getConfig("base_url")+l,"INFO")
				nt.parseURI(l.replace(".bz2",""),l.split(".")[0],l.replace(".bz2",""),l.split(".")[0])
				log.put("Parsed "+config.getConfig("base_url")+l,"SUCCESS")
		except KeyError:
				dlfile(config.getConfig("base_url")+l)
				log.put("Parsing "+config.getConfig("base_url")+l,"INFO")
				nt.parseURI(l.replace(".bz2",""),l.split(".")[0])
				log.put("Parsed "+config.getConfig("base_url")+l,"SUCCESS")
	log.put("Tracked files updated","SUCCESS")
	log.put("Deleting all files from cache","INFO")
	os.system("rm *.nt")
	os.system("rm *.ttl")
	log.put("Files deleted from cache","SUCCESS")
예제 #57
0
def update(Game,Language,Version,UpdateType,Hd):
    global version,updateType,language,game,hd
    version = Version
    updateType = UpdateType
    language = Language
    game = Game
    hd = Hd
    
    if not version or not updateType or not language or not game:
        parser.error("参数不完整")

    print "开始更新..."
    if not re.match(r'[0-9]+(\.[0-9]+){3}',version):
        raise Exception("版本号:%s 不符合规则"%version)
    gameConfig = config.getConfig(game)
    ip = getOption(gameConfig,language,"mobile_www_ip")
    port = getOption(gameConfig,language,"mobile_www_port",type="int")
    if not port :
        port = 22

    global sshobj
    sshobj = ssh.ssh(ip,port)

    global onlineDir,onlineTestDir,startVersion,zipMode
    onlineDir = getOption(gameConfig,language,"mobile_www_root")
    onlineTestDir = getOption(gameConfig,language,"mobile_www_root_test")
    startVersion = getOption(gameConfig,language,"mobile_www_start_zip_version")
    zipMode = getOption(gameConfig,language,"mobile_www_diff",type="bool")

    cmd("test -d " + onlineDir)
    cmd("test -d " + onlineTestDir)
    cmd("test -d " + onlineTestDir + "/" + version)
    cmd("! test -d " + onlineDir + "/" + version)

    versionCheck()
    backupRes()
    resCopyToOnline()
예제 #58
0
def init(Game,Language,Version,UpdateType,Hd):
    global version,updateType,language,game,hd,wwwDir,zipDiff
    version = Version
    updateType = UpdateType
    language = Language
    game = Game
    hd = Hd
    global remoteShellDir
    remoteShellDir = "/app/opbin/workspace"
    if not version or not updateType or not language or not game:
        parser.error("参数不完整")
    if not re.match(r'[0-9]+(\.[0-9]+){3}',version):
        raise Exception("版本号:%s 不符合规则"%version)
    global ip,startZipVersion,cdn,port
    gameConfig = config.getConfig(game)
    wwwDir = getOption(gameConfig,language,"mobile_www_root_test")
    ip = getOption(gameConfig,language,"mobile_www_ip")
    port = getOption(gameConfig,language,"mobile_www_port")
    if not port or port.strip() == "":
        port = 22
    startZipVersion = getOption(gameConfig,language,"mobile_www_start_zip_version")
    cdn = getOption(gameConfig,language,"mobile_www_cdn")
    zipDiff = getOption(gameConfig,language,"mobile_www_diff",type="bool")
    update()
예제 #59
0
파일: news.py 프로젝트: tongpao/tongpao
 def __init__(self):
     self.config = config.getConfig()
     self.db = db(w_db = self.config.site_db_w) 
예제 #60
0
from shipping import Package
from ups import PACKAGES
import logging
logging.basicConfig(level=logging.DEBUG, filename='test.log')
from shipping import setLoggingLevel
setLoggingLevel(logging.DEBUG)
#logging.getLogger('%s.ups' % __name__).setLevel(logging.DEBUG)
#logging.getLogger('%s.fedex' % __name__).setLevel(logging.DEBUG)


white_house = Address('Mr. President', '1600 Pennsylvania Avenue NW', 'Washington', 'DC', '20500', 'US', company_name='White House')
powells = Address('Manager', '1005 W Burnside', 'Portland', 'OR', '97209', 'US', is_residence = False, company_name='Powell\'s City of Books')
our_place = Address('Wholesale Imports Guy', '4957 Summer Ave', 'Memphis', 'TN', '38122', 'US', is_residence = False, company_name='WholesaleImport.com')

import config
ups_config = config.getConfig('ups')
fedex_prod = config.getConfig('fedex')
fedex_test = config.getConfig('fedex_test')

from ups import UPS
ups = UPS(ups_config, debug=False)
#print(white_house)
#print(ups.validate(white_house))

#print(powells)
#r = ups.validate(powells)
#print r

ten_pound_box = Package(10.0 * 16, 12, 12, 12, value=100, require_signature=3, reference='a12302b')
our_packaging =  PACKAGES[0][0]