From 4a5e1bc880e22ee49ffeed91b4dd650365c8cac3 Mon Sep 17 00:00:00 2001 From: emijrp Date: Mon, 5 Mar 2012 11:08:03 +0000 Subject: [PATCH] converting api check and indexphp check to fuctions git-svn-id: https://wikiteam.googlecode.com/svn/trunk@395 31edc4fc-5e31-b4c4-d58b-c8bc928bcb95 --- dumpgenerator.py | 33 +++++++++++++++++++++------------ gui.py | 8 ++++++-- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/dumpgenerator.py b/dumpgenerator.py index a46d388..b646c49 100644 --- a/dumpgenerator.py +++ b/dumpgenerator.py @@ -780,11 +780,7 @@ def getParameters(params=[]): if config['api']: #check api.php - f = urllib.urlopen(config['api']) - raw = f.read() - f.close() - print 'Checking api.php...' - if re.search(r'action=query', raw): + if checkAPI(config['api']): print 'api.php is OK' else: print 'Error in api.php, please, provide a correct path to api.php' @@ -792,16 +788,10 @@ def getParameters(params=[]): if config['index']: #check index.php - req = urllib2.Request(url=config['index'], data=urllib.urlencode({'title': 'Special:Version', }), headers={'User-Agent': getUserAgent()}) - f = urllib2.urlopen(req) - raw = f.read() - f.close() - print 'Checking index.php...' - if re.search(r'(This wiki is powered by|

)', raw): + if checkIndexphp(config['index']): print 'index.php is OK' else: print 'Error in index.php, please, provide a correct path to index.php' - print raw[:500] sys.exit() #calculating path, if not defined by user with --path= @@ -810,6 +800,25 @@ def getParameters(params=[]): return config, other +def checkAPI(api): + f = urllib.urlopen(api) + raw = f.read() + f.close() + print 'Checking api.php...' + if re.search(r'action=query', raw): + return True + return False + +def checkIndexphp(indexphp): + req = urllib2.Request(url=indexphp, data=urllib.urlencode({'title': 'Special:Version', }), headers={'User-Agent': getUserAgent()}) + f = urllib2.urlopen(req) + raw = f.read() + f.close() + print 'Checking index.php...' + if re.search(r'(This wiki is powered by|

)', raw): + return True + return False + def removeIP(raw=''): """ Remove IP from HTML comments """ raw = re.sub(r'\d+\.\d+\.\d+\.\d+', '0.0.0.0', raw) diff --git a/gui.py b/gui.py index 7121731..721eccc 100644 --- a/gui.py +++ b/gui.py @@ -85,10 +85,14 @@ class App: #dump generator tab (1) self.label11 = Label(self.frame1, text="Wiki URL:") self.label11.grid(row=0, column=0) - self.entry11 = Entry(self.frame1, width=20) + self.entry11 = Entry(self.frame1, width=40) self.entry11.grid(row=0, column=1) + self.optionmenu11var = StringVar(self.frame1) + self.optionmenu11var.set("api") + self.optionmenu11 = OptionMenu(self.frame1, self.optionmenu11var, "api", "index.php") + self.optionmenu11.grid(row=0, column=2) self.button11 = Button(self.frame1, text="Check", command=lambda: thread.start_new_thread(self.callback, ()), width=5) - self.button11.grid(row=0, column=2) + self.button11.grid(row=0, column=3) #downloader tab (2) self.label25var = StringVar(self.frame2)