def gather_dependencies(self): log.info('gathering dependencies...') self.npm(['shrinkwrap']) shrinkwrapFile = join(self.module_dir, 'npm-shrinkwrap.json') if is_existing_file(shrinkwrapFile): move(shrinkwrapFile, self.shrinkwrap) # clean shrinkwrap file see spec on https://wiki.wdf.sap.corp/wiki/display/xs2/Filtering+SAP-internal+metadata+before+release cleanedShrinwrap = {} with open(self.shrinkwrap, 'r') as f: cleanedShrinwrap = json.load(f) keystoremove = [] self._clean_shrinkwrap(cleanedShrinwrap, listofkeytoremove=keystoremove) for keys in keystoremove: shrinkwrappart = cleanedShrinwrap for key in keys[:-1]: shrinkwrappart = shrinkwrappart[key] shrinkwrappart.pop(keys[-1], None) with open(self.shrinkwrap, 'w') as jsonfile: json.dump(cleanedShrinwrap, jsonfile, indent=2) dep = self.module_dir p = Properties() for (m, v) in self.list_deps(join(dep), ''): p.setProperty(m, v) with open(self.deps, 'w') as f: p.store(f) copyfile(self.deps, join(dep, 'dependencies'))
def testParsePropertiesInput(self): properties = Properties() properties.load(open(self.properties_file)) self.assertEquals(23, len(properties.items())) self.assertEquals('Value00', properties['Key00']) self.assertEquals('Value01', properties['Key01']) self.assertEquals('Value02', properties['Key02']) self.assertEquals('Value03', properties['Key03']) self.assertEquals('Value04', properties['Key04']) self.assertEquals('Value05a, Value05b, Value05c', properties['Key05']) self.assertEquals('Value06a, Value06b, Value06c', properties['Key06']) self.assertEquals('Value07b', properties['Key07']) self.assertEquals( 'Value08a, Value08b, Value08c, Value08d, Value08e, Value08f', properties['Key08']) self.assertEquals( 'Value09a, Value09b, Value09c, Value09d, Value09e, Value09f', properties['Key09']) self.assertEquals('Value10', properties['Key10']) self.assertEquals('', properties['Key11']) self.assertEquals('Value12a, Value12b, Value12c', properties['Key12']) self.assertEquals('Value13 With Spaces', properties['Key13']) self.assertEquals('Value14 With Spaces', properties['Key14']) self.assertEquals('Value15 With Spaces', properties['Key15']) self.assertEquals('Value16', properties['Key16 With Spaces']) self.assertEquals('Value17', properties['Key17 With Spaces']) self.assertEquals('Value18 # Not a comment.', properties['Key18']) self.assertEquals('Value19 ! Not a comment.', properties['Key19']) self.assertEquals('Value20', properties['Key20=WithEquals']) self.assertEquals('Value21', properties['Key21:WithColon']) self.assertEquals('Value22', properties['Key22'])
def change_dbms_config(db): from pyjavaproperties import Properties p = Properties() p.load(open('config/database.properties')) print p['dbms'] print db p['dbms'] = db p.store(open('config/database.properties', 'w'))
def __init__(self): self.prop = Properties() try: propertiesFile = open("../Files/Config.properties", 'r') self.prop.load(propertiesFile) self.prop.list() except FileNotFoundError as e: print(e)
def getFilename(filename): p = Properties() p.load(open('../build.number.properties')) minor = p['build.minor'] major = p['build.major'] point = p['build.point'] filename = filename + '-' + major + minor + point return filename
def getFilename(): p = Properties(); p.load(open('../../build.number.properties')); minor = p['build.minor']; major = p['build.major']; point = p['build.point']; filename = 'core_' + major + minor + point return filename
def suffixFilename(filename, build): p = Properties() p.load(open('projects/mtg/build.number.properties')) minor = p['build.minor'] major = p['build.major'] point = p['build.point'] name, extension = os.path.splitext(filename) filename = name + '-' + major + minor + point + '-' + build + extension return filename
def load_properties_locally(locale): props = Properties() props.load( open(os.path.abspath( os.path.join(os.path.abspath(os.path.join(os.getcwd(), os.pardir)), os.pardir)) + '/main/resources/messages' + locale + '.properties', mode='r')) return props
def write_to_report(): prop = Properties() out = open(globals.ALLURE_RESULTS + "environment.properties", mode='w') prop.setProperty("Browser", ReadConfig.browser()) prop.setProperty("URL", ReadConfig.get_url()) prop.setProperty("Python", str(sys.version)) window_version = str(sys.getwindowsversion()) prop.setProperty("Platform", window_version.title()) prop.store(out)
def __init__(self): # Open and load the file. For each file property, # we assign it as the property of the object instance with open(APP_PROP_FILE, "r") as app_property_file: app_properties = Properties() app_properties.load(app_property_file) for property, value in app_properties.items(): setattr(self, property, value)
def update_properties_file(properties_file, new_properties): p = Properties() logging.debug('Opening file %s', properties_file) p.load(open(properties_file)) for name, value in new_properties: logging.info('Setting new value of %s to %s', name, value) p[name] = value logging.debug('Saving file %s with new values', properties_file) p.store(open(properties_file, 'w'))
def isPropertiesFileValid(filePath): """Verifies if a given properties file is valid""" p = Properties() try: p.load(open(filePath)) return True except: return sys.exc_info()[1]
def load(filename=DEFAULT_CONFIG_FILENAME): p = Properties() if os.path.isfile(filename): p.load(open('stock.properties')) if not p['listed.pricePath'].strip(): p['listed.pricePath'] = DEFAULT_LISTED_PRICE_PATH if not p['listed.instPath'].strip(): p['listed.instPath'] = DEFAULT_LISTED_INST_PATH if not p['listed.lastDownload'].strip(): p['listed.lastDownload'] = DEFAULT_START_DATE if p['listed.isDownload'].strip() != 'false': p['listed.isDownload'] = 'true' if not p['listed.lastUpdateDb'].strip(): p['listed.lastUpdateDb'] = DEFAULT_START_DATE if p['listed.isUpdateDb'].strip() != 'false': p['listed.isUpdateDb'] = 'true' if not p['listed.lastUpdateIdx'].strip(): p['listed.lastUpdateIdx'] = DEFAULT_START_DATE if p['listed.isUpdateIdx'].strip() != 'false': p['listed.isUpdateIdx'] = 'true' if not p['otc.pricePath'].strip(): p['otc.pricePath'] = DEFAULT_OTC_PRICE_PATH if not p['otc.instPath'].strip(): p['otc.instPath'] = DEFAULT_OTC_INST_PATH if not p['otc.lastDownload'].strip(): p['otc.lastDownload'] = DEFAULT_START_DATE if p['otc.isDownload'].strip() != 'false': p['otc.isDownload'] = 'true' if not p['otc.lastUpdateDb'].strip(): p['otc.lastUpdateDb'] = DEFAULT_START_DATE if p['otc.isUpdateDb'].strip() != 'false': p['otc.isUpdateDb'] = 'true' if not p['otc.lastUpdateIdx'].strip(): p['otc.lastUpdateIdx'] = DEFAULT_START_DATE if p['otc.isUpdateIdx'].strip() != 'false': p['otc.isUpdateIdx'] = 'true' if not p['db.server'].strip(): p['db.server'] = 'SERVER_NAME' if not p['db.username'].strip(): p['db.username'] = '******' if not p['db.password'].strip(): p['db.password'] = '******' if not p['db.database'].strip(): p['db.database'] = 'DATABASE_NAME' return p
def __init__(self): self.driver = webdriver.Chrome( executable_path= "/home/easyway/Desktop/selnium jars/chromedriver_linux64/chromedriver" ) self.p = Properties() self.p.load( open( '/home/easyway/Music/github/SeleniumWithPython/config.properties' )) self.p.list()
def parse_property_file(filename): """ parse java properties file :param filename: the path of the properties file :return: dictionary loaded from the file """ if not os.path.isfile(filename): raise RuntimeError( "No file found for parameter at {0}".format(filename)) p = Properties() p.load(open(filename)) return p
def __init__(self): self.propAbhi = Properties() try: propertiesFile = open("./Files/Config.properties") self.propAbhi.load(propertiesFile) self.propAbhi.list() except FileNotFoundError as e: print(e) self.logger = logging.getLogger() self.logger.setLevel(logging.INFO) self.driver = null
def write_version_properties(build_cfg): p = Properties() log.info('version is ' + build_cfg.version()) log.info('scm_url is ' + str(build_cfg.scm_snapshot_url())) p.setProperty('release_version', build_cfg.version()) p.setProperty('scm_url', str(build_cfg.scm_snapshot_url())) # pairs = [('release_version', build_cfg.version()), # ('scm_url', build_cfg.scm_snapshot_url())] # contents = '\n'.join([key + '=' + str(value) for (key, value) in pairs]) with open(build_cfg.version_properties_file(), 'w') as f: p.store(f)
def __generate_workload_config(self, extraneous_config): # Read base workload properties into a dict if we haven't already if self.__base_workload_props is None: props = Properties() with open(self.workload_path) as wf: props.load(wf) self.__base_workload_props = props.getPropertyDict() if extraneous_config is None: extraneous_config = {} # Merge base workload properties with extraneous options workload_config = dict(self.__base_workload_props) workload_config.update(extraneous_config) # Merge and return the workload config dict return workload_config
def __setattr__(self, name, value): # For each property assigned to the instance object, we write it to the #file, If it doesn't exist we add it. app_properties = Properties() with open(APP_PROP_FILE, "r") as app_property_file: app_properties.load(app_property_file) current_properties = app_properties.propertyNames() if name not in current_properties or value != app_properties.get(name): with open(APP_PROP_FILE, "w") as app_property_file: app_properties[name] = value app_properties.store(app_property_file) super(MyAppProperties, self).__setattr__(name, value)
def get_property_value(property_name): cur_path = os.getcwd() ui_map_file = os.path.join(cur_path, '..' + os.sep, 'STAF_Config' + os.sep + 'ui_map.properties') ui_map_file = os.path.abspath(ui_map_file) prop = Properties() prop.load(open(ui_map_file)) if prop.getProperty(property_name).strip() == "": return "Property not found" else: return prop.getProperty(property_name)
def updateConfigReport(): for model in [file for file in glob.glob('./*.model')]: print('\tChecking [{0}]'.format(model)) type, target, spec = readModel(model) print('\t\tType: {0}, Target: {1}'.format(type, target)) if type == 'XML': compareXML(target, spec, etree.XML(open(target, "r").read())) elif type == 'OS': compareOS(target, spec) elif type == 'properties': p = Properties() p.load(open(target, "r")) compareProperties(target, spec, p) else: print('\t{0} is invalid.'.format(model))
def run_servers(): print "Running Servers..." p = Properties() p.load(open(property_file_name, 'r')) hostname = p[configHostname] port = p[configPortname] status = ssh( server_machines["ConfigServer"][0], server_machines["ConfigServer"][1], "cd " + server_folder + " && java -jar " + server_folder + "ConfigServer.jar") if status != 0: print "Error running ConfigServer." print "Started ConfigServer on " + server_machines["ConfigServer"][ 0] + "..." status = ssh(server_machines["ConfigServer"][0], server_machines["ConfigServer"][1], "cd " + server_folder + " && ps aux | grep '[j]ava -jar /home' | grep " + server_machines["ConfigServer"][1] + " | awk '{print \$2}' > pid", blocking=True, verbose=True) if status != 0: print "Error saving pid file." time.sleep(1) for i in server_machines: if i == "ConfigServer": continue status = ssh( server_machines[i][0], server_machines[i][1], "cd " + server_folder + " && java -jar " + server_folder + i + ".jar " + hostname + " " + port) if status != 0: print "Error running " + i + "." else: print "Started " + i + " on " + server_machines[i][0] + "..." status = ssh(server_machines[i][0], server_machines[i][1], "cd " + server_folder + " && ps aux | grep '[j]ava -jar /home' | grep " + server_machines[i][1] + " | awk '{print \$2}' > pid", blocking=True, verbose=True) if status != 0: print "Error saving pid file." time.sleep(2)
def readModel(modelFile): fd = open(modelFile, "r") targetline = fd.readline() target = re.match("compareTo\((XML|OS|properties)\):\s*(.*)", targetline) if target is not None: if target.groups()[0] == 'XML': spec = etree.XML(fd.read()) elif target.groups()[0] == 'OS': spec = yaml.load(fd.read(), Loader=yaml.FullLoader) elif target.groups()[0] == 'properties': p = Properties() p.load(fd) spec = p else: spec = None return target.groups()[0], target.groups()[1], spec else: return None, None, None
def createResult(path): all_dir=getDirList(path) varss=['project.dir','outputFile'] vars2=['outputFile','project.dir'] for x in all_dir: print x p = Properties() p.load(open('rouge.properties')) for name, value in [('project.dir', x), ('outputFile', str(x+'_results.csv'))]: p[name] = value p.store(open('rouge.properties', 'w')) #time.sleep(30) runJar(path)
def write(keydict, savedir): if not os.path.exists(savedir): raise Exception('"' + savedir + '" does not exist!') loadfile = os.path.join(savedir, JitsiProperties.propertiesfile) savefile = loadfile if not os.path.exists(loadfile) and os.path.exists( JitsiProperties.path): print 'Adium WARNING: "' + loadfile + '" does not exist! Reading from:' loadfile = os.path.join(JitsiProperties.path, JitsiProperties.propertiesfile) print '\t"' + loadfile + '"' propkey_base = 'net.java.sip.communicator.plugin.otr.' p = Properties() p.load(open(loadfile)) for name, key in keydict.iteritems(): if 'verification' in key and key['verification'] != '': verifiedkey = (propkey_base + re.sub('[^a-zA-Z0-9_]', '_', key['name']) + '_publicKey_verified') p[verifiedkey] = 'true' if 'y' in key: pubkey = (propkey_base + re.sub('[^a-zA-Z0-9_]', '_', key['name']) + '_publicKey') p.setProperty(pubkey, util.ExportDsaX509(key)) if 'x' in key and '@' in key['name']: pubkey = ( propkey_base + 'Jabber_' + re.sub('[^a-zA-Z0-9_]', '_', key['name']) + '_' + re.sub('[^a-zA-Z0-9_]', '_', key['name'].split('@')[1]) + '_publicKey') p.setProperty(pubkey, util.ExportDsaX509(key)) privkey = ( propkey_base + 'Jabber_' + re.sub('[^a-zA-Z0-9_]', '_', key['name']) + '_' + re.sub('[^a-zA-Z0-9_]', '_', key['name'].split('@')[1]) + '_privateKey') p.setProperty(privkey, util.ExportDsaPkcs8(key)) p.store(open(savefile, 'w'))
def connect_to_s3(): boto_kwargs = {} try: with open(CONFIG_FILE, 'r') as f: p = Properties() p.load(f) access_key = p.get('accessKey') if access_key: logger.debug('Reading access key from {0}'.format(CONFIG_FILE)) boto_kwargs['aws_access_key_id'] = access_key secret_key = p.get('secretKey') if secret_key: logger.debug('Reading access key from {0}'.format(CONFIG_FILE)) boto_kwargs['aws_secret_access_key'] = secret_key except IOError: logger.debug('Could not load {0}, using ENV vars'.format(CONFIG_FILE)) config = Config(connect_timeout=4, read_timeout=4) return boto3.resource('s3', config=config, **boto_kwargs)
def main(): p = Properties() p.load(open('res/proj.properties')) print(c.sendBirdyHeader) ts = time.gmtime() ts2 = time.asctime(ts) if (len(sys.argv) ) <= 1: # if no arguments are provided, print usage and exit print(c.errorMsg + c.askForHelp) print("{!}-----[Settings]--- Workspace: " + p['WORKSPACE']) print("{!}-----[Settings]--- hinge-id: " + p['HINGE-ID']) print("{!}-----[Settings]--- hinge-token: " + p['HINGE-TOKEN']) sys.exit(0) else: # Get Options options, remainder = getopt.getopt(sys.argv[1:], 'o:v', [ 'help', 'app=', 'put=', 'interactive=', 'version', ]) for opt, arg in options: if opt in ('-h', '--help'): print_help() elif opt in ('-a', '--app'): c.app = arg elif opt in ('-i', '--interactive'): if arg == "yes": interactive_mode = True elif opt == ('-i', '--interactive'): if arg != "yes": print("interactive") start_sendbirdy() sys.exit(0)
def testParsePropertiesInput(self): properties = Properties() properties.load(open(self.properties_file)) self.assertEqual(25, len(properties.items())) self.assertEqual('Value00', properties['Key00']) self.assertEqual('Value01', properties['Key01']) self.assertEqual('Value02', properties['Key02']) self.assertEqual('Value03', properties['Key03']) self.assertEqual('Value04', properties['Key04']) self.assertEqual('Value05a, Value05b, Value05c', properties['Key05']) self.assertEqual('Value06a, Value06b, Value06c', properties['Key06']) self.assertEqual('Value07b', properties['Key07']) self.assertEqual( 'Value08a, Value08b, Value08c, Value08d, Value08e, Value08f', properties['Key08']) self.assertEqual( 'Value09a, Value09b, Value09c, Value09d, Value09e, Value09f', properties['Key09']) self.assertEqual('Value10', properties['Key10']) self.assertEqual('', properties['Key11']) self.assertEqual('Value12a, Value12b, Value12c', properties['Key12']) self.assertEqual('Value13 With Spaces', properties['Key13']) self.assertEqual('Value14 With Spaces', properties['Key14']) self.assertEqual('Value15 With Spaces', properties['Key15']) self.assertEqual('Value16', properties['Key16 With Spaces']) self.assertEqual('Value17', properties['Key17 With Spaces']) self.assertEqual('Value18 # Not a comment.', properties['Key18']) self.assertEqual('Value19 ! Not a comment.', properties['Key19']) # Single referenced property self.assertEqual('Value19 ! Not a comment.Value20', properties['Key20']) self.assertEqual('Value21', properties['Key21=WithEquals']) self.assertEqual('Value22', properties['Key22:WithColon']) self.assertEqual('Value23', properties['Key23']) # Multiple referenced properties with separator self.assertEqual( 'Value18 # Not a comment.-separator-Value19 ! Not a comment.', properties['Key24']) properties.store(open('saved.properties', 'w'))
def get_data_from_property_file(self, file_name): """| Usage | Gets data from .property file and returns dictionary. For more information on dictionary: https://github.com/robotframework/robotframework/blob/master/atest/testdata/standard_libraries/collections/dictionary.robot | Arguents | 'file_name' = .property file location Example: |***TestCases*** | ${dict} | Get Data From Property File | ${filename} ${value} | Get From Dictionary | ${dict} | ${key} """ if not os.path.exists(file_name): raise AssertionError("File not found error :" + file_name + " doesn't exist") else: try: p = Properties() p.load(open(file_name)) return p except: raise AssertionError( "Error in Properties file. Please pass standard properties files" )
def format(file): p = Properties() p.load(open('res/proj.properties')) dt = datetime.datetime.now().strftime("%Y%m%d%H%M") try: for line in open(file, 'r'): parsed = json.loads(line) formatted_outfile = str(p.getProperty('FORMATTEDOUTFILE')) + "sendbirdy-" + dt + ".json" try: f = open(formatted_outfile, "a") f.write(json.dumps(parsed, indent=4, sort_keys=True)) f.close() except IOError as io: print("{!}----- I/O error({0}): {1}"+ format(io.errno)) except Exception as e: print(c.indent_msg + c.indent_err + e) print(c.indent_msg + c.indent_info + " Output Located : [" + formatted_outfile) return