def test_wizard_from_config_file_obj(test_config_file): keys = {} keys["nick"] = {"type": "text"} keys["account_id"] = {"type": "text"} keys["server"] = {"type": "text"} keys["port"] = {"type": "text"} keys["password"] = {"type": "text"} keys["register"] = {"type": "text"} c = ConfigFile(test_config_file) c.set_valid_keys(keys) c.set("nick", "rgs") c.set("account_id", "rgs@andromeda") c.set("server", "andromeda") c.set("port", 5223) c.set("password", "97c74fa0dc3b39b8c87f119fa53cced2b7040786") c.set("register", True) c.save() c = ConfigFile(test_config_file) c.set_valid_keys(keys) c.load() config_w = ConfigWizard(test_config_file) config_items = [{ "item_label": "Nickname", "item_type": "text", "item_name": "nick" }, { "item_label": "Account ID", "item_type": "text", "item_name": "account_id" }, { "item_label": "Server", "item_type": "text", "item_name": "server" }, { "item_label": "Port", "item_type": "text", "item_name": "port" }, { "item_label": "Password", "item_type": "text", "item_name": "password" }, { "item_label": "Register", "item_type": "text", "item_name": "register" }] config_w.set_config_items(config_items) config_w.set_config_file_obj(c) config_w.show()
def show(self, read_from_disc=False): if read_from_disc: self._config_file_obj = ConfigFile(self._config_file_path) self._config_file_obj.set_valid_keys(self._valid_keys) self._config_file_obj.load() else: if self._config_file_obj is None: raise RuntimeError("I need the run time obj") self._config_popup = Gtk.Window() self._config_popup.set_default_size(200, 200) self._config_popup.connect('delete_event', self._close_config_cb) table = Gtk.Table(12, 1, True) self._config_popup.add(table) row = 1 for i in self._config_items: hbox = self._create_param(i) table.attach(hbox, 0, 1, row, row + 1, xpadding=5, ypadding=2) row = row + 1 hbox = Gtk.HBox() save_button = Gtk.Button.new_with_label('Save') save_button.set_size_request(50, 15) save_button.connect('pressed', self._save_config_cb) hbox.add(save_button) cancel_button = Gtk.Button.new_with_label('Cancel') cancel_button.set_size_request(50, 15) cancel_button.connect('pressed', self._close_config_cb) hbox.add(cancel_button) table.attach(hbox, 0, 1, row, row + 1, xpadding=5, ypadding=2) self._config_popup.show_all()
def main(): parse_conf = ConfigFile('config.cfg') parse_conf.read_config_file() if not parse_conf.username: username = raw_input('Enter your username: '******'Logging in as {}'.format(username) password = getpass('Enter your password: '******'folder title'] download_images = raw_input('Download images? (y = yes, defaults to no) ') if download_images.lower() == 'y': dtl.download_images = True else: dtl.download_images = False dtl.base_path = os.path.join(dtl.base_path, dtl.docs_folder) print 'File path to save to is: ' + dtl.base_path dtl.download_folder_contents(docs_folder_feed['folder feed']) utilfunc.check_for_tex_extension(dtl.base_path) dtl.cleanup_leftover_comments() comp_latex = CompileLaTeX(dtl.base_path) comp_latex.replace_quote_characters() main_latex_file = raw_input('Enter the name of the main LaTeX file: ') if main_latex_file: comp_latex.compile_to_latex(main_latex_file) else: print 'No file name entered.' if not parse_conf.config_exists(): config_saved = """\ Your username ({}) and chosen folder ({}) have been saved in {}""".format( username, dtl.docs_folder, os.path.join(dtl.base_path, 'config.cfg')) print textwrap.dedent(config_saved) parse_conf.write_config_file(username=username, folder_name=dtl.docs_folder)
def maintain(cliargs): # 'conf' must be imported by the subpackages, so assign it globally global conf conf = ConfigFile({ 'db_path': cliargs.db_path, 'init_env': str(cliargs.init_env), 'revise': str(cliargs.revise), 'migrate': str(cliargs.migrate), }) models, api, static = _pre_run(False) if conf.get_bool('init_env'): models.init_migrations() elif conf.get_bool('revise'): models.create_revision() elif conf.get_bool('migrate'): models.create_migration() else: raise ValueError("Unspecified maintenance command")
else: scan() return if not op.isdir("data"): os.mkdir("data") with utils.dirBongdi("data"): MY_PATH = os.getcwd() # op.dirname(__file__) TARGET_DIR = op.join(MY_PATH, REPO_NAME) CONFIG_FILE = op.join(MY_PATH, "configuration.do.not.edit") if op.isfile(CONFIG_FILE): pass # so that configFile can be made global else: print("Configuration file not found! Are you trying to setup?") if utils.replyIsYes(): utils.setup(TARGET_DIR, CONFIG_FILE) else: raise utils.UserCausedError("User refused to continue with setup") shutil.rmdir("data") configFile = ConfigFile(CONFIG_FILE, REPO_NAME) main()
from flask import Flask, send_file, make_response, redirect, request from ezmysql import TableDef from configfile import ConfigFile from requests import post as http_post CONFIG = ConfigFile('./itapps.cfg') DB_server = CONFIG.Get('DBServer') DB_user = CONFIG.Get('DBUser') DB_password = CONFIG.Get('DBPassword') TABLES = Config.Get('DBTables').split(',') # Configure table objects TABLES = [{"name" : a,"def" : TableDef(DB_server,DB_user,DB_password,a)} for a in TABLES] # Pull schema for thisTable in DB_tables: thisTable['schema'] = thisTable['def'].Schema() ROOT = '/var/www/python/dbedit' app = Flask(__name__) @app.route('/') def getroot(): return render_template('{}/templates/show_tables.html'.format(ROOT),tables=[a['name'] for a in DB_tables]) @app.routes('/<table>/list') def TableList(table): tableAr = [a for a in DB_tables if a['name'] == table] if len(tableAr) == 1:
'root': { 'level': 'INFO', 'handlers': ['wsgi'] } }) app = Flask(__name__) # Debug mode (development environment) app.debug = False debug_mode = False # Init modules app.config.from_object(Config) configfile = ConfigFile(app, 'main.cfg') csvreader = CSVReader(configfile.laser_etch_QC['PNFile']) db = SQLAlchemy(app) migrate = Migrate(app, db) login = LoginManager(app) login.login_view = 'login' socketio = SocketIO(app, manage_session=False) Session(app) # Serial setup # PLC serial plc_ser = None from flask_serial import Serial
def main_app(offline: bool): global_storage = GlobalStorage() sm = None aq = None ae = None if not offline: sm = SimConnect() aq = AircraftRequests(sm, _time=200) ae = AircraftEvents(sm) global_storage.set_aircraft_events(ae) global_storage.set_aircraft_requests(aq) else: global_storage.set_aircraft_events(MockAircraftEvents()) global_storage.set_aircraft_requests(MockAircraftRequests()) aircraft = aq.get('TITLE') print("Current aircraft:", aircraft) outport = mido.open_output('X-TOUCH MINI 1') # pylint: disable=no-member control_change_dict = {} note_dict = {} def handle_message(msg: mido.Message): # print(msg) if msg.type == 'control_change': if msg.control in control_change_dict: control_change_dict[msg.control].on_cc_data(msg.value) elif msg.type == 'note_on': if msg.note in note_dict: note_dict[msg.note].on_note_data(True) elif msg.type == 'note_off': if msg.note in note_dict: note_dict[msg.note].on_note_data(False) inport = mido.open_input('X-TOUCH MINI 0', callback=handle_message) # pylint: disable=no-member for e in range(1, 17): encoder = RotaryEncoder(e, outport) global_storage.add_encoder(encoder) for b in range(1, 33): btn = PushButton(b, outport) global_storage.add_button(btn) for f in range(1, 3): fader = Fader(f) global_storage.add_fader(fader) c = ConfigFile(aircraft) c.configure() triggers = c.triggers for encoder in GlobalStorage().encoders: control_change_dict[encoder.rotary_control_channel] = encoder note_dict[encoder.button_note] = encoder for btn in GlobalStorage().buttons: note_dict[btn.button_note] = btn for f in GlobalStorage().faders: control_change_dict[f.control_channel] = f triggers[0].on_simvar_data(1.0) while True: for obj in GlobalStorage().all_elements: if obj.bound_simvar and aq: sv = aq.get(obj.bound_simvar) obj.on_simvar_data(sv) current_aircraft = aq.get('TITLE') if current_aircraft and aircraft != current_aircraft: print("Aircraft changed from", aircraft, "to", current_aircraft) break time.sleep(0.05) global_storage.clear() inport.close() outport.close()
base_conf = ConfigFile( ( { 'host': 'localhost', 'port': '13502', 'proxy_url': '', 'origins': '', 'ssl_cert': '', 'ssl_key': '', 'workers': '1', 'force_development_server': 'false', 'db_path': os.path.join(datadir, 'db.sqlite'), 'client_conf': os.path.join(configdir, 'client.json'), 'user_script_dir': '/usr/share/wiki-monkey/' # No need to support 'debug' in the configuration file }, { 'archwiki': ( { 'origins': 'https://wiki.archlinux.org', }, {}, ), 'wikipedia': ( { 'origins': 'https://en.wikipedia.org', }, {}, ), }, ), inherit_options=True, )
def setUp(self): # 创建对象 config_dir = os.path.abspath( os.path.join(os.path.dirname(__file__), 'files')) self.configfile = ConfigFile(config_dir)
def _openConfig(self, path): return ConfigFile(path, self.CONF_VERSION)
# -*- coding: utf-8 -*- # Author: Ztj import logging import logging.config import os from configfile import ConfigFile from registry import Registry from libs.logger import JsonLogger """全局设置""" logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') """全局变量""" service_root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) """初始化配置""" GlobalConfigFile = ConfigFile(os.path.join(service_root_path, 'configs')) """加载配置文件""" app_options = Registry(GlobalConfigFile.load_app('app')) """配置日志""" log_options = GlobalConfigFile.load_app('log') if log_options is not None: logging.setLoggerClass(JsonLogger) logging.config.dictConfig(log_options) json_logger = logging.getLogger('json')