示例#1
0
 def testBuggyNodesReduce(self):
     object = syck.load(BUGGY_NODES)
     nodes = syck.parse(BUGGY_NODES)
     output = syck.dump(nodes)
     #print output
     nodes2 = syck.load(output)
     output2 = syck.emit(nodes2)
     object2 = syck.load(output2)
     self.assertEqual(object, object2)
示例#2
0
 def __init__(self, pref_string):
     # Load default values first
     from mallet.config import data_dir
     default_pref = open(os.path.join(data_dir, 'default.yaml')).read()
     default_data = syck.load(default_pref)
     # Load from user preferences
     self._data = syck.load(pref_string)
     if self._data is None:
         self._data = {}
     self._data.update(default_data)
示例#3
0
 def testExtensions(self):
     source = EXTENSIONS[0]
     object = EXTENSIONS[1]
     object2 = syck.load(source, Loader=ExLoader)
     for left, right in zip(object, object2):
         self.assertEqual(left, right)
     source2 = syck.dump(object2, Dumper=ExDumper)
     object3 = syck.load(source2, Loader=ExLoader)
     for left, right in zip(object, object3):
         self.assertEqual(left, right)
示例#4
0
 def testNonsense(self):
     class MyFile1:
         def read(self, max_length):
             return ' '*(max_length+1)
     class MyFile2:
         def read(self, max_length):
             return None
     self.assertRaises(ValueError, lambda: syck.parse(MyFile1()))
     self.assertRaises(ValueError, lambda: syck.load(MyFile1()))
     self.assertRaises(TypeError, lambda: syck.parse(MyFile2()))
     self.assertRaises(TypeError, lambda: syck.load(MyFile2()))
示例#5
0
 def testTimestamp(self):
     # Again, Syck does not understand the latest two forms.
     #self.assertEqual(syck.load(
     #        '- 2001-12-15T02:59:43.1Z\n'
     #        '- 2001-12-14t21:59:43.10-05:00\n'
     #        '- 2001-12-14 21:59:43.10 -5\n'
     #        '- 2001-12-15 2:59:43.10\n'),
     #    [datetime.datetime(2001, 12, 15, 2, 59, 43, 100000)]*4)
     self.assertEqual(syck.load(
             '- 2001-12-15T02:59:43.1Z\n'
             '- 2001-12-14t21:59:43.10-05:00\n'
             '- 2001-12-14 21:59:43.10 -05\n'
             '- 2001-12-15 02:59:43.10 Z\n'),
         [datetime.datetime(2001, 12, 15, 2, 59, 43, 100000)]*4)
     self.assertEqual(syck.load('2002-12-14'), datetime.datetime(2002, 12, 14))
示例#6
0
    def __init__(self, lang_override=None):

        # L_O_G.info('init spellchecker')

        self.spellengine = None
        self.lang = None
        self._need_to_download = None
        self.currentDownloads = set()
        self.expectedNext = None

        # load YAML file describing the dictionaries

        filename = program_dir() / "res" / ("dictionaries-%s.yaml" % Aspell.VERSION)
        try:
            with open(filename) as f:
                self.dict_info = syck.load(f)
                if not isinstance(self.dict_info, dict):
                    raise ValueError("invalid YAML in %s" % filename)
        except Exception:
            print_exc()
            self.dict_info = {}

        # load an engine using swap engine, if no engine is failed use the NullSpellEngine
        if not self.SwapEngine(lang_override):
            self.spellengine = NullSpellEngine()

        profile.prefs.add_observer(
            self.on_prefs_change,  # @UndefinedVariable
            "messaging.spellcheck.enabled",
            "messaging.spellcheck.engineoptions.lang",
            "messaging.spellcheck.engineoptions.encoding",
            "messaging.spellcheck.engineoptions.keyboard",
            "messaging.spellcheck.engineoptions.sug-mode",
        )  # @UndefinedVariable
示例#7
0
    def __init__(self, lang_override=None):

        #L_O_G.info('init spellchecker')

        self.spellengine = None
        self.lang = None
        self._need_to_download = None
        self.currentDownloads = set()
        self.expectedNext = None

        # load YAML file describing the dictionaries

        filename = program_dir() / 'res' / ('dictionaries-%s.yaml' %
                                            Aspell.VERSION)
        try:
            with open(filename) as f:
                self.dict_info = syck.load(f)
                if not isinstance(self.dict_info, dict):
                    raise ValueError('invalid YAML in %s' % filename)
        except Exception:
            print_exc()
            self.dict_info = {}

        # load an engine using swap engine, if no engine is failed use the NullSpellEngine
        if not self.SwapEngine(lang_override):
            self.spellengine = NullSpellEngine()

        profile.prefs.add_observer(
            self.on_prefs_change,  #@UndefinedVariable
            'messaging.spellcheck.enabled',
            'messaging.spellcheck.engineoptions.lang',
            'messaging.spellcheck.engineoptions.encoding',
            'messaging.spellcheck.engineoptions.keyboard',
            'messaging.spellcheck.engineoptions.sug-mode')  #@UndefinedVariable
示例#8
0
 def testLoad(self):
     self._testWarning()
     document, values = DOCUMENT
     new_values = syck.load(document)
     for string, new_string in zip(values, new_values):
         self.assertEqual(string, new_string)
         self.assertEqual(type(string), type(new_string))
示例#9
0
 def testLoad(self):
     self._testWarning()
     document, values = DOCUMENT
     new_values = syck.load(document)
     for string, new_string in zip(values, new_values):
         self.assertEqual(string, new_string)
         self.assertEqual(type(string), type(new_string))
示例#10
0
 def testMutableKey(self):
     document = syck.load(MUTABLE_KEY)
     self.assertEqual(type(document), list)
     self.assertEqual(len(document), 1)
     self.assertEqual(type(document[0]), tuple)
     self.assertEqual(len(document[0]), 2)
     self.assertEqual(document[0][0], document[0][1])
示例#11
0
 def testDuplicateKey(self):
     document = syck.load(DUPLICATE_KEY)
     self.assertEqual(type(document), list)
     self.assertEqual(len(document), 2)
     self.assertEqual(len(document[0]), 2)
     self.assertEqual(len(document[1]), 2)
     self.assertEqual(document[0][0], document[1][0])
示例#12
0
文件: Probes.py 项目: ab/bcfg2
 def yaml(self):
     if self._yaml is None and has_yaml:
         try:
             self._yaml = yaml.load(self.data)
         except yaml_error:
             pass
     return self._yaml
示例#13
0
def quick_name_lookup(p, **names):
    '''
    Given a path object to a skin YAML file, and "name keys", returns the values of those keys.

    The names must be on the highest level of key-value pairs.

    Returns a mapping of {names: values}
    '''

    #TODO: do we even need to parse the file here?

    names = dict((name.lower(), key) for key, name in names.iteritems())
    vals = {}

    with p.open('r') as f:
        s = syck.load(f)
        for k, name in getattr(s, 'iteritems', lambda: s)():
            try:
                k = k.lower()
            except AttributeError:
                pass
            else:
                if k in names and isinstance(name, basestring):
                    vals[k] = name
                    if len(vals) == len(names):
                        break
    return vals
示例#14
0
def yaml_load(filename):
    """Load and interpret a YAML file, using whichever library is
    found. The following packages are tried:

     pysyck
     pyyaml (with C extensions if available)

    """
    f = open(filename)
    try:
        import syck
        s = f.read()
        y = syck.load(s)

    except:
        import yaml
        try:
            from yaml import CLoader as Loader
        except ImportError:
            from yaml import Loader

        y = yaml.load(f, Loader=Loader)

    f.close()
    return y
示例#15
0
 def testDuplicateKey(self):
     document = syck.load(DUPLICATE_KEY)
     self.assertEqual(type(document), list)
     self.assertEqual(len(document), 2)
     self.assertEqual(len(document[0]), 2)
     self.assertEqual(len(document[1]), 2)
     self.assertEqual(document[0][0], document[1][0])
示例#16
0
def load_soundset(name):
    set_name = set_dir = None

    for set_name, set_dir in list_soundsets():
        if set_name == name:
            found = True
            break
    else:
        found = False

    if set_dir and found:
        soundset_yaml = set_dir / DESC_FILENAME
    else:
        soundset_yaml = None

    if soundset_yaml is None or not soundset_yaml.isfile():
        raise SoundsetException('soundset %r is missing %r' % (name, DESC_FILENAME))

    # load from YAML file in res dir
    with file(soundset_yaml, 'r') as f:
        soundset = syck.load(f)

    if soundset is None:
        raise SoundsetException('soundset %r is empty' % name)

    # fix contact_signoff -> contact.signoff
    underscores_to_dots(soundset)

    # turn relative paths in YAML to actual paths
    fix_paths(soundset, set_dir)

    return Soundset(soundset)
示例#17
0
 def testTimestamp(self):
     # Again, Syck does not understand the latest two forms.
     #self.assertEqual(syck.load(
     #        '- 2001-12-15T02:59:43.1Z\n'
     #        '- 2001-12-14t21:59:43.10-05:00\n'
     #        '- 2001-12-14 21:59:43.10 -5\n'
     #        '- 2001-12-15 2:59:43.10\n'),
     #    [datetime.datetime(2001, 12, 15, 2, 59, 43, 100000)]*4)
     self.assertEqual(
         syck.load('- 2001-12-15T02:59:43.1Z\n'
                   '- 2001-12-14t21:59:43.10-05:00\n'
                   '- 2001-12-14 21:59:43.10 -05\n'
                   '- 2001-12-15 02:59:43.10 Z\n'),
         [datetime.datetime(2001, 12, 15, 2, 59, 43, 100000)] * 4)
     self.assertEqual(syck.load('2002-12-14'),
                      datetime.datetime(2002, 12, 14))
示例#18
0
 def testMutableKey(self):
     document = syck.load(MUTABLE_KEY)
     self.assertEqual(type(document), list)
     self.assertEqual(len(document), 1)
     self.assertEqual(type(document[0]), tuple)
     self.assertEqual(len(document[0]), 2)
     self.assertEqual(document[0][0], document[0][1])
示例#19
0
    def got_updateyaml(self, req = None, fobj = None):
        '''
        an open fileobject that contains yaml with manifest locations in it.
        '''
        try:
            data = fobj.read()
        except Exception as e:
            return self.manifest_path_error(e)

        try:
            ui = syck.load(data)
        except Exception as e:
            return self.manifest_path_error(e)

        all = ui.get('all', {})
        mine = ui.get(config.platform, None) or {}

        merged = all.copy()
        merged.update(mine)

        manifest_path = merged.get(self.release_type, merged.get('release', None))
        if manifest_path is None:
            self.update_check_error(Exception("No manifest URL for %r in %r" % (self.release_type, all)))
        else:
            log.info("Got manifest path: %r", manifest_path)
            self.remote_manifest_path = manifest_path
            downloader.httpopen(self.remote_manifest_path, method = 'HEAD', success = self.check_manifest_integrity, error = self.manifest_check_error)
示例#20
0
    def prepare_data(self, fast = False):
        Diagnostic.prepare_data(self, fast)

        from path import path

        logdir = path(self.logfilename).parent
        daigpath = logdir/'diag.yaml'

        if daigpath.isfile():
            with open(daigpath, 'r') as diagfile:
                data = syck.load(diagfile)

            # ensure that the process that crashed was the one that wrote the file
            uniquekey = getattr(getattr(sys, 'opts', None), 'crashuniquekey', None)
            if uniquekey is None:
                return

            try:
                uniquekey = int(uniquekey)
            except ValueError:
                uniquekey = None

            if data['uniquekey'] != uniquekey:
                return

            crun = data['args']['crun']
            if self.crashuser is not None and crun != self.crashuser:
                msg = 'ERROR: crash user does not match: %r and %r' % (self.crashuser, crun)
                print >> sys.stderr, msg
                return # don't update with YAML data

            self.prepared_args.update(data['args'])
            self.prepared_files.update(data['files'])
示例#21
0
def load_soundset(name):
    set_name = set_dir = None

    for set_name, set_dir in list_soundsets():
        if set_name == name:
            found = True
            break
    else:
        found = False

    if set_dir and found:
        soundset_yaml = set_dir / DESC_FILENAME
    else:
        soundset_yaml = None

    if soundset_yaml is None or not soundset_yaml.isfile():
        raise SoundsetException('soundset %r is missing %r' %
                                (name, DESC_FILENAME))

    # load from YAML file in res dir
    with file(soundset_yaml, 'r') as f:
        soundset = syck.load(f)

    if soundset is None:
        raise SoundsetException('soundset %r is empty' % name)

    # fix contact_signoff -> contact.signoff
    underscores_to_dots(soundset)

    # turn relative paths in YAML to actual paths
    fix_paths(soundset, set_dir)

    return Soundset(soundset)
示例#22
0
    def got_updateyaml(self, req=None, fobj=None):
        '''
        an open fileobject that contains yaml with manifest locations in it.
        '''
        try:
            data = fobj.read()
        except Exception as e:
            return self.manifest_path_error(e)

        try:
            ui = syck.load(data)
        except Exception as e:
            return self.manifest_path_error(e)

        all = ui.get('all', {})
        mine = ui.get(config.platform, None) or {}

        merged = all.copy()
        merged.update(mine)

        manifest_path = merged.get(self.release_type,
                                   merged.get('release', None))
        if manifest_path is None:
            self.update_check_error(
                Exception("No manifest URL for %r in %r" %
                          (self.release_type, all)))
        else:
            log.info("Got manifest path: %r", manifest_path)
            self.remote_manifest_path = manifest_path
            downloader.httpopen(self.remote_manifest_path,
                                method='HEAD',
                                success=self.check_manifest_integrity,
                                error=self.manifest_check_error)
示例#23
0
 def testScalarTypes(self):
     scalars = syck.load(syck.dump(SCALARS))
     for a, b in zip(scalars, SCALARS):
         self.assertEqual(type(a), type(b))
         if type(a) is float:
             self.assertEqual(repr(a), repr(b))
         else:
             self.assertEqual(a, b)
示例#24
0
 def yaml(self):
     """ The probe data as a decoded YAML data structure """
     if self._yaml is None and HAS_YAML:
         try:
             self._yaml = yaml.load(self.data)
         except YAMLError:
             pass
     return self._yaml
示例#25
0
    def __init__(s, cfgfile):
        s.cfgfile = cfgfile

        f = open(cfgfile, 'r')
        data = f.read()
        f.close()

        s.tree = syck.load(data)
示例#26
0
 def testInteger(self):
     # Syck does not understand '_' and binary integer.
     #self.assertEqual(syck.load(
     #    '- 685230\n- +685_230\n- 02472256\n- 0x_0A_74_AE\n'
     #    '- 0b1010_0111_0100_1010_1110\n- 190:20:30\n'), [685230]*6)
     self.assertEqual(syck.load(
         '- 685230\n- +685230\n- 02472256\n- 0x0A74AE\n'
         '- 190:20:30\n'), [685230]*5)
示例#27
0
 def testInteger(self):
     # Syck does not understand '_' and binary integer.
     #self.assertEqual(syck.load(
     #    '- 685230\n- +685_230\n- 02472256\n- 0x_0A_74_AE\n'
     #    '- 0b1010_0111_0100_1010_1110\n- 190:20:30\n'), [685230]*6)
     self.assertEqual(syck.load(
         '- 685230\n- +685230\n- 02472256\n- 0x0A74AE\n'
         '- 190:20:30\n'), [685230]*5)
示例#28
0
    def updatesite(self):
        if self._updatesite is None:
            try:
                self._updatesite = syck.load((self.local_path / 'index.yaml').open())['source']
            except Exception:
                raise Exception('Unknown source site for %r', self)

        return self._updatesite
示例#29
0
def wkstats():
    '''Returns a dictionary of WebKit memory statistics.'''

    from cStringIO import StringIO
    import wx.webview
    import syck

    return syck.load(StringIO(wx.webview.WebView.GetStatistics().encode('utf-8')))
示例#30
0
 def yaml(self):
     """ The probe data as a decoded YAML data structure """
     if self._yaml is None and HAS_YAML:
         try:
             self._yaml = yaml.load(self.data)
         except YAMLError:
             pass
     return self._yaml
示例#31
0
def wkstats():
    '''Returns a dictionary of WebKit memory statistics.'''

    from cStringIO import StringIO
    import wx.webview
    import syck

    return syck.load(
        StringIO(wx.webview.WebView.GetStatistics().encode('utf-8')))
示例#32
0
文件: feature.py 项目: sgricci/digsby
    def updatesite(self):
        if self._updatesite is None:
            try:
                self._updatesite = syck.load(
                    (self.local_path / 'index.yaml').open())['source']
            except Exception:
                raise Exception('Unknown source site for %r', self)

        return self._updatesite
示例#33
0
    def LoadKeys(self, filepath):
        'Loads a set of keyboard shortcuts from a YAML file.'

        addkey = self.AddKeyboardShortcut
        import syck

        with open(filepath) as f:
            for actionname, accels in flatten(merge_keys(syck.load(f))):
                addkey(actionname, accels)
示例#34
0
    def LoadKeys(self, filepath):
        'Loads a set of keyboard shortcuts from a YAML file.'

        addkey = self.AddKeyboardShortcut
        import syck

        with open(filepath) as f:
            for actionname, accels in flatten(merge_keys(syck.load(f))):
                addkey(actionname, accels)
示例#35
0
 def possibleScriptNames(self, packageName, scriptName):
     #packageName = '-'.join(packageName.split('-')[:-1])
     packageInfoPath = os.path.join(mode.serverHome, "packages", "packages.yml")
     data = syck.load(open(packageInfoPath).read())
     scriptNames = data[packageName].get("executables", [])
     possibleCompletions = []
     for i in scriptNames:
         if i.lower().startswith(scriptName.lower()):
             possibleCompletions.append(i)
     return possibleCompletions
示例#36
0
 def testDumpUnicode(self):
     for string, tag in UNICODE_STRINGS:
         #print string
         document = syck.dump(string)
         #print document
         new_tag = syck.parse(document).tag
         new_string = syck.load(document)
         self.assertEqual(string, new_string)
         self.assertEqual(type(string), type(new_string))
         self.assertEqual(tag, new_tag)
示例#37
0
 def testDumpUnicode(self):
     for string, tag in UNICODE_STRINGS:
         #print string
         document = syck.dump(string)
         #print document
         new_tag = syck.parse(document).tag
         new_string = syck.load(document)
         self.assertEqual(string, new_string)
         self.assertEqual(type(string), type(new_string))
         self.assertEqual(tag, new_tag)
示例#38
0
def write_results():
    results = {}
    uas = []
    uastrings = {}
    for item in category_contents_all['.']:
        results[item] = {}

    f = open('%s/results.html' % MISCOUTPUTDIR, 'w')
    f.write(templates['results'])

    if not os.path.exists('results.yaml'):
        print "Can't find results.yaml"
    else:
        for resultset in yaml.load(open('results.yaml').read()):
            #title = "%s (%s)" % (resultset['ua'], resultset['time'])
            title = resultset['name']
            #assert title not in uas # don't allow repetitions
            if title not in uas:
                uas.append(title)
                uastrings[title] = resultset['ua']
            else:
                assert uastrings[title] == resultset['ua']
            for r in resultset['results']:
                if r['id'] not in results:
                    print 'Skipping results for removed test %s' % r['id']
                    continue
                results[r['id']][title] = (
                    r['status'].lower(),
                    re.sub(
                        r'%(..)', lambda m: chr(int(m.group(1), 16)),
                        re.sub(r'%u(....)',
                               lambda m: unichr(int(m.group(1), 16)),
                               r['notes'])).encode('utf8'))

    passes = {}
    for ua in uas:
        f.write('<th title="%s">%s\n' % (uastrings[ua], ua))
        passes[ua] = 0
    for id in category_contents_all['.']:
        f.write(
            '<tr><td><a href="#%s" id="%s">#</a> <a href="%s.html">%s</a>\n' %
            (id, id, id, id))
        for ua in uas:
            status, details = results[id].get(ua, ('', ''))
            f.write('<td class="r %s"><ul class="d">%s</ul>\n' %
                    (status, details))
            if status == 'pass': passes[ua] += 1
    f.write('<tr><th>Passes\n')
    for ua in uas:
        f.write('<td>%.1f%%\n' %
                ((100.0 * passes[ua]) / len(category_contents_all['.'])))
    f.write('<tr><td>\n')
    for ua in uas:
        f.write('<td>%s\n' % ua)
    f.write('</table>\n')
示例#39
0
def init_portable():
    import syck
    with open(__res_dir() / "portable.yaml") as f:
        usb_info = syck.load(f)

    for name in usb_info.keys():
        usb_info[name] = path(usb_info[name]).abspath()

    _set_paths(**usb_info)

    return usb_info
示例#40
0
 def set_default_properties(self):
     """ Set default properties from config files.
     """
     modname = self.__module__.split('.')[-1]
     config = None
     pkg_path = os.path.abspath('actors/config') + \
             '/' + modname + '.' + PkgDeviceActor._get_desktop()
     try:
         config = syck.load(open(pkg_path).read())
     except Exception, e:
         print e
 def set_default_properties(self):
     """ Set default properties from config files.
     """
     modname = self.__module__.split('.')[-1]
     config = None
     pkg_path = os.path.abspath('actors/config') + \
             '/' + modname + '.' + PkgDeviceActor._get_desktop()
     try:
         config = syck.load(open(pkg_path).read())
     except Exception, e:
         print e
示例#42
0
def readData(files):
    global inputData
    global dataOrder
    def _getVal(name):
    	_v = name.rsplit("_", 1)[1]
	_v = _v.rsplit(".", 2)[0]
	return float(_v)
    _inputData = dict((_getVal(_f), syck.load(file(_f)))
    	for _f in _dataFiles
    )
    # return inputData, dataOrder
    return (_inputData, sorted(_inputData.keys()))
示例#43
0
def write_results():
    results = {}
    uas = []
    uastrings = {}
    for item in category_contents_all["."]:
        results[item] = {}

    f = open("%s/results.html" % MISCOUTPUTDIR, "w")
    f.write(templates["results"])

    if not os.path.exists("results.yaml"):
        print "Can't find results.yaml"
    else:
        for resultset in yaml.load(open("results.yaml").read()):
            # title = "%s (%s)" % (resultset['ua'], resultset['time'])
            title = resultset["name"]
            # assert title not in uas # don't allow repetitions
            if title not in uas:
                uas.append(title)
                uastrings[title] = resultset["ua"]
            else:
                assert uastrings[title] == resultset["ua"]
            for r in resultset["results"]:
                if r["id"] not in results:
                    print "Skipping results for removed test %s" % r["id"]
                    continue
                results[r["id"]][title] = (
                    r["status"].lower(),
                    re.sub(
                        r"%(..)",
                        lambda m: chr(int(m.group(1), 16)),
                        re.sub(r"%u(....)", lambda m: unichr(int(m.group(1), 16)), r["notes"]),
                    ).encode("utf8"),
                )

    passes = {}
    for ua in uas:
        f.write('<th title="%s">%s\n' % (uastrings[ua], ua))
        passes[ua] = 0
    for id in category_contents_all["."]:
        f.write('<tr><td><a href="#%s" id="%s">#</a> <a href="%s.html">%s</a>\n' % (id, id, id, id))
        for ua in uas:
            status, details = results[id].get(ua, ("", ""))
            f.write('<td class="r %s"><ul class="d">%s</ul>\n' % (status, details))
            if status == "pass":
                passes[ua] += 1
    f.write("<tr><th>Passes\n")
    for ua in uas:
        f.write("<td>%.1f%%\n" % ((100.0 * passes[ua]) / len(category_contents_all["."])))
    f.write("<tr><td>\n")
    for ua in uas:
        f.write("<td>%s\n" % ua)
    f.write("</table>\n")
示例#44
0
    def get_packages(module_name):
        """ Return packages for an actor.

        Return packages for an actor based on actors/config/* files and on
        user's desktop.
        """
        pkg_path = os.path.abspath('actors/config') + \
                '/' + module_name + '.' + PkgDeviceActor._get_desktop()
        config = {}
        try:
            config = syck.load(open(pkg_path).read())
        except Exception, e:
            pass
示例#45
0
def yaml_load(fname):
    import syck as yaml
    with closing(zipopen(fname)) as f:
        modulefier = util.primitives.mapping.dictrecurse(lambda x: YAMLModule(fname, x))

        raw_values = yaml.load(f)
        if not isinstance(raw_values, dict):
            val = dict(__content__=raw_values)
        else:
            val = raw_values
        mod = modulefier(val)
        mod.__content__ = raw_values # in case it was a dictionary.
        return mod
    def get_packages(module_name):
        """ Return packages for an actor.

        Return packages for an actor based on actors/config/* files and on
        user's desktop.
        """
        pkg_path = os.path.abspath('actors/config') + \
                '/' + module_name + '.' + PkgDeviceActor._get_desktop()
        config = {}
        try:
            config = syck.load(open(pkg_path).read())
        except Exception, e:
            pass
示例#47
0
 def yaml(self):
     if self._yaml is None:
         if has_yaml:
             try:
                 self._yaml = yaml.load(self.data)
             except yaml.YAMLError:
                 pass
         elif has_syck:
             try:
                 self._yaml = syck.load(self.data)
             except syck.error:
                 pass
     return self._yaml
示例#48
0
文件: Probes.py 项目: m4z/bcfg2
 def yaml(self):
     if self._yaml is None:
         if has_yaml:
             try:
                 self._yaml = yaml.load(self.data)
             except yaml.YAMLError:
                 pass
         elif has_syck:
             try:
                 self._yaml = syck.load(self.data)
             except syck.error:
                 pass
     return self._yaml
def test_file(filename):
  """Runs the Ts and Tp tests on the given config file and generates a report.
  
  Args:
    filename: the name of the file to run the tests on
  """
  
  test_configs = []
  test_names = []
  title = ''
  filename_prefix = ''
  
  # Read in the profile info from the YAML config file
  config_file = open(filename, 'r')
  yaml = syck.load(config_file)
  config_file.close()
  for item in yaml:
    if item == 'title':
      title = yaml[item]
    elif item == 'filename':
      filename_prefix = yaml[item]
    else:
      new_config = [yaml[item]['preferences'],
                    yaml[item]['extensions'],
                    yaml[item]['firefox']]
      test_configs.append(new_config)
      test_names.append(item)
  config_file.close()
  
  # Run startup time test
  ts_times = ts.RunStartupTests(paths.BASE_PROFILE_DIR,
                                test_configs,
                                TS_NUM_RUNS)
  
  # Run page load test.  For possible values of counters argument, see
  # http://technet2.microsoft.com/WindowsServer/en/Library/86b5d116-6fb3-427b-af8c-9077162125fe1033.mspx?mfr=true
  (tp_times, tp_counters) = tp.RunPltTests(paths.BASE_PROFILE_DIR,
                                           test_configs,
                                           TP_NUM_CYCLES,
                                           ['Private Bytes', 'Working Set', '% Processor Time'],
                                           TP_RESOLUTION)
  
  # Generate a report of the results.
  report.GenerateReport(title,
                        filename_prefix,
                        test_names,
                        ts_times,
                        tp_times,
                        tp_counters,
                        TP_RESOLUTION)
示例#50
0
文件: v0.py 项目: sgricci/digsby
    def load_from_disk(self):
        path = self.get_splash_data_path()
        try:
            with open(path, 'rb') as f:
                all_info = syck.load(f)

            if not isinstance(all_info, dict):
                all_info = {}

            info = all_info.get('users', self.info_default)
            last = all_info.get('last', self.last_default)
            self.crypt_pws(info, 'decode')
        except Exception, _e:
            traceback.print_exc()
示例#51
0
 def testFloat(self):
     self.assertEqual(syck.load('6.8523015e+5'), 685230.15)
     # Syck does not understand '_'.
     #self.assertAlmostEqual(syck.load('685.230_15e+03'), 685230.15)
     #self.assertAlmostEqual(syck.load('685_230.15'), 685230.15)
     self.assertEqual(syck.load('685.23015e+03'), 685230.15)
     self.assertEqual(syck.load('685230.15'), 685230.15)
     self.assertEqual(syck.load('190:20:30.15'), 685230.15)
     self.assertEqual(repr(syck.load('-.inf')), repr(-INF))
     self.assertEqual(repr(syck.load('.nan')), repr(NAN))
示例#52
0
def load_yaml(str_or_path):
    from gui.skin import SkinStorage

    bytes, fpath = getcontent(str_or_path)
    if isinstance(bytes, unicode):
        bytes = bytes.encode('utf-8')

    if not bytes:
        raise SkinException('no bytes in ' + str_or_path)

    content = load_yaml_content(bytes)

    try:
        root = syck.load(content)
    except syck.error, e:
        raise SkinException(syck_error_message(e, fpath))
示例#53
0
def get_client_tag():
    if getattr(sys, 'DEV', False):
        tag = ''
    else:
        tag = 'release'

    tag_fname = 'tag.yaml'
    for fpath in ((stdpaths.userlocaldata / tag_fname),
                  (util.program_dir() / tag_fname)):
        try:
            # If the location or name of this file changes, also update the installer (DigsbyInstaller/DigsbyInstall.nsi)
            # since it deletes it.
            with open(fpath, 'rb') as f:
                yaml = syck.load(f)
                tag = yaml['tag']

        except Exception, e:
            log.debug('Didn\'t get a release tag from %r: %r', fpath, e)
        else:
            log.info("Got release tag %r from %r", tag, fpath)
            break
示例#54
0
def defaultprefs():
    '''
    Returns the default prefs as a Storage object
    '''
    import prefs
    import stdpaths
    import config

    the_prefs = util.Storage()

    resdir = os.path.join(util.program_dir(), 'res')
    filenames = [
        os.path.join(resdir, 'defaults.yaml'),
        os.path.join(resdir, config.platformName, 'defaults.yaml'),
        stdpaths.config / 'prefs.yaml',
        stdpaths.userdata / 'prefs.yaml',
    ]

    for filename in filenames:
        info('loading prefs from %r', filename)

        try:
            with open(filename, 'rb') as f:
                prefdict = syck.load(f)
        except Exception, e:
            log.info('Error loading prefs from %r: %r', filename, e)
            continue

        if not isinstance(prefdict, dict):
            continue

        if not sys.DEV:
            prefdict.pop('debug', None)

        prefdict = prefs.flatten(prefdict)
        the_prefs.update(prefdict)
示例#55
0
class TestValuesAndSources(test_parser.TestValuesAndSources):
    def testValues1(self):
        self._testValues(test_parser.COMPARE1)

    def testValues2(self):
        self._testValues(test_parser.COMPARE2)

    def testValues3(self):
        self._testValues(test_parser.COMPARE3)

    def testFileValues1(self):
        self._testFileValues(test_parser.COMPARE1)

    def testFileValues2(self):
        self._testFileValues(test_parser.COMPARE2)

    def testFileValues3(self):
        self._testFileValues(test_parser.COMPARE3)

    def testNonsense(self):
        class MyFile1:
            def read(self, max_length):
                return ' ' * (max_length + 1)

        class MyFile2:
            def read(self, max_length):
                return None

        self.assertRaises(ValueError, lambda: syck.parse(MyFile1()))
        self.assertRaises(ValueError, lambda: syck.load(MyFile1()))
        self.assertRaises(TypeError, lambda: syck.parse(MyFile2()))
        self.assertRaises(TypeError, lambda: syck.load(MyFile2()))

    def _testValues(self, (source, structure)):
        self.assertEqualStructure(syck.parse(source), structure)
        self.assertEqual(syck.load(source), structure)