def start(bot, update): """/start command""" lang = update.effective_user.language_code bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.TYPING) reg_status = DBWorker.get_reg_status(update.message.chat_id) if reg_status == RegStatus.NO_ROOM: update.message.reply_text( ParseConfig.get_conversations(lang, 'registration', 'no_room')) return ROOM elif reg_status == RegStatus.COMPLETE: update.message.reply_text( ParseConfig.get_conversations(lang, 'registration', 'already_registered')) return ConversationHandler.END phone_btn = KeyboardButton(text=ParseConfig.get_reg_btn( lang, 'share_phone_number'), request_contact=True) keyboard = ReplyKeyboardMarkup([[phone_btn]], one_time_keyboard=True) update.message.reply_text(ParseConfig.get_conversations( lang, 'registration', 'need_phone_number'), reply_markup=keyboard) return PHONE
def main_menu(bot, update): """Show main menu""" bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.TYPING) lang = update.effective_user.language_code LOGGER.info(lang) if DBWorker.get_reg_status(update.message.chat_id) != RegStatus.COMPLETE: update.message.reply_text( ParseConfig.get_conversations(lang, 'main', 'uncomplete_registration')) return ConversationHandler.END change_room_btn = KeyboardButton( text=ParseConfig.get_main_menu_btn(lang, 'change_room')) send_complaint_btn = KeyboardButton( text=ParseConfig.get_main_menu_btn(lang, 'send_complaint')) change_status_btn = KeyboardButton( text=ParseConfig.get_main_menu_btn(lang, 'change_status')) keyboard = ReplyKeyboardMarkup( [[change_room_btn, send_complaint_btn], [change_status_btn]], one_time_keyboard=True) update.message.reply_text(ParseConfig.get_conversations( lang, 'main', 'main_menu'), reply_markup=keyboard) return MAIN_MENU
def main(argv): # define some defaults configFile = scriptPath + '/../etc/config.xml' # parse the command line arguments try: opts, args = getopt.getopt(argv, "hf:n:", ['help', 'fields=', 'name']) except getopt.GetoptError: sys.exit(2) field = 'status,address,speed' name = '' # override defaults based on command line arguments for opt, arg in opts: if opt in ('-h', '--help'): usage() sys.exit() elif opt == '-f': field = arg elif opt == '-n': name = arg # load up the configs Config = ParseConfig.parseConfig(configFile); fields = field.split(','); getData(Config, fields)
def phone(bot, update): """Get user phone""" lang = update.effective_user.language_code bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.TYPING) chat_id = update.message.chat_id phone_number = update.message.contact.phone_number LOGGER.info('New user: '******' | ' + str(phone_number)) phone_number = re.sub('[()+-]', '', phone_number) DBWorker.reg_user(chat_id, phone_number) LOGGER.info('User was registered: ' + str(chat_id) + ' | ' + str(phone_number)) update.message.reply_text(ParseConfig.get_conversations( lang, 'registration', 'get_room_number'), reply_markup=ReplyKeyboardRemove()) return ROOM
def main_menu_update_room(bot, update): """Update room number from main menu""" bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.TYPING) lang = update.effective_user.language_code if not DBWorker.update_room(update.message.chat_id, update.message.text): update.message.reply_text( ParseConfig.get_conversations(lang, 'main', 'incorrect_room_number')) return UPDATE_ROOM update.message.reply_text( ParseConfig.get_conversations(lang, 'main', 'changed_room_number')) return MAIN_MENU
def main(argv): # define some defaults configFile = scriptPath + '/../etc/config.xml' # parse the command line arguments try: opts, args = getopt.getopt(argv, "hf:n:", ['help', 'fields=', 'name']) except getopt.GetoptError: sys.exit(2) field = 'status,address,speed' name = '' # override defaults based on command line arguments for opt, arg in opts: if opt in ('-h', '--help'): usage() sys.exit() elif opt == '-f': field = arg elif opt == '-n': name = arg # load up the configs Config = ParseConfig.parseConfig(configFile) fields = field.split(',') getData(Config, fields)
def help(bot, update): """Show help information""" bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.TYPING) lang = update.effective_user.language_code update.message.reply_text(ParseConfig.get_conversations(lang, 'help'))
def _parseModel(self): fp = open(self.conf, 'r') data = fp.readlines() fp.close() p = ParseConfig(data) p.showDict() config = p.getDict() self.proj_str = config['proj_str'] tokens = config['proj_origin'].split(',') self.origin = [float(tokens[0]), float(tokens[1])] self.rot = float(config['proj_rot']) tokens = config['proj_size'].split(',') self.size = [float(tokens[0]), float(tokens[1])] self.spacing = float(config['spacing']) return (0)
def main(): """Start bot""" token = ParseConfig.get_token() port = int(os.environ.get('PORT', '5000')) updater = Updater(token) dpt = updater.dispatcher reg_conv_handler = ConversationHandler( entry_points=[CommandHandler('start', start)], states={ PHONE: [MessageHandler(Filters.contact, phone)], ROOM: [MessageHandler(Filters.text, room)] }, fallbacks=[CommandHandler('start', start)]) main_conv_handler = ConversationHandler( entry_points=[CommandHandler('main', main_menu)], states={ MAIN_MENU: [MessageHandler(Filters.text, main_menu_handler)], UPDATE_ROOM: [MessageHandler(Filters.text, main_menu_update_room)], COMPLAINT: [MessageHandler(Filters.text, add_complaint)], CHANGE_STATUS: [MessageHandler(Filters.text, change_room_status)] }, fallbacks=[CommandHandler('main', main_menu)]) dpt.add_handler(reg_conv_handler) dpt.add_handler(main_conv_handler) dpt.add_handler(CommandHandler('help', help)) dpt.add_error_handler(error) env = ParseConfig.get_env() if env == 'prod': LOGGER.info('------Production environment------') updater.start_webhook(listen="0.0.0.0", port=port, url_path=token) updater.bot.set_webhook('https://' + ParseConfig.get_url() + '.herokuapp.com/' + token) elif env == 'dev': LOGGER.info('------Development environment------') updater.start_polling() else: LOGGER.info('------Unkonwn environment------') updater.idle()
def room(bot, update): """Register user room""" lang = update.effective_user.language_code bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.TYPING) if not DBWorker.update_room(update.message.chat_id, update.message.text): update.message.reply_text( ParseConfig.get_conversations(lang, 'registration', 'incorrect_room_number')) return ROOM update.message.reply_text( ParseConfig.get_conversations(lang, 'registration', 'finished_registration')) return ConversationHandler.END
def run(self,configfile,register=False,verbose=False): self.cwd = os.getcwd() self.ph = Plugin.plghandler(self) self.configfile = configfile self.config = ParseConfig.readconfigfile(configfile) self.admins = ParseConfig.parselist(self.config["admins"],",") self.verbose = verbose self.tasclient = Client.tasclient(self) for p in ParseConfig.parselist(self.config["plugins"],","): self.ph.addplugin(p,self.tasclient) self.tasclient.events.onconnected = self.Dologin self.tasclient.events.onloggedin = self.onlogin self.reg = register notice("Connecting to %s:%i" % (self.config["serveraddr"],int(self.config["serverport"]))) self.tasclient.connect(self.config["serveraddr"],int(self.config["serverport"]))
def add_complaint(bot, update): """Add complaint""" bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.TYPING) lang = update.effective_user.language_code DBWorker.add_complaint(update.message.chat_id, update.message.text) update.message.reply_text( ParseConfig.get_conversations(lang, 'main', 'added_complaint')) return MAIN_MENU
def change_room_status(bot, update): """Change room status""" lang = update.effective_user.language_code bot.send_chat_action(chat_id=update.message.chat_id, action=ChatAction.TYPING) DBWorker.change_room_status(DBWorker.get_room(update.message.chat_id), update.message.text) update.message.reply_text( ParseConfig.get_conversations(lang, 'main', 'status_successfully_changed')) return MAIN_MENU
def loadConfs(self): configs = ParseConfig.ParseConfig(self.USER_CONFIG_FILE) if not configs.parse() or configs.isEmpty() or not configs.isValid(): return False configs = configs.getContent() logger.log( logging.INFO, "Config file for user '{}' found and valid".format(self.USER_NAME)) for name in configs: if configs[name]["enable"]: currentContainerPath = self.USER_ROOT_FOLDER + name self.containers.append( Container(name, configs[name], LUKSDevice.LUKSDevice(currentContainerPath))) return True
def main_menu_handler(bot, update): """Main menu buttons handler""" cmd = update.message.text lang = update.effective_user.language_code if cmd == ParseConfig.get_main_menu_btn(lang, 'change_room'): update.message.reply_text( ParseConfig.get_conversations(lang, 'main', 'get_room_number')) return ROOM elif cmd == ParseConfig.get_main_menu_btn(lang, 'send_complaint'): update.message.reply_text( ParseConfig.get_conversations(lang, 'main', 'get_complaint')) return COMPLAINT elif cmd == ParseConfig.get_main_menu_btn(lang, 'change_status'): update.message.reply_text( ParseConfig.get_conversations(lang, 'main', 'get_room_status')) return CHANGE_STATUS
import wrap import sys, os import datetime sys.path.append(os.getcwd()) import ParseConfig reload(ParseConfig) print "Select config file" configFile = wrap.openFileDialog("Select config file", filter="Text Files (*.txt)") print "Config file is '%s'" % configFile tasks = ParseConfig.parseConfig(configFile, 'DefaultSettings_2_Wrapping.txt') tasksCount = len(tasks) for taskNum, task in enumerate(tasks): print "Task %d of %d" % (taskNum + 1, tasksCount) print "Loading scan '%s'..." % task['scanFileName'] scan = wrap.Geom(task['scanFileName'], fitToView=False) scan.wireframe = False scaleFactor = 100.0 / scan.boundingBoxSize[0] scan.scale(scaleFactor) wrap.fitToView() print "OK" if 'textureFileName' in task: print "Loading texture '%s'" % task['textureFileName'] scan.texture = wrap.Image(task['textureFileName']) print "OK"
def main(): pid = os.getpid() logFile = '/tmp/backend-%d.log' % pid debug = 1 # define some defaults configFile = scriptPath + '/../etc/config.xml' # load up the configs Config = ParseConfig.parseConfig(configFile) # setup the logger if (debug): logger.setLevel(logging.DEBUG) else: logger.setLevel(logging.INFO) ch = logging.handlers.RotatingFileHandler(logFile, maxBytes=25000000, backupCount=5) if (debug): ch.setLevel(logging.DEBUG) else: ch.setLevel(logging.INFO) formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") ch.setFormatter(formatter) logger.addHandler(ch) # and fire up the logger logger.info('startup') first_time = True db = TimeSeries(Config) # here, we have to deal with how to talk to PowerDNS. while 1: # loop forever reading from PowerDNS rawline = sys.stdin.readline() if rawline == '': logger.debug('EOF') return # EOF detected line = rawline.rstrip() logger.debug('received from pdns:%s' % line) # If this is the first pass reading from PowerDNS, look for a HELO if first_time: if line == 'HELO\t1': fprint('OK\togslb backend firing up') else: fprint('FAIL') logger.debug('HELO input not received - execution aborted') rawline = sys.stdin.readline( ) # as per docs - read another line before aborting logger.debug('calling sys.exit()') sys.exit(1) first_time = False else: # now we actually get busy query = line.split('\t') if len(query) != 6: # fprint('LOG\tPowerDNS sent unparseable line') # fprint('FAIL') fprint('END') else: logger.debug('Performing DNSLookup(%s)' % repr(query)) lookup = '' # Here, we actually to the real work. Lookup a hostname in redis and prioritize it lookup = DNSLookup(db, query) if lookup != '': logger.debug(lookup) fprint(lookup) fprint('END')
import wrap import sys, os sys.path.append(os.getcwd()) import ParseConfig reload(ParseConfig) print "Select config file" configFile = wrap.openFileDialog("Select config file", filter="Text Files (*.txt)") print "Config file is '%s'" % configFile tasks = ParseConfig.parseConfig(configFile) basemesh = None scan = None for taskNum, task in enumerate(tasks): if basemesh: del basemesh if scan: del scan wrap.fitToView() print "Task %d of %d" % (taskNum + 1, len(tasks)) print "Loading scan '%s'..." % task['scanFileName'] scan = wrap.Geom(task['scanFileName'], fitToView=False) scan.wireframe = False scaleFactor = 100.0 / scan.boundingBoxSize[0] scan.scale(scaleFactor) wrap.fitToView() print "OK"
def main(): pid = os.getpid() logFile = "/tmp/backend-%d.log" % pid debug = 1 # define some defaults configFile = scriptPath + "/../etc/config.xml" # load up the configs Config = ParseConfig.parseConfig(configFile) # setup the logger if debug: logger.setLevel(logging.DEBUG) else: logger.setLevel(logging.INFO) ch = logging.handlers.RotatingFileHandler(logFile, maxBytes=25000000, backupCount=5) if debug: ch.setLevel(logging.DEBUG) else: ch.setLevel(logging.INFO) formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") ch.setFormatter(formatter) logger.addHandler(ch) # and fire up the logger logger.info("startup") first_time = True db = TimeSeries(Config) # here, we have to deal with how to talk to PowerDNS. while 1: # loop forever reading from PowerDNS rawline = sys.stdin.readline() if rawline == "": logger.debug("EOF") return # EOF detected line = rawline.rstrip() logger.debug("received from pdns:%s" % line) # If this is the first pass reading from PowerDNS, look for a HELO if first_time: if line == "HELO\t1": fprint("OK\togslb backend firing up") else: fprint("FAIL") logger.debug("HELO input not received - execution aborted") rawline = sys.stdin.readline() # as per docs - read another line before aborting logger.debug("calling sys.exit()") sys.exit(1) first_time = False else: # now we actually get busy query = line.split("\t") if len(query) != 6: # fprint('LOG\tPowerDNS sent unparseable line') # fprint('FAIL') fprint("END") else: logger.debug("Performing DNSLookup(%s)" % repr(query)) lookup = "" # Here, we actually to the real work. Lookup a hostname in redis and prioritize it lookup = DNSLookup(db, query) if lookup != "": logger.debug(lookup) fprint(lookup) fprint("END")
import wrap import sys,os sys.path.append(os.getcwd()) import ParseConfig; reload(ParseConfig) print "Select config file" configFile = wrap.openFileDialog("Select config file",filter="Text Files (*.txt)") print "Config file is '%s'" % configFile tasks = ParseConfig.parseConfig(configFile, "DefaultSettings_3_PostProcessing.txt") for taskNum, task in enumerate(tasks): if 'wrapped' in locals(): del wrapped if 'scan' in locals(): del scan print "Task %d of %d" % (taskNum + 1, len(tasks)) print "Loading scan '%s'..." % task['scanFileName'] scan = wrap.Geom(task['scanFileName'], fitToView = False) scan.wireframe = False scaleFactor = 100.0 / scan.boundingBoxSize[0] scan.scale(scaleFactor) wrap.fitToView() print "OK" if 'textureFileName' in task: print "Loading texture '%s'" % task['textureFileName'] scan.texture = wrap.Image(task['textureFileName']) print "OK" else:
import wrap import sys, os sys.path.append(os.getcwd()) import ParseConfig reload(ParseConfig) print "Select config file" configFile = wrap.openFileDialog("Select config file", filter="Text Files (*.txt)") print "Config file is '%s'" % configFile tasks = ParseConfig.parseConfig(configFile, "DefaultSettings_3_PostProcessing.txt") for taskNum, task in enumerate(tasks): if 'wrapped' in locals(): del wrapped if 'scan' in locals(): del scan print "Task %d of %d" % (taskNum + 1, len(tasks)) print "Loading scan '%s'..." % task['scanFileName'] scan = wrap.Geom(task['scanFileName'], fitToView=False) scan.wireframe = False scaleFactor = 100.0 / scan.boundingBoxSize[0] scan.scale(scaleFactor) wrap.fitToView() print "OK" if 'textureFileName' in task: print "Loading texture '%s'" % task['textureFileName']
def ReloadConfig(self): self.config = ParseConfig.readconfigfile(self.configfile) self.admins = ParseConfig.parselist(self.config["admins"],",")
def SaveConfig(self): ParseConfig.writeconfigfile(self.configfile,self.config)
# -*- coding: utf-8 -*- from customlog import Log from jinja2 import Environment, FileSystemLoader import ParseConfig from ladderdb import LadderDB from beaker.cache import CacheManager from beaker.util import parse_cache_config_options cache_opts = { 'cache.type': 'memory', 'cache.data_dir': 'tmp/cache/data', 'cache.lock_dir': 'tmp/cache/lock' } config = ParseConfig.readconfigfile( 'Main.conf' ) Log.Init( 'website.log', 'website.log' ) db = LadderDB(config['alchemy-uri']) env = Environment(loader=FileSystemLoader('templates')) staging = 'staging' in config.keys() cache = CacheManager(**parse_cache_config_options(cache_opts))
import wrap import sys,os sys.path.append(os.getcwd()) import ParseConfig; reload(ParseConfig) print "Select config file" configFile = wrap.openFileDialog("Select config file",filter="Text Files (*.txt)") print "Config file is '%s'" % configFile tasks = ParseConfig.parseConfig(configFile) taskNum = 0 while True: task = tasks[taskNum] print "Task %d of %d" % (taskNum + 1, len(tasks)) print "Loading scan '%s'..." % task['scanFileName'] scan = wrap.Geom(task['scanFileName'], fitToView = False) scan.wireframe = False scaleFactor = 100.0 / scan.boundingBoxSize[0] scan.scale(scaleFactor) wrap.fitToView() print "OK" if 'textureFileName' in task: print "Loading texture '%s'" % task['textureFileName'] scan.texture = wrap.Image(task['textureFileName']) print "OK"
import wrap import sys,os import datetime sys.path.append(os.getcwd()) import ParseConfig; reload(ParseConfig) print "Select config file" configFile = wrap.openFileDialog("Select config file",filter="Text Files (*.txt)") print "Config file is '%s'" % configFile tasks = ParseConfig.parseConfig(configFile, 'DefaultSettings_2_Wrapping.txt') tasksCount = len(tasks) for taskNum, task in enumerate(tasks): print "Task %d of %d" % (taskNum + 1, tasksCount) print "Loading scan '%s'..." % task['scanFileName'] scan = wrap.Geom(task['scanFileName'], fitToView = False) scan.wireframe = False scaleFactor = 100.0 / scan.boundingBoxSize[0] scan.scale(scaleFactor) wrap.fitToView() print "OK" if 'textureFileName' in task: print "Loading texture '%s'" % task['textureFileName'] scan.texture = wrap.Image(task['textureFileName']) print "OK" else: print "No texture found"