Example #1
0
def run(mainframe, x):
    from modules.EasyGuider import EasyCommander, EasyUtils
    easy = EasyCommander.EasyCommander(parent=mainframe, easyfile='easyPlugin.py', inline=True, cmdoption='', outputencoding=x.options.encoding)
    if easy.run():
        values = easy.GetValue()
        var = {'text':{}}
        d = var['text']
        d.update({
            'pin_author':values['pin_author'],
            'pin_name':values['pin_name'],
            'pin_email':values['pin_email'],
            'pin_date':values['pin_date'],
            'pin_version':values['pin_version'],
            'pin_description':values['pin_description'],
            'pin_homepage':values['pin_homepage'],

        })
        d['neweditpath'] = mainframe.workpath
        if values['modules_info']:
            d['modules_names'] = values['modules_info']
            d['modules_info'] = values['modules_info']
        else:
            d['modules'] = []

        from meteor import TemplateScript, Template
        from StringIO import StringIO
        buf = StringIO()
        template = Template()
        template.load('plugin.script', 'text')
        buf.write(template.value('text', EasyUtils.str_object(var)))
        buf.seek(0)
        ts = TemplateScript()
        ts.run(buf, var)

        return True
Example #2
0
def run(mainframe, x):
    from modules.EasyGuider import EasyCommander, EasyUtils
    easy = EasyCommander.EasyCommander(parent=mainframe, easyfile='easyPlugin.py', inline=True, cmdoption='', outputencoding=x.options.encoding)
    if easy.run():
        values = easy.GetValue()
        var = {'text':{}}
        d = var['text']
        d.update({
            'pin_author':values['pin_author'],
            'pin_name':values['pin_name'],
            'pin_email':values['pin_email'],
            'pin_date':values['pin_date'],
            'pin_version':values['pin_version'],
            'pin_description':values['pin_description'],
            'pin_homepage':values['pin_homepage'],

        })
        d['neweditpath'] = mainframe.workpath
        if values['modules_info']:
            d['modules_names'] = values['modules_info']
            d['modules_info'] = values['modules_info']
        else:
            d['modules'] = []

        from meteor import TemplateScript, Template
        from StringIO import StringIO
        buf = StringIO()
        template = Template()
        template.load('plugin.script', 'text')
        buf.write(template.value('text', EasyUtils.str_object(var)))
        buf.seek(0)
        ts = TemplateScript()
        ts.run(buf, var)

        return True
Example #3
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
Example #4
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