def __init__(self, configdir=None): self.configdir = configdir if not self.configdir: self.configdir = get_config_dir() self.statusfile = os.path.join(self.configdir, statfile) self.status = configparser() self.status.read(self.statusfile)
def __init__(self): global pid bus_name = dbus.service.BusName('org.polaris.service', bus=dbus.SessionBus()) dbus.service.Object.__init__(self, bus_name, '/org/polaris/service') from ConfigParser import RawConfigParser as configparser import wnck config = configparser() config.readfp(open(os.path.expanduser("~/.polarisrc"))) self.DZEN2_OPTS = config.get("General", "dzen2_opts") self.WORKSPACES_NFG = config.get("Workspaces", "normal_fg") self.WORKSPACES_NBG = config.get("Workspaces", "normal_bg") self.WORKSPACES_AFG = config.get("Workspaces", "active_fg") self.WORKSPACES_ABG = config.get("Workspaces", "active_bg") self.TASKS_NFG = config.get("Tasks", "normal_fg") self.TASKS_NBG = config.get("Tasks", "normal_bg") self.TASKS_AFG = config.get("Tasks", "active_fg") self.TASKS_ABG = config.get("Tasks", "active_bg") self.TASKS_IFG = config.get("Tasks", "iconiz_fg") self.TASKS_IBG = config.get("Tasks", "iconiz_bg") self.CLOCK_FG = config.get("Clock", "clock_fg") self.CLOCK_FORMAT = config.get("Clock", "strftime") dzen2_invocation = ["/usr/bin/dzen2", "-p"] dzen2_invocation.extend(self.DZEN2_OPTS.split()) self.dzen2_pipe = subprocess.Popen(dzen2_invocation, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, close_fds=True) pid = self.dzen2_pipe.pid #gobject.timeout_add(100, self.is_dzen2_running) self.screen = wnck.screen_get_default() self.screen.force_update() self.screen.connect("active-workspace-changed", self.get_workspaces) self.screen.connect("workspace-created", self.get_workspaces) self.screen.connect("workspace-destroyed", self.get_workspaces) self.screen.connect("active-window-changed", self.get_windows) self.screen.connect("window-opened", self.get_windows) self.screen.connect("window-closed", self.get_windows) self.screen.connect self.last_event = 0 self.get_workspaces() self.get_windows() self.get_time() self.output_dzen_line() gobject.timeout_add(10000, self.get_time)
def load_config(path): # Load and parse required config file try: config = configparser() config.optionxform = str if len(config.read(path)) != 1: raise IOError except StandardError: # Either couldn't read/find the file, or couldn't parse it. print "Warning! Could not load %s" % (path,) raise ImportError else: return config
def load_config(path): # Load and parse required config file try: config = configparser() config.optionxform = str if len(config.read(path)) != 1: raise IOError except StandardError: # Either couldn't read/find the file, or couldn't parse it. print "Warning! Could not load %s" % (path, ) raise ImportError else: return config
def create_dumb_file(): config_parser = configparser() config_parser.add_section(SECTION_NAME) for option, dumb_value in zip(OPTIONS, DUMB_OPTIONS_VALUES): config_parser.set(SECTION_NAME, option, dumb_value) directory_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../' + CREDENTIALS_FOLDER_NAME) if not os.path.exists(directory_path): os.makedirs(directory_path) with open(get_dumb_path(), 'w') as dumb_file: config_parser.write(dumb_file)
def configure(self, configFile): """Caller passes a config file. Method modifies database connection and DQS directory attributes values from initial Nones. Provides CAOM database configuration ('x.config') and defaults ('x.defaults') files, found respectively under DQS/CONFIG, DQS/DEFAULTS. Caller picks appropos file. parameters: <string>, mddb config file, default 'mddb.cfg' return: <void>, configured instance attributes """ conf = configparser() conf.read(configFile) self.configFile = configFile self.CONFIG = conf.get('dqs_dirs','config') self.DATASETS = conf.get('dqs_dirs','datasets') self.HEADERS = conf.get('dqs_dirs','header') self.OVERRIDE = conf.get('dqs_dirs','override') self.VALIDATE = conf.get('dqs_dirs','validate') self.logs = conf.get('dqs_dirs','logs') self.scripts = conf.get('dqs_dirs','scripts') self.server = conf.get('database','server') self.database = conf.get('database','database') self.schema = conf.get('database','schema') self.collection = conf.get('database','collection') self.executable = conf.get('execute','executable') # Providing CAOM configuration ('.config') and defaults ('.defaults') # files, found respectively under DQS/CONFIG, DQS/DEFAULTS. self.cimageDBConfig = conf.get('configs','cimageconfig') self.cimage2dDBConfig = conf.get('configs','cimage2dconfig') self.cimage3dDBConfig = conf.get('configs','cimage3dconfig') self.fitsDBConfig = conf.get('configs','fitsconfig') self.fits2dDBConfig = conf.get('configs','fits2dconfig') self.fits3dDBConfig = conf.get('configs','fits3dconfig') self.uvfitsDBConfig = conf.get('configs','uvfitsconfig') self.uvmsDBConfig = conf.get('configs','uvmsconfig') self.fitsDBDefault = conf.get('config_defaults','fitsdefault') self.uvfitsDBDefault = conf.get('config_defaults','uvfitsdefault') self.cimageDBDefault = conf.get('config_defaults','cimagedefault') self.uvmsDBDefault = conf.get('config_defaults','uvmsdefault') return
def read(filename='constants.ini', constants_file=None): '''Read a constants ini file and return the constants helper object. When added to the page_options config, these constants can be used inside the templates where the section/data of the constants ini is dereferenced using constants.SECTION.KEY. ''' config = configparser() if constants_file: config.readfp(constants_file) else: config.read(filename) constants = namedtuple("Constant", config.sections())._make([ namedtuple('Field', dict(config.items(section)).keys() )._make(dict(config.items(section)).values()) for section in config.sections() ]) return constants
def read(filename='constants.ini', constants_file=None): '''Read a constants ini file and return the constants helper object. When added to the page_options config, these constants can be used inside the templates where the section/data of the constants ini is dereferenced using constants.SECTION.KEY. ''' config = configparser() if constants_file: config.readfp(constants_file) else: config.read(filename) constants = namedtuple("Constant", config.sections())._make([ namedtuple('Field', dict(config.items(section)).keys())._make( dict(config.items(section)).values()) for section in config.sections() ]) return constants
def __cmdSwitches(self,cmd): """Extend command line with boolean switches in config file. The verbose switch for fits2caom appears to be unique as the only short option available, hence a single '-' opt. """ boolOpts = 'switches' conf = configparser() conf.read(self.mddb_env.configFile) opts = conf.options(boolOpts) for opt in opts: try: assert conf.getboolean(boolOpts,opt) if opt == 'verbose': cmd.extend(['-v']) else: cmd.extend(['--'+opt]) except AssertionError: pass except ValueError: pass except NoOptionError: pass return cmd
def __init__(self, custom_config_path=None): xdg_config_dir = os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")) xdg_config_path = os.path.join(xdg_config_dir, 'indimpc/indimpc.rc') if custom_config_path: self.config_path = custom_config_path elif os.path.isfile(xdg_config_path): self.config_path = xdg_config_path self.config_parser = configparser() if self.config_path: self.config_parser.read(self.config_path) else: self.config_path = xdg_config_path if self.config_parser.has_section("General"): self.general_grab_keys = self.config_parser.getboolean("General", "grab_keys") else: self.general_grab_keys = True if self.config_parser.has_section("MPD"): self.mpd_host = self.config_parser.get("MPD", "host") self.mpd_port = self.config_parser.getint("MPD", "port") self.mpd_password = self.config_parser.get("MPD", "password") else: env_host = os.environ.get("MPD_HOST", "localhost") if "@" in env_host: self.mpd_password, self.mpd_host = env_host.split("@", 1) else: self.mpd_password, self.mpd_host = None, env_host env_port = os.environ.get("MPD_PORT", 6600) self.mpd_port = int(env_port) if self.config_parser.has_section("Client"): self.client_name = self.config_parser.get("Client", "name") self.client_mode = self.config_parser.get("Client", "mode") self.client_command = self.config_parser.get("Client", "command") else: self.client_name = "ncmpc++" self.client_mode = "gnome-terminal" self.client_command = "ncmpcpp"
def __init__(self, file=None): from ConfigParser import RawConfigParser as configparser cfg = configparser() if hasattr(file, 'readline'): # file like object cfg.readfp(file) else: filename = os.path.expanduser(os.path.expandvars(file)) cfg.read(filename) for secname in cfg.sections(): kwds = {i[0]:i[1] for i in cfg.items(secname)} cat, name = secname.split() objstore = self.__dict__.setdefault(cat, OrderedDict()) try: factory = kwds.pop('factory') except KeyError: factory = getattr(ersatz.factories, cat) else: factory = get_method(factory) objstore[name] = factory(name, **kwds)
def read_conf_file(self, file_name=None): if self.conf_file_parser is None: config = configparser() if file_name is None: file_name = self.model + ".conf" sys.stderr.write("o Assuming conf file is called " + file_name + "\n") if os.sep in file_name: # Path specified try: config.read_file(io.open(file_name, encoding="utf8")) except AttributeError: config.readfp(io.open(file_name, encoding="utf8")) else: if not os.path.isfile(script_dir + os.sep + file_name): sys.stderr.write("FATAL: could not find configuration file " + file_name + " in " + script_dir + "\n") sys.exit() try: config.read_file(io.open(script_dir + os.sep + file_name,encoding="utf8")) except AttributeError: config.readfp(io.open(script_dir + os.sep + file_name,encoding="utf8")) self.conf_file_parser = config else: config = self.conf_file_parser for key, val in config.items(self.lang): if key in ["base_letters","vowels","diacritics","unused"]: if key == "unused": vals = val.split(",") vals = [v.strip() for v in vals] else: vals = list(val) self.conf[key] = set(vals) elif key == "pos_classes": mappings = val.strip().replace("\r","").split('\n') for mapping in mappings: if "<-" in mapping: target, sources = mapping.strip().split("<-") for source in sources.split("|"): self.short_pos[source] = target elif key == "regex_tok": self.regex_tok = [] items = val.strip().split("\n") for regex in items: if "\t" in regex: f, r = regex.strip().split("\t") self.regex_tok.append((re.compile(f),r)) else: sys.stderr.write("WARN: regex entry without tab in conf file\n") elif key == "allowed": self.enforce_allowed = True items = val.strip().split("\n") for rule in items: if "<-" in rule: position, chars = rule.strip().split("<-") try: position = int(position) except Exception as e: raise ValueError("Can't interpret position instruction in conf file as integer: " + position + "\n") self.allowed[position] = list(chars) else: sys.stderr.write("WARN: allowed segmentation position entry without '<-' in conf file\n") self.letters = self.conf["base_letters"]
#!/usr/bin/env python import MySQLdb try: from ConfigParser import ConfigParser as configparser except: from configparser import ConfigParser as configparser from os.path import isfile from random import randint as rand CONF = configparser() for filepath in ['/etc/deadlocker/settings.conf', 'settings.conf']: if isfile(filepath): CONF.read(filepath) break QUERY = ''' UPDATE quark_mac_addresses SET deallocated=0, deallocated_at=NULL, transaction_id=%s WHERE quark_mac_addresses.deallocated_at <= '2016-02-11 13:19:44.057987' AND quark_mac_addresses.deallocated = true LIMIT 1''' QUERY_TEST = ''' UPDATE quark_mac_addresses SET deallocated=0, deallocated_at=NULL,
def __init__(self, configdir=None): self.configdir = configdir if not self.configdir: self.configdir = get_config_dir() self.config = configparser(config_defaults) self.config.read(os.path.join(self.configdir, conffile))