def convertYaml2Xml(inFileName):
    inobj = yaml.loadFile(inFileName)
    out = []
    level = 0
    convertYaml2XmlAux(inobj, level, out)
    outStr = "".join(out)
    sys.stdout.write(outStr)
def convertYaml2Xml(inFileName):
    inobj = yaml.loadFile(inFileName)
    out = []
    level = 0
    convertYaml2XmlAux(inobj, level, out)
    outStr = "".join(out)
    sys.stdout.write(outStr)
Exemple #3
0
def test_app(app):
    """test_app(app)
    
    Tests the application app:
    - a clean sqlite in-memory database is create
    - the applications models are installed
    - the fixtures in path-to-app/fixtures/*.yml are created
    - settings.ROOT_URLCONF is pointed at the applications urls-module
    - the tests in the tests-module are run with doctest.testmod
      given the fixtures and a browser-instance as globals
    """

    # Import application module
    if '.' in app:
        i = app.rfind('.')
        app_name = app[i+1:]
    else:
        app_name = app
    module = __import__(app, None, None, ['*'])

    # Reinitialize database
    db.db.real_close() # this is in effect a 'drop database' with a sqlite :memory: database
    management.init()

    # Install models
    for model in module.models.__all__:
        management.install(meta.get_app(model))

    # Load fixtures
    files = os.path.join(os.path.dirname(module.__file__), 'fixtures', '*.yml')
    fixtures = {}
    for yml in [ yaml.loadFile(f) for f in glob(files) ]:
        models = yml.next()
        
        for model, fixs in models.items():
            model = meta.get_module(app_name, model)
            klass = model.Klass
    
            for name, kwargs in fixs.items():
                obj = create_object(klass, kwargs)
                # Load object from database, this normalizes it.
                fixtures[name] = model.get_object(pk=obj.id)

    # Commit fixtures
    db.db.commit()

    # Munge django.conf.settings.ROOT_URLCONF to point to
    # this apps urls-module,
    settings.ROOT_URLCONF = app + '.urls'

    # Run tests
    module = __import__(app, None, None, ['tests'])
    tests = getattr(module, 'tests', None)
    if tests:
        globs = {
            'browser': Browser(app),
        }
        globs.update(fixtures)
        doctest.testmod(tests, None, globs)
Exemple #4
0
 def __init__(self):
     cp = ConfigParser.ConfigParser()
     cp.read('vellumpb.ini')
     lastmap = cp.get('vellumpb', 'lastmap', None)
     if lastmap is None:
         self.map = None
     else:
         self.map = yaml.loadFile(lastmap).next()
Exemple #5
0
def parse_rules():
    print "Load rules"
    fp = open(options.rules, "r")
    txt = fp.read(-1)
    try:
        s = yaml.loadFile(options.rules)
    #   import syck
    #   s = syck.load(txt)
    except TypeError, e:
        print "%s:%d: (column %d) %s" % \
            (options.rules, e [0], e [1], e [2])
        os.abort ()
def getHtml(yamlfile, countItems, template):
    ydata = list(yaml.loadFile(yamlfile))[0]
    Page.docFactory = loaders.xmlfile(template)

    d = Page(ydata, countItems).renderString()

    output = []
    d.addCallback(cb, output)
    d.addErrback(eb)
    reactor.run()

    return output[0]
Exemple #7
0
 def loadSavedGame(self):
     loaded = yaml.loadFile(fs.saved).next()
     for id, data in loaded.items():
         model = loader.fromDict(data)
         self.models[model] = id
         dispatcher.send(signal=New, sender='realm', model=model)
         for prop, value in data.items():
             if prop == 'TYPE':
                 continue
             dispatcher.send(signal=model, 
                             sender='realm', 
                             property=prop,
                             old=None, 
                             value=value)
Exemple #8
0
 def loadSavedGame(self):
     loaded = yaml.loadFile(fs.saved).next()
     for id, data in loaded.items():
         model = loader.fromDict(data)
         self.models[model] = id
         dispatcher.send(signal=New, sender='realm', model=model)
         for prop, value in data.items():
             if prop == 'TYPE':
                 continue
             dispatcher.send(signal=model,
                             sender='realm',
                             property=prop,
                             old=None,
                             value=value)
	def __init__(self, dirName, rawServer):
		super(FeedStore, self).__init__()
		self.rawServer = rawServer
		self.savePending = False
		self.records = {}
		self.md5s = {}
		self.fileName = os.path.join(dirName, FILE_NAME)
		if not os.path.exists(self.fileName) and os.path.exists(self.fileName + NEW):
			# Previous process must have been killed before .new file was renamed.
			# (highly unlikely, but possible)
			os.rename(self.fileName + NEW, self.fileName)
		if os.path.exists(self.fileName):
			records = yaml.loadFile(self.fileName).next()
			for record in [Record(self, dict) for dict in records]:
				url = record.url
				self.records[url] = record
				self.md5s[md5.new(url).hexdigest()] = url
Exemple #10
0
    def run(self):
        mod = self.mod

        # read config information from imported template module
        if hasattr(mod, "scriptfile") and mod.scriptfile:
            self.scriptfile = mod.scriptfile
        elif hasattr(mod, "templatefile") and mod.templatefile:
            self.templatefile = mod.templatefile
        elif hasattr(mod, "inipickle") and mod.inipickle:
            self.inipickle = mod.inipickle
        elif hasattr(mod, "picklefile") and mod.picklefile:
            self.picklefile = mod.picklefile
        elif hasattr(mod, "outputfile") and mod.outputfile:
            self.outputfile = mod.outputfile
        elif hasattr(mod, "yamlfile") and mod.yamlfile:
            self.yamlfile = mod.yamlfile
            try:
                import yaml
            except:
                self.yamlfile = ""

        if self.picklefile:
            try:
                f = file(self.picklefile)
                import pickle

                self.values = pickle.load(f)
                f.close()
            except:
                self.log.traceback()
        elif self.inipickle:
            try:
                import obj2ini

                self.values = obj2ini.load(self.inipickle)
            except:
                self.log.traceback()
        elif self.yamlfile:
            try:
                import yaml

                self.values = yaml.loadFile(self.yamlfile).next()
            except:
                self.log.traceback()
        self.easy = easy = self.create_easy(mod, self.values)
        if easy.ShowModal() == wx.ID_OK:
            self.values = easy.GetValue()
            if self.picklefile:
                try:
                    import pickle

                    f = file(self.picklefile, "wb")
                    pickle.dump(self.values, f)
                    f.close()
                except:
                    self.log.traceback()
            elif self.inipickle:
                try:
                    import obj2ini

                    obj2ini.dump(self.values, self.inipickle)
                except:
                    self.log.traceback()
            elif self.yamlfile:
                try:
                    import yaml

                    yaml.dumpToFile(file(self.yamlfile, "wb"), self.values)
                except:
                    self.log.traceback()

            if self.scriptfile:
                # cal scriptpath
                SCRIPTPATH = ""
                if hasattr(mod, "__file__"):
                    SCRIPTPATH = os.path.dirname(
                        os.path.abspath(os.path.join(os.path.dirname(mod.__file__), self.scriptfile))
                    )
                # add scriptpath
                # self.values['SCRIPTPATH'] = SCRIPTPATH
                oldworkpath = os.getcwd()
                try:
                    #                    os.chdir(SCRIPTPATH)
                    #                    from meteor import TemplateScript, Template
                    #                    from StringIO import StringIO
                    #                    buf = StringIO()
                    #                    template = Template()
                    #                    template.load(os.path.basename(self.scriptfile), 'text')
                    #                    buf.write(template.value('text', EasyUtils.str_object(self.values, self.outputencoding)))
                    #                    buf.seek(0)
                    #                    ts = TemplateScript()
                    #                    ts.run(buf, self.values, True)
                    if SCRIPTPATH:
                        os.chdir(SCRIPTPATH)
                    from meteor import TemplateScript

                    ts = TemplateScript()
                    ts.run(self.scriptfile, self.values, True)
                finally:
                    os.chdir(oldworkpath)
            #                    if self.verbose:
            #                        print buf.getvalue()
            elif self.templatefile:
                from meteor import Template

                template = Template()
                template.load(self.templatefile)
                if isinstance(self.outputfile, (str, unicode)):
                    f = file(self.outputfile, "wb")
                elif not self.outputfile:
                    f = sys.stdout
                else:
                    f = self.outputfile
                f.write(template.value(values=EasyUtils.str_object(self.values, self.outputencoding)))
            return True
        else:
            return False
Exemple #11
0
    def run(self):
        mod = self.mod

        #read config information from imported template module
        if hasattr(mod, 'scriptfile') and mod.scriptfile:
            self.scriptfile = mod.scriptfile
        elif hasattr(mod, 'templatefile') and mod.templatefile:
            self.templatefile = mod.templatefile
        elif hasattr(mod, 'inipickle') and mod.inipickle:
            self.inipickle = mod.inipickle
        elif hasattr(mod, 'picklefile') and mod.picklefile:
            self.picklefile = mod.picklefile
        elif hasattr(mod, 'outputfile') and mod.outputfile:
            self.outputfile = mod.outputfile
        elif hasattr(mod, 'yamlfile') and mod.yamlfile:
            self.yamlfile = mod.yamlfile
            try:
                import yaml
            except:
                self.yamlfile = ''

        if self.picklefile:
            try:
                f = file(self.picklefile)
                import pickle
                self.values = pickle.load(f)
                f.close()
            except:
                self.log.traceback()
        elif self.inipickle:
            try:
                import obj2ini
                self.values = obj2ini.load(self.inipickle)
            except:
                self.log.traceback()
        elif self.yamlfile:
            try:
                import yaml
                self.values = yaml.loadFile(self.yamlfile).next()
            except:
                self.log.traceback()
        self.easy = easy = self.create_easy(mod, self.values)
        if easy.ShowModal() == wx.ID_OK:
            self.values = easy.GetValue()
            if self.picklefile:
                try:
                    import pickle
                    f = file(self.picklefile, 'wb')
                    pickle.dump(self.values, f)
                    f.close()
                except:
                    self.log.traceback()
            elif self.inipickle:
                try:
                    import obj2ini
                    obj2ini.dump(self.values, self.inipickle)
                except:
                    self.log.traceback()
            elif self.yamlfile:
                try:
                    import yaml
                    yaml.dumpToFile(file(self.yamlfile, 'wb'), self.values)
                except:
                    self.log.traceback()

            if self.scriptfile:
                #cal scriptpath
                SCRIPTPATH = ''
                if hasattr(mod, '__file__'):
                    SCRIPTPATH = os.path.dirname(
                        os.path.abspath(
                            os.path.join(os.path.dirname(mod.__file__),
                                         self.scriptfile)))
                #add scriptpath
                #self.values['SCRIPTPATH'] = SCRIPTPATH
                oldworkpath = os.getcwd()
                try:
                    #                    os.chdir(SCRIPTPATH)
                    #                    from meteor import TemplateScript, Template
                    #                    from StringIO import StringIO
                    #                    buf = StringIO()
                    #                    template = Template()
                    #                    template.load(os.path.basename(self.scriptfile), 'text')
                    #                    buf.write(template.value('text', EasyUtils.str_object(self.values, self.outputencoding)))
                    #                    buf.seek(0)
                    #                    ts = TemplateScript()
                    #                    ts.run(buf, self.values, True)
                    if SCRIPTPATH:
                        os.chdir(SCRIPTPATH)
                    from meteor import TemplateScript
                    ts = TemplateScript()
                    ts.run(self.scriptfile, self.values, True)
                finally:
                    os.chdir(oldworkpath)


#                    if self.verbose:
#                        print buf.getvalue()
            elif self.templatefile:
                from meteor import Template
                template = Template()
                template.load(self.templatefile)
                if isinstance(self.outputfile, (str, unicode)):
                    f = file(self.outputfile, 'wb')
                elif not self.outputfile:
                    f = sys.stdout
                else:
                    f = self.outputfile
                f.write(
                    template.value(values=EasyUtils.str_object(
                        self.values, self.outputencoding)))
            return True
        else:
            return False
Exemple #12
0
def comfile(fn):
    return comyt(yaml.loadFile(fn).next())
Exemple #13
0
 def remote_listAvailableFiles(self):
     return yaml.loadFile(self.lastmap).next()
Exemple #14
0
 def remote_listAvailableFiles(self):
     return yaml.loadFile(self.lastmap).next()