def testConfig(self): logger.debug('-'*26 + '\n') logger.info('Running simple configuration test...') import config config.check() config.reload() configdata = str(config.get_config()) config.set('testval', 1337) if not config.get('testval', None) is 1337: self.assertTrue(False) config.set('testval') if not config.get('testval', None) is None: self.assertTrue(False) config.save() config.reload() if not str(config.get_config()) == configdata: self.assertTrue(False) self.assertTrue(True)
def setUp(self): yaml_file = os.path.join(os.path.dirname(__file__), '..', '..', 'config.yml') config.load(yaml_file) config.bootstrap(['-vv']) # make sure we're not mocking out google reader app_globals.OPTIONS['test'] = False config.parse_options(['--output-path=/tmp/gris-test', '--num-items=1']) config.check() self.reader = app_globals.READER = Reader()
def setup(opts=None): """Parse options. If none given, opts is set to sys.argv""" if opts is None: opts = sys.argv[1:] config.bootstrap(opts) config.load() config.parse_options(opts) ensure_dir_exists(app_globals.OPTIONS['output_path']) log_start() if app_globals.OPTIONS['report_pid']: proctl.report_pid() exit(0) config.check() proctl.ensure_singleton_process() init_signals()
def create_application(): global app, db, UserManager if not config.check(): return None if not os.path.exists(config.get('base', 'cache_dir')): os.makedirs(config.get('base', 'cache_dir')) import db db.init_db() app = Flask(__name__) app.secret_key = '?9huDM\\H' if config.get('base', 'log_file'): import logging from logging.handlers import TimedRotatingFileHandler handler = TimedRotatingFileHandler(config.get('base', 'log_file'), when = 'midnight') handler.setLevel(logging.WARNING) app.logger.addHandler(handler) app.teardown_request(teardown) import frontend import api return app
def command_line(): if not config.check(): sys.exit(1) db.init_db() if len(sys.argv) > 1: CLI().onecmd(' '.join(sys.argv[1:])) else: CLI().cmdloop()
def start_standalone_server(host=None, port=None, debug=True): if not config.check(): sys.exit(1) if not os.path.exists(config.get('base', 'cache_dir')): os.makedirs(config.get('base', 'cache_dir')) import db from web import app db.init_db() app.run(host=host, port=port, debug=debug)
def play_ruzzle(frame, how_many, longest_first): # excluding words that contain letters not present in game frame words = [word for word in WORDS if set(word).issubset(flat_frame)] # sorting by length of the word words = sorted(words, key=len, reverse=True) # looping through word list results = {} for word in words: # find all potential starting cells for that word in current frame starts = [c for c in frame.frame if c.letter == word[0]] # check for each start point if word can be traced tries = [check(word, start, 1, {}, []) for start in starts] # listing solutions and picking a random one found = [t for t in tries if t] if found: solution = random.choice(found) solve = [] # press a random point of each cell touched to draw the word # this is done to dissimulate that the player is a bot for cell in solution: cell.real_x = random.randint(cell.gui["xmin"], cell.gui["xmax"]) cell.real_y = random.randint(cell.gui["ymin"], cell.gui["ymax"]) solve.append(cell) results[word] = solve # bring focus on emulator window by clicking on it pyautogui.moveTo(532, 63) pyautogui.click() word_list = list(results.items()) if longest_first.upper() == "Y": random.shuffle(word_list) results = dict(word_list) # draw the words counter = 0 for word, eureka in results.items(): if counter < how_many: print(counter, word) draw_word(eureka) counter += 1 else: break
def compare_exports(tmp_path, get_files, cfg_toml, name, addline=False): """ Compares exports to $System.OBJ.ExportUDL. """ # First retrieve the data using copy-iris-items get_files(cfg_toml, tmp_path) expect = [name] got = list_files(join(tmp_path, 'src')) # Make sure we retrieved the right item assert expect == got, f"Should get {expect}, got {got}" # Get the export data with open(join(tmp_path, 'src', name), 'rt', encoding="UTF-8") as f: data_from_api = f.read() # Add a line to the copy-iris-items export, if so requested. This # should remove the difference, created by a backward-compatibility # setting, with the data retrieved below. if addline: data_from_api += '\n' # Convert config toml string to get at server properties. Set # defaults by calling the regular config check method. cfg_ns = ns.dict2ns(toml.loads(cfg_toml)) config.check(cfg_ns) # Get data from $System.OBJ.ExportUDL() data_from_export = get_export(cfg_ns.Server, name) # Save for debugging purposes if data_from_api != data_from_export: with open(join(tmp_path, 'src', name + '2'), 'wt', encoding="UTF-8") as f: f.write(data_from_export) assert data_from_api == data_from_export, "Both methods should return the same data"
def run(self): Lista = self.entry_box.get("1.0", "end").split("\n") while True: try: Lista.remove("") except ValueError: break if len(Lista) > 0: try: requests.get("https://google.com") except: self._Log.configure(text="Check Your Network", fg='red') return False self._Log.configure(text="Log : All Is Good :)", fg='white') self.result_box.delete("1.0", "end") LIVE = 0 DIE = 0 UNKNOWN = 0 for mail in Lista: res = config.check(mail) soup = BeautifulSoup(res, features="html.parser").findAll( 'div', {'class': 'success valid'}) if len(soup) > 0: self.result_box.configure(state='normal') self.result_box.insert('end', "{}\n".format(mail), 'YES') self.result_box.configure(state='disabled') LIVE += 1 self.tl.configure(text=f"LIVE : {LIVE}") else: self.result_box.configure(state='normal') self.result_box.insert('end', "{}\n".format(mail), 'NO') self.result_box.configure(state='disabled') DIE += 1 self.td.configure(text=f"DIE : {DIE}") else: self._Log.configure(text="Insert Your Mail list in The entry box", fg='red')
def cli(username, password): """The taiga command interface.""" if config.check(): api.auth(username=username, password=password) else: exit()
def checkConf(): return( config.check() )
# coding: utf-8 import config import os.path, sys if __name__ == '__main__': if not config.check(): sys.exit(1) if not os.path.exists(config.get('base', 'cache_dir')): os.makedirs(config.get('base', 'cache_dir')) import db from web import app db.init_db() app.run(host = '0.0.0.0', debug = True)
help="mail you want to check", default=None) parser.add_argument('-ml', '--maillist', required=False, help="Path to mail list you want to check", default=None) args = parser.parse_args() if __name__ == "__main__": if args.mail: try: requests.get("https://google.com") except: print("Check Your Network") sys.exit(1) res = config.check(args.mail) soup = BeautifulSoup(res, features="html.parser").findAll( 'div', {'class': 'success valid'}) if len(soup) > 0: print(fg("#00FF00") + soup[0].text + attr("reset")) else: print("{1}{0} Not Valid{2}".format(args.mail, fg("#f00"), attr("reset"))) elif args.maillist: if config.file_get_contents(args.maillist): Lista = config.file_get_contents(args.maillist).split("\n") try: requests.get("https://google.com") except: print("Check Your Network") sys.exit(1)
def run(self,d): assert type(d)==dict ntime = d['time'][0] # d['time'][1]-= 31*24*60*60 ttime = d['time'][1] stime = time2data(ttime) for table in self.tables(): if table=='empresa': a,e = self.select(table) empresa = e[0][0] if empresa is None: continue r = config.check('Site','name',empresa.encode('UTF-8'),True) r = config.check('Report','title',empresa.encode('UTF-8')) d[table] = empresa elif table in ['modulo_io_cfg']: a,e = self.select(table) d[table] = [dict(zip(a,q)) for q in e] elif table == 'instrumentos': a,e = self.select(table) dd = dict([[q[0],dict(translate(zip(a[1:],q[1:])))] for q in e]) d[table] = dd [config.check('Site','instrument-{}'.format(x),dd[x]['description'].encode('UTF-8'),True) for x in dd.keys()] [config.check('Figure {}'.format(x),'description',dd[x]['description'].encode('UTF-8')) for x in dd.keys()] for x in dd.keys(): for k in dd[x].keys(): if k in ['status','date','model']: config.check('Instrument {}'.format(x), k, dd[x][k]) elif k=='description': config.check('Instrument {}'.format(x), k, dd[x][k].encode('UTF-8')) config.checklist('Report','figures',['Figure {}'.format(x) for x in dd.keys()]) elif table=='rel_alarmes': a,e = self.select(table,where="dataInicio>{0} OR dataFim>{0}".format(stime)) dd = [dict(zip(a,q)) for q in e] d[table] = dd larms = {} for l in e: if l[0] not in larms.keys(): larms[l[0]] = set() larms[l[0]].add(l[1].encode('utf8')) z = [config.checklist('Instrument {}'.format(x), 'alarms', larms[x]) for x in larms.keys()] else: u,v = self.query('SELECT id,COUNT(*) AS n FROM {} WHERE data>{} GROUP BY id;'.format(table,stime)) if not len(v): continue for i,n in v: d['data'][i] = {} d['keys'][i] = [] inst = 'Instrument {}'.format(i) config.check(inst, 'type', table) txfrms = config.checklist(inst, 'transform',[]) or []; a,e = self.select(table,limit=n,where="data>{0} AND id={1}".format(stime,i),order='data') g = a.index('data') common, flags, keys = [], [], {} j = 0 for x in a: y = translate(x) keys[y] = (j,x) if y in ['temperature', 'VoltR', 'humidity', 'temp_dry', 'temp_wet', 'tension']: common.append(y) else: flags.append(y) j+= 1 meters = config.checklist(table, 'meters', common) or []; config.checklist(table, 'flags', flags); for j in range(len(meters)): txf = txfrms and txfrms[j] or None met = meters[j] d['data'][i][met] = [(q[g],translatev(keys[met][1],q[keys[met][0]],txf)) for q in e] d['keys'][i].append(met) config.checklist('Instrument {}'.format(i), 'meters', meters, True) ii = ';\n{:03}.'.format(i) config.check('Figure {}'.format(i), 'meters', ii[2:]+ii.join(common)) return d