def override(self, configFile): """ over ride configuration from file """ with open(configFile) as fp: for key, value in jprops.iter_properties(fp): self.configs[key] = value
def __init__(self, token=None, apiurl=None, path_to_config_file=DEFAULT_CONFIG_PROPERTIES): # in case either token is not provided, load them from the property file if token is None: # load token from property file try: with open(path_to_config_file) as fp: props = list(jprops.iter_properties(fp)) prop_token = None prop_apiurl = None # check whether token and apiurl exist for key, value in props: if key == 'token': prop_token = value if key == 'apiurl': prop_apiurl = value if prop_token is None: raise Pdf4meClientException( 'Please store the token in the ' + path_to_config_file + 'file or provide your token in the Pdf4meClient constructor.') except IOError: raise Pdf4meClientException( 'The config.properties file is not stored at \'' + path_to_config_file + '\'. Please initialize the Pdf4meClient object with the correct path to your conifg.properties file. Or else provide your token in the Pdf4meClient constructor.') self.custom_http = CustomHttp(prop_token, prop_apiurl) else: self.custom_http = CustomHttp(token, apiurl)
def handle(self): envLocation = os.environ.get('AUTOMATED_HOME') propLocation = os.path.join(envLocation, 'listenerLog0.properties') propLocation = os.path.abspath(propLocation) lastTestPassed = "true" onHold = "false" breakPoint = "false" data = "" with open(propLocation) as fp: for key, value in jprops.iter_properties(fp): if key.startswith('data'): data = value if data == 'kill': self._signal_kill() elif data == 'pause': self.server.debugger.pause() elif data == 'resume': self.server.debugger.resume() elif data == 'step_next': self.server.debugger.step_next() elif data == 'step_over': self.server.debugger.step_over() elif data == 'pause_on_failure': self.server.debugger.pause_on_failure(True) elif data == 'do_not_pause_on_failure': self.server.debugger.pause_on_failure(False)
def __init__(self, configFile, defValues, verbose=False): configs = {} with open(configFile) as fp: for key, value in jprops.iter_properties(fp): configs[key] = value self.configs = configs self.defValues = defValues self.verbose = verbose
def get_configs(configFile): configs = {} print "using following configurations" with open(configFile) as fp: for key, value in jprops.iter_properties(fp): print key, value configs[key] = value return configs
def getConfigs(configFile): configs = {} print "using following configurations" with open(configFile) as fp: for key, value in jprops.iter_properties(fp): print key, value configs[key] = value return configs
def check_status(self): envLocation = os.environ.get('AUTOMATED_HOME') propLocation = os.path.join(envLocation, 'listenerLog0.properties') propLocation = os.path.abspath(propLocation) data = "" with open(propLocation) as fp: for key, value in jprops.iter_properties(fp): if key.startswith('data'): data = value return data
def __init__(self, filename): try: import jprops except: print('Error: jprops module for parsing .properties files is missing. Download and follow installation instructions from http://mgood.github.com/jprops/') sys.exit(2) self.keys = [] with open(filename) as fp: for key, value in jprops.iter_properties(fp): self.keys.append(key)
def parse_properties(file): props = {} with open(file, 'rb') as fp: for key, value in jprops.iter_properties(fp): if key == 'AndroidVersion.ApiLevel': props['api'] = value elif key == 'Pkg.LicenseRef': props['license'] = value elif key == 'Pkg.Revision': props['revision'] = value elif key == 'SystemImage.Abi': props['abi'] = value elif key == 'SystemImage.TagId': props['tag'] = value return props
def add_props_file(base_path, addition_path): with open(addition_path, "rt") as file_in: props = list(jprops.iter_properties(file_in, comments=True)) with open(base_path, "a") as file_out: for prop in props: if not isinstance(prop[0], _CommentSentinel): file_out.write(f"{prop[0]}={prop[1]}\n") else: file_out.write(f"\n\n# {prop[1]}\n")
def setup_ansible_config(self): ansibleFilename = '/etc/ansible/hosts' self.ANSIBLE_HOSTS = {} try: # jprops does a good job of handling the minutiae of parsing a properties file, but # it does not handle sections. So we use a hacky wrapper on jprops to do that. lines = open(ansibleFilename).read().splitlines() fo = sectionFilename = None sectionFiles = [] for line in lines: regex = re.compile(r'[[]([^]]*)[]]') match = regex.match(line) if match: section = match.group(1) if fo: fo.close() sectionFilename = '/var/local/ramdisk/ansible.' + section + '.ini' fo = open(sectionFilename, 'w') sectionFiles.append(sectionFilename) else: if fo: fo.write(line + "\n") if fo: fo.close() ansibleMinersFilename = '/var/local/ramdisk/ansible.miners.ini' with open(ansibleMinersFilename) as fh: for ip, value in jprops.iter_properties(fh): (hostname, platform) = value.strip().split(' ') hostname = hostname.split('=')[1] platform = platform.split('=')[1] self.ANSIBLE_HOSTS[hostname] = { 'hostname': hostname, 'platform': platform, 'ip': ip } # We don't need these section files anymore. for fn in sectionFiles: os.remove(fn) except IOError as ex: print(str(ex)) except AttributeError as ex: print(ansibleFilename + ' format is invalid (for miners).' + str(ex)) except: print(sys.exc_info()[0])
def __init__(self, client_id=None, secret=None, path_to_config_file=DEFAULT_CONFIG_PROPERTIES): # in case either client_id or secret is not provided, load them from the property file if client_id is None or secret is None: # load client_id and secret from property file try: with open(path_to_config_file) as fp: props = list(jprops.iter_properties(fp)) prop_client_id = None prop_secret = None # check whether client_id and secret exist for key, value in props: if key == 'client_id': prop_client_id = value elif key == 'secret': prop_secret = value if prop_client_id is None: raise Pdf4meClientException( 'Please store the client_id in the ' + path_to_config_file + ' file or provide your client_id in the Pdf4meClient constructor.' ) elif prop_secret is None: raise Pdf4meClientException( 'Please store the secret in the ' + path_to_config_file + ' file or provide your secret in the Pdf4meClient constructor.' ) except IOError: raise Pdf4meClientException( 'The config.properties file is not stored at \'' + path_to_config_file + '\'. Please initialize the Pdf4meClient object with the correct path to your conifg.properties file. Or else provide your clientId AND secret in the Pdf4meClient constructor.' ) self.custom_http = CustomHttp(prop_client_id, prop_secret) else: self.custom_http = CustomHttp(client_id, secret)
def start_keyword(self, name, attrs): #print 'About to execute keyword %s with arguments %s' % (name, attrs['args']) envLocation = os.environ.get('AUTOMATED_HOME') propLocation = os.path.join(envLocation, 'listenerLog0.properties') propLocation = os.path.abspath(propLocation) lastKeyword = "" with open(propLocation) as fp: for key, value in jprops.iter_properties(fp): if key.startswith('lastKeyword'): lastKeyword = value #print lastKeyword self._send_socket("start_keyword", name, attrs) if self._debugger.is_breakpoint(name, attrs): self._debugger.pause() paused = self._debugger.is_paused() if paused: self._send_socket('paused') self._debugger.start_keyword() if paused: self._send_socket('continue')
def _send_socket(self, data): envLocation = os.environ.get('AUTOMATED_HOME') propLocation = os.path.join(envLocation, 'listenerLog0.properties') propLocation = os.path.abspath(propLocation) lastTestPassed = "true" onHold = "false" breakPoint = "false" lastKeyword = "" with open(propLocation) as fp: for key, value in jprops.iter_properties(fp): if key.startswith('lastTestPassed'): lastTestPassed = value if key.startswith('onHold'): onHold = value if key.startswith('breakPoint'): breakPoint = value if key.startswith('lastKeyword'): lastKeyword = value '''lastTestPassed = "true" onHold = "false" breakPoint = "false" with open(propLocation) as fp: for key, value in jprops.iter_properties(fp): if key.startswith('lastTestPassed'): lastTestPassed = value if key.startswith('onHold'): onHold = value if key.startswith('breakPoint'): breakPoint = value with open(propLocation, 'w') as fp: jprops.write_property(fp, 'lastTestPassed', lastTestPassed) jprops.write_property(fp, 'onHold', onHold) jprops.write_property(fp, 'breakPoint', 'true')''' with open(propLocation, 'w') as fp: jprops.write_property(fp, 'data', data) jprops.write_property(fp, 'lastTestPassed', lastTestPassed) jprops.write_property(fp, 'onHold', onHold) jprops.write_property(fp, 'lastKeyword', lastKeyword) jprops.write_property(fp, 'breakPoint', 'true')
def test_iter_properties_ignores_comments_by_default(): fp = BytesIO(b'a\n#foo\nb\n') assert list(jprops.iter_properties(fp)) == [('a', ''), ('b', '')]
def prop_templates_to_instances(var_file_path, template_files, print_variables=False): """ This function renders a list of files ending with .tmpl into files without .tmpl ending, replacing template_variables from conf. if such files exist before hand they are deleted :param var_file_path: :param template_files: :param print_variables: :return: """ with open(var_file_path) as fp: variable_map = jprops.load_properties(fp) if print_variables: tuple_list_vars = jprops.iter_properties(fp, comments=False) logging.info(f'\n\nproperties:\n') for prop in list(tuple_list_vars): logging.info(prop) for template_file in template_files: prop_file = template_file.replace('.tmpl', '') try: os.remove(prop_file) except OSError: pass with open(template_file, "rt") as file_in: props = list(jprops.iter_properties(file_in, comments=True)) with open(prop_file, "wt") as file_out: for prop in props: logging.info(f'prop: {prop} of type: {type(prop[0])}') if not isinstance(prop[0], _CommentSentinel): new_prop = prop[1] if '#' in prop[1]: logging.debug(prop) vrs = get_vars_from_string(prop[1], '#') logging.debug(vrs) new_val = prop[1] for k in vrs: logging.debug( f'key: {k} value:{variable_map[k]}') new_val = new_val.replace(k, variable_map[k]) new_val = new_val.replace('#', '') new_prop = new_val new_prop = new_prop.replace('"', '') file_out.write(f"{prop[0]}={new_prop}\n") else: file_out.write(f"\n\n# {prop[1]}\n")
def test_read_text(): fp = StringIO(u'a=\u00ff\n') assert list(jprops.iter_properties(fp)) == [(u'a', u'\u00ff')]
def test_iter_properties_includes_comments(): fp = BytesIO(b'a\n#foo\nb\n') assert (list(jprops.iter_properties(fp, comments=True)) == [('a', ''), (jprops.COMMENT, 'foo'), ('b', '')])
def test_read_bytes(): fp = BytesIO(b'a=\\u00ff\n') assert list(jprops.iter_properties(fp)) == [(u'a', u'\u00ff')]
def test_iter_properties_includes_comments(): fp = BytesIO(b'a\n#foo\nb\n') assert (list(jprops.iter_properties(fp, comments=True)) == [ ('a', ''), (jprops.COMMENT, 'foo'), ('b', '') ])