def readnicklist(): global nick nick = DictIni() nick.setfilename("nicklist.ini") nick.read("nicklist.ini")
def readconfig(): global conf conf = DictIni() #general config conf.general.server = 'jiwai.de' conf.general.resource = 'chat' conf.general.private = 0 conf.general.hide_status = 0 conf.general.debug = 1 conf.general.configencoding = 'utf-8' conf.general.sysprompt = '***' conf.general.logpath = '' conf.general.language = '' conf.general.logfileformat = '%Y%m%d' conf.general.status = 'Ready' if len(sys.argv)>1: conf.setfilename(sys.argv[1]) conf.read(sys.argv[1]) else: conf.setfilename("gtalk.ini") conf.read("gtalk.ini") #encoding convert encoding = conf.general.configencoding conf.general.topic = conf.general.topic conf.general.status = conf.general.status for key, value in conf.emotes.items(): conf.emotes[key] = value
def _populate(self): """ Load the inifile with the package names and description """ pkg_dict = DictIni(self.inifile) for section, packages in pkg_dict.items(): for pkg_name, pkg_description in packages.iteritems(): if self.cache.has_key(pkg_name): pkg = self.cache[pkg_name] if pkg.is_installed: status = 2 else: status = 0 else: pkg = None status = 1 print("This package : '%s:%s' isn't available in your \ configured repositories" % (pkg_name, pkg_description)) self.packages.append( {'name':pkg_name, 'description':pkg_description, 'package':pkg, 'status':status, 'section':section}) self.packages = sorted(self.packages, key=lambda a:a['status']) self.reset()
def initParameter(self): # ini: (1) file: names(list), savedir, datadir; # (2) parameter: current, repeat, sequence(list) try: self.ini = DictIni('segment.ini') if not os.path.exists(self.ini.file.savedir): os.mkdir(self.ini.file.savedir) return False except Exception: return True
def getlocale(): if len(sys.argv) > 1: conf = DictIni(sys.argv[1]) else: conf = DictIni("confbot.ini") try: loc = conf.general['language'] except: loc = '' if not loc: loc = locale.getdefaultlocale()[0] if loc is None: loc = 'en' return loc
def readconfig(): global conf, userinfo conf = DictIni() #======================= #= General Config conf.general.server = 'gmail.com' conf.general.resource = 'conference' conf.general.private = 0 conf.general.hide_status = 0 conf.general.debug = 1 conf.general.configencoding = 'utf-8' conf.general.sysprompt = '***' conf.general.logpath = 'logs' conf.general.language = '' conf.general.status = _('Ready') conf.general.maxnicklen = 10 conf.general.floodback = 0 if len(sys.argv) > 1: conf.setfilename(sys.argv[1]) conf.read(sys.argv[1]) else: conf.setfilename("config.ini") conf.read("config.ini") #get real value readoptionorprompt('general', "account", _("What is the account name of your bot:")) readoptionorprompt('general', "password", _("What is the password of your bot:")) readoptionorprompt('general', "topic", _("Write a short description about your bot:")) #encoding convert encoding = conf.general.configencoding conf.general.sysprompt = i18n.Unicode(conf.general.sysprompt, encoding) conf.general.topic = i18n.Unicode(conf.general.topic, encoding) conf.general.status = i18n.Unicode(conf.general.status, encoding) for key, flags in conf.userinfo.items(): if 'super' in flags: break else: print _("Input super admin email account:"), admin = raw_input().lower() conf.userinfo[admin] = ['user', 'super'] userinfo = conf.userinfo
def __init__(self): super(SettingWindow, self).__init__() self.setupUi(self) self.msgLabel = QtGui.QLabel() self.msgLabel.setMinimumSize(self.msgLabel.sizeHint()) self.msgLabel.setAlignment(QtCore.Qt.AlignHCenter) self.msgLabel.setStyleSheet("QLabel{padding-left: 8px}") self.statusbar.addWidget(self.msgLabel) self.actionInit.triggered.connect(self.initParameter) self.actionMean.triggered.connect(self.saveMeanContour) self.ini = DictIni('segment.ini')
def readconfig(): global conf, welcome, userinfo conf = DictIni() #general config conf.general.server = 'gmail.com' conf.general.resource = 'conference' conf.general.private = 0 conf.general.hide_status = 0 conf.general.debug = 1 conf.general.configencoding = 'utf-8' conf.general.sysprompt = '***' conf.general.logpath = '' conf.general.language = '' conf.general.logfileformat = '%Y%m%d' conf.general.status = _('Ready') #general emotes conf.emotes.cry = _('cries') conf.emotes.jump = _('jumps') conf.emotes.hop = _('hops') conf.emotes.sigh = _('sighs') conf.emotes.fart = _('farts') conf.emotes.smile = _('smiles') conf.emotes.keeldie = _('keels over and dies') conf.emotes.clap = _('claps') conf.emotes.laugh = _('laughs') if len(sys.argv)>1: conf.setfilename(sys.argv[1]) conf.read(sys.argv[1]) else: conf.setfilename("confbot.ini") conf.read("confbot.ini") #get real value readoptionorprompt('general', "account", _("What is the account name of your bot:")) readoptionorprompt('general', "password", _("What is the password of your bot:")) readoptionorprompt('general', "topic", _("Write a short description about your bot:")) #encoding convert encoding = conf.general.configencoding conf.general.sysprompt = i18n.Unicode(conf.general.sysprompt, encoding) conf.general.topic = i18n.Unicode(conf.general.topic, encoding) conf.general.status = i18n.Unicode(conf.general.status, encoding) for key, value in conf.emotes.items(): conf.emotes[key] = i18n.Unicode(value, encoding) for key, flags in conf.userinfo.items(): if 'super' in flags: break else: print _("Input super admin email account:"), admin = raw_input() conf.userinfo[admin] = ['user', 'super'] #deal with welcome message if os.path.exists('welcome.txt'): welcome = unicode(file('welcome.txt').read(), encoding) userinfo = conf.userinfo
ask = dict.ask[str(i)] exp += "<li>%s" % ask["question"] exp += "<SUP>正确答案::%s</SUP>" % ask["key"] #unicode(str(dict.ask[i]["question"]), "utf8").encode("utf8") exp += "<ul>" qk = [j for j in ask.keys()] qk.sort() #name="animal[]" for q in qk: if 1 == len(q): exp += "<li>%s" % ask[q] else: pass exp += "</ul>" exp += "</li>" exp += "</ul>" exp += "</div>" # id=qpage return exp open(pubq, "w").write(QUERY["cfgfile"]) qcfg = DictIni(cfgf) print expage(qcfg) print "<hr/>" # 测试... #print dir() #print QUERY["cfgfile"] #print qcfg.desc
class MainWindow(QtGui.QMainWindow, Ui_SegmentationMainWindow): def __init__(self, gui): super(MainWindow, self).__init__() self.gui = gui self.setupUi(self) self.msgLabel = QtGui.QLabel() self.msgLabel.setMinimumSize(self.msgLabel.sizeHint()) self.msgLabel.setAlignment(QtCore.Qt.AlignHCenter) self.msgLabel.setStyleSheet("QLabel{padding-left: 8px}") self.statusbar.addWidget(self.msgLabel) self.actionNext.triggered.connect(self.saveAndNext) self.actionView.triggered.connect(self.viewData) self.error = self.initParameter() if self.error: # There's no valid ini file self.actionNext.setDisabled(True) self.actionView.setDisabled(True) self.loadData(self.ini.parameter.current) self.widgetView = ResultImageView(self) def getData(self, key = None): return self.data def initParameter(self): # ini: (1) file: names(list), savedir, datadir; # (2) parameter: current, repeat, sequence(list) try: self.ini = DictIni('segment.ini') if not os.path.exists(self.ini.file.savedir): os.mkdir(self.ini.file.savedir) return False except Exception: return True def loadData(self, index): if self.error: self.data = None return dataname = self.ini.file.names[self.ini.parameter.sequence[index]] dir = self.ini.file.datadir + dataname data, info = db.loadMatData(dir) dataname = str(index) + '.mat' dir = self.ini.file.savedir + dataname point = db.loadMatPoint(dir) self.data = db.BasicData(data, info, point) def saveData(self, index): self.widgetView.save() dataname = str(index) + '.mat' dir = self.ini.file.savedir + dataname db.saveMatPoint(dir, self.data, self.ini.file.names[self.ini.parameter.sequence[index]]) def saveAndNext(self): self.saveData(self.ini.parameter.current) self.showErrorMessage('Success', 'Save sucessfully!') self.ini.parameter.current += 1 if self.ini.parameter.current < len(self.ini.parameter.sequence): self.loadData(self.ini.parameter.current) self.setQVTKWidget() else: self.showErrorMessage('Congratulation', 'Your task has finished!') self.ini.parameter.current -= 1 def viewData(self): self.saveData(self.ini.parameter.current) items = map(str, range(len(self.ini.parameter.sequence))) item, ok = QtGui.QInputDialog.getItem(self, "Select the data", "Index:", items, self.ini.parameter.current, False) if ok and item: item = int(item) if self.ini.parameter.current != item: self.ini.parameter.current = item self.loadData(self.ini.parameter.current) self.setQVTKWidget() def setQVTKWidget(self): self.widgetView.setWidgetView(self.qvtkWidget) def showMessageOnStatusBar(self, text): self.msgLabel.setText(text) def getMessageOnStatusBar(self): return str(self.msgLabel.text()) def showErrorMessage(self, title, message): QtGui.QMessageBox.information(self, title, message) def show(self): super(MainWindow, self).show() self.setQVTKWidget() if self.error: self.showErrorMessage("File error", "Can't find a valid ini file!") def closeEvent(self, event): self.ini.save() if not self.error: self.saveData(self.ini.parameter.current) event.accept()
# qdesign.py 快捷问卷设计 #!/usr/bin/env python # coding:utf-8 import time, datetime import sys, os, string, re from Cheetah.Template import Template as ctTpl #sys.path.append("/usr/local/www/data/karriweb/src/plugin") # /usr/local/www/data/warder/questionnaire #from karriweb import * #from agentweb import * #from agentsys import * from dict4ini import DictIni #初始化参数集中维护! qpath = "q/" pubq = qpath + "easy051201.cfg" page = open("questionnaire.tmpl", "r").read() vPool = {} vPool['cfgtxt'] = open(pubq, "r").read() txp = ctTpl(page, searchList=[vPool]) print txp #print dir() qcfg = DictIni(pubq) #print len(qcfg) #print qcfg.desc.learn
def readconfig(): global conf, welcome, userinfo conf = DictIni() # general config conf.general.server = "gmail.com" conf.general.resource = "conference" conf.general.private = 0 conf.general.hide_status = 0 conf.general.debug = 1 conf.general.configencoding = "utf-8" conf.general.sysprompt = "***" conf.general.logpath = "" conf.general.language = "" conf.general.logfileformat = "%Y%m%d" conf.general.status = _("Ready") # general emotes conf.emotes.cry = _("cries") conf.emotes.jump = _("jumps") conf.emotes.hop = _("hops") conf.emotes.sigh = _("sighs") conf.emotes.fart = _("farts") conf.emotes.smile = _("smiles") conf.emotes.keeldie = _("keels over and dies") conf.emotes.clap = _("claps") conf.emotes.laugh = _("laughs") if len(sys.argv) > 1: conf.setfilename(sys.argv[1]) conf.read(sys.argv[1]) else: conf.setfilename("confbot.ini") conf.read("confbot.ini") # get real value readoptionorprompt("general", "account", _("What is the account name of your bot:")) readoptionorprompt("general", "password", _("What is the password of your bot:")) readoptionorprompt("general", "topic", _("Write a short description about your bot:")) # encoding convert encoding = conf.general.configencoding conf.general.sysprompt = i18n.Unicode(conf.general.sysprompt, encoding) conf.general.topic = i18n.Unicode(conf.general.topic, encoding) conf.general.status = i18n.Unicode(conf.general.status, encoding) for key, value in conf.emotes.items(): conf.emotes[key] = i18n.Unicode(value, encoding) for key, flags in conf.userinfo.items(): if "super" in flags: break else: print _("Input super admin email account:"), admin = raw_input() conf.userinfo[admin] = ["user", "super"] # deal with welcome message if os.path.exists("welcome.txt"): welcome = unicode(file("welcome.txt").read(), encoding) userinfo = conf.userinfo
This function is to generate a full ini file. The format of ini file: ('segment.ini') [file] datadir = ... savedir = ... [parameter] repeat = ... ''' if not os.path.exists(ini.file.savedir): os.mkdir(ini.file.savedir) namelist = os.listdir(ini.file.datadir) #print namelist ini.file.names = namelist repeat_time = ini.parameter.repeat cnt = len(namelist) ini.parameter.sequence = [] for i in range(repeat_time): ini.parameter.sequence += permutation(cnt).tolist() #print ini.parameter.sequence ini.parameter.current = 0 ini.save() return namelist, repeat_time if __name__ == "__main__": ini = DictIni('segment.ini') initParameter(ini)
def readconfig(): global conf, welcome, userinfo conf = DictIni() #general config conf.general.server = 'gmail.com' conf.general.resource = 'conference' conf.general.private = 0 conf.general.hide_status = 0 conf.general.debug = 1 conf.general.configencoding = 'utf-8' conf.general.sysprompt = '***' conf.general.logpath = '' conf.general.language = '' conf.general.logfileformat = '%Y%m%d' conf.general.status = _('Ready') #general emotes conf.emotes.cry = _('cries') conf.emotes.jump = _('jumps') conf.emotes.hop = _('hops') conf.emotes.sigh = _('sighs') conf.emotes.fart = _('farts') conf.emotes.smile = _('smiles') conf.emotes.keeldie = _('keels over and dies') conf.emotes.clap = _('claps') conf.emotes.laugh = _('laughs') if len(sys.argv) > 1: conf.setfilename(sys.argv[1]) conf.read(sys.argv[1]) else: conf.setfilename("confbot.ini") conf.read("confbot.ini") #get real value readoptionorprompt('general', "account", _("What is the account name of your bot:")) readoptionorprompt('general', "password", _("What is the password of your bot:")) readoptionorprompt('general', "topic", _("Write a short description about your bot:")) #encoding convert encoding = conf.general.configencoding conf.general.sysprompt = i18n.Unicode(conf.general.sysprompt, encoding) conf.general.topic = i18n.Unicode(conf.general.topic, encoding) conf.general.status = i18n.Unicode(conf.general.status, encoding) for key, value in conf.emotes.items(): conf.emotes[key] = i18n.Unicode(value, encoding) for key, flags in conf.userinfo.items(): if 'super' in flags: break else: print _("Input super admin email account:"), admin = raw_input() conf.userinfo[admin] = ['user', 'super'] #deal with welcome message if os.path.exists('welcome.txt'): welcome = unicode(file('welcome.txt').read(), encoding) userinfo = conf.userinfo
class MainWindow(QtGui.QMainWindow, Ui_SegmentationMainWindow): def __init__(self, gui): super(MainWindow, self).__init__() self.gui = gui self.setupUi(self) self.msgLabel = QtGui.QLabel() self.msgLabel.setMinimumSize(self.msgLabel.sizeHint()) self.msgLabel.setAlignment(QtCore.Qt.AlignHCenter) self.msgLabel.setStyleSheet("QLabel{padding-left: 8px}") self.statusbar.addWidget(self.msgLabel) self.actionNext.triggered.connect(self.saveAndNext) self.actionView.triggered.connect(self.viewData) self.error = self.initParameter() if self.error: # There's no valid ini file self.actionNext.setDisabled(True) self.actionView.setDisabled(True) self.loadData(self.ini.parameter.current) self.widgetView = ResultImageView(self) def getData(self, key=None): return self.data def initParameter(self): # ini: (1) file: names(list), savedir, datadir; # (2) parameter: current, repeat, sequence(list) try: self.ini = DictIni('segment.ini') if not os.path.exists(self.ini.file.savedir): os.mkdir(self.ini.file.savedir) return False except Exception: return True def loadData(self, index): if self.error: self.data = None return dataname = self.ini.file.names[self.ini.parameter.sequence[index]] dir = self.ini.file.datadir + dataname data, info = db.loadMatData(dir) dataname = str(index) + '.mat' dir = self.ini.file.savedir + dataname point = db.loadMatPoint(dir) self.data = db.BasicData(data, info, point) def saveData(self, index): self.widgetView.save() dataname = str(index) + '.mat' dir = self.ini.file.savedir + dataname db.saveMatPoint( dir, self.data, self.ini.file.names[self.ini.parameter.sequence[index]]) def saveAndNext(self): self.saveData(self.ini.parameter.current) self.showErrorMessage('Success', 'Save sucessfully!') self.ini.parameter.current += 1 if self.ini.parameter.current < len(self.ini.parameter.sequence): self.loadData(self.ini.parameter.current) self.setQVTKWidget() else: self.showErrorMessage('Congratulation', 'Your task has finished!') self.ini.parameter.current -= 1 def viewData(self): self.saveData(self.ini.parameter.current) items = map(str, range(len(self.ini.parameter.sequence))) item, ok = QtGui.QInputDialog.getItem(self, "Select the data", "Index:", items, self.ini.parameter.current, False) if ok and item: item = int(item) if self.ini.parameter.current != item: self.ini.parameter.current = item self.loadData(self.ini.parameter.current) self.setQVTKWidget() def setQVTKWidget(self): self.widgetView.setWidgetView(self.qvtkWidget) def showMessageOnStatusBar(self, text): self.msgLabel.setText(text) def getMessageOnStatusBar(self): return str(self.msgLabel.text()) def showErrorMessage(self, title, message): QtGui.QMessageBox.information(self, title, message) def show(self): super(MainWindow, self).show() self.setQVTKWidget() if self.error: self.showErrorMessage("File error", "Can't find a valid ini file!") def closeEvent(self, event): self.ini.save() if not self.error: self.saveData(self.ini.parameter.current) event.accept()