def OnTestPressed(self, sender, e): try: root = os.path.dirname(os.path.realpath(__file__)) yamlPath = os.path.join(root, r'data\Project_Database.yaml') with open(yamlPath, 'r') as fileDescriptor: database = yaml.load(fileDescriptor) try: self.tBoxProjName.Text = database['Project']['Name'] except: pass try: self.tBoxProjNum.Text = database['Project']['Number'] except: pass try: self.tBoxClientName.Text = database['Project']['Client']['Name'] except: pass try: self.tBoxProjCity.Text = database['Project']['Location']['City'] except: pass try: self.drpDwnProjState.SelectedKey = database['Project']['Location']['State'] except: pass try: self.drpDwnProjCountry.SelectedKey = database['Project']['Location']['Country'] except: pass except: print "YAML Failed"
def runDeviceTestsFromYAML(self, file_name): yamlFile = open(os.path.join(TEST_RESOURCES_DIR, file_name)) yamlContents = yaml.load(yamlFile) yamlFile.close() for test_case in yamlContents['test_cases']: # Inputs to Parse() user_agent_string = test_case['user_agent_string'] kwds = {} if 'js_ua' in test_case: kwds = eval(test_case['js_ua']) # The expected results expected = { 'family': test_case['family'], 'is_mobile': test_case['is_mobile'], 'is_spider': test_case['is_spider'] } result = user_agent_parser.ParseDevice(user_agent_string, **kwds) self.assertEqual( result, expected, u"UA: {0}\n expected<{1} {2} {3}> != actual<{4} {5} {6}>". format(user_agent_string, expected['family'], expected['is_mobile'], expected['is_spider'], result['family'], result['is_mobile'], result['is_spider']))
def runOSTestsFromYAML(self, file_name): yamlFile = open(os.path.join(TEST_RESOURCES_DIR, file_name)) yamlContents = yaml.load(yamlFile) yamlFile.close() for test_case in yamlContents['test_cases']: # Inputs to Parse() user_agent_string = test_case['user_agent_string'] kwds = {} if 'js_ua' in test_case: kwds = eval(test_case['js_ua']) # The expected results expected = { 'family': test_case['family'], 'major': test_case['major'], 'minor': test_case['minor'], 'patch': test_case['patch'], 'patch_minor': test_case['patch_minor'] } result = user_agent_parser.ParseOS(user_agent_string, **kwds) self.assertEqual(result, expected, u"UA: {0}\n expected<{1} {2} {3} {4} {5}> != actual<{6} {7} {8} {9} {10}>".format(\ user_agent_string, expected['family'], expected['major'], expected['minor'], expected['patch'], expected['patch_minor'], result['family'], result['major'], result['minor'], result['patch'], result['patch_minor']))
def makePGTSComparisonYAML(self): import codecs outfile = codecs.open('outfile.yaml', 'w', 'utf-8') print >> outfile, "test_cases:" yamlFile = open( os.path.join(TEST_RESOURCES_DIR, 'pgts_browser_list.yaml')) yamlContents = yaml.load(yamlFile) yamlFile.close() for test_case in yamlContents['test_cases']: user_agent_string = test_case['user_agent_string'] kwds = {} if 'js_ua' in test_case: kwds = eval(test_case['js_ua']) (family, major, minor, patch) = user_agent_parser.ParseUserAgent(user_agent_string, **kwds) # Escape any double-quotes in the UA string user_agent_string = re.sub(r'"', '\\"', user_agent_string) print >> outfile, ' - user_agent_string: "' + unicode(user_agent_string) + '"' + "\n" +\ ' family: "' + family + "\"\n" +\ " major: " + ('' if (major is None) else "'" + major + "'") + "\n" +\ " minor: " + ('' if (minor is None) else "'" + minor + "'") + "\n" +\ " patch: " + ('' if (patch is None) else "'" + patch + "'") outfile.close()
def load_yaml(self, map_key, path): ''' 使用一个map_key对yaml文件进行映射获取 :param map_key: map_key :param path: yaml文件路劲 :return: ''' if map_key not in self._parms: self._parms[map_key] = yaml.load(stream=open(path, 'rb').read())
def GetDatabaseTemplate(): ''' Gets the yaml databse template Input: None Returns: Dictionary of yaml file on success ''' try: with open(yamlPath, 'r') as fileDescriptor: databaseTemplate = yaml.load(fileDescriptor) return databaseTemplate except: return None
def GetProjectDatabase(databaseFile): ''' Gets the yaml project database Input: databaseFile - path to the database Returns: Dictionary of yaml file on success ''' try: with open(databaseFile, 'r') as fileDescriptor: databaseTemplate = yaml.load(fileDescriptor) return databaseTemplate except: return None
def load_yaml(yaml_file): '''加载yaml文件''' path_yaml = os.path.join(base_dir, "conf" + os.sep + yaml_file) with open(path_yaml) as f: return yaml.load(f)
def load(self, path): self._steam = self._steams[ path] if path in self._steams else yaml.load(open(path)) self._path = path
filterdict = { 'js_user_agent_string': js_user_agent_string, 'js_user_agent_family': js_user_agent_family, 'js_user_agent_v1': js_user_agent_v1, 'js_user_agent_v2': js_user_agent_v2, 'js_user_agent_v3': js_user_agent_v3 } for key, value in filterdict.items(): if value is not None and value != '': filters[key] = value return filters # Build the list of user agent parsers from YAML yamlFile = open(os.path.join(ROOT_DIR, 'data/regexes.yaml')) yaml = yaml.load(yamlFile) yamlFile.close() USER_AGENT_PARSERS = [] for _ua_parser in yaml['user_agent_parsers']: _regex = _ua_parser['regex'] _family_replacement = None if 'family_replacement' in _ua_parser: _family_replacement = _ua_parser['family_replacement'] _v1_replacement = None if 'v1_replacement' in _ua_parser: _v1_replacement = _ua_parser['v1_replacement'] USER_AGENT_PARSERS.append(
#Read from YAML database import os from libs import yaml root = os.path.dirname(os.path.realpath(__file__)) yamlPath = os.path.join(root, "Project_Info.yaml") with open(yamlPath, 'r') as fileDescriptor: database = yaml.load(fileDescriptor) print database['Building'][1]['Functions'] print database['Building'][1]['Level'][2]['Name'] print database['Building'][1]['Level'][2]['Z'] print "Number of levels: " + str(len(database['Building'][1]['Level'])) ##WRITE DATA #data = { #'Version':'0.1', #'Project':{ # 'Name':'The Embankment', # 'Number':'A1802', # 'Location':{ # 'Street': '2112 Jersey Ave.', # 'City': 'New Jersey', # 'State': 'New Jersey', # 'Country': 'USA' # }, # 'Client':{ # 'Name': 'Albanese' # }, # 'Functions': [