Revision: 4302
Author: russblau
Date: 2007-09-15 21:09:42 +0000 (Sat, 15 Sep 2007)
Log Message:
-----------
Remove duplication; bugfix in version.py; convert
casechecker and category.py to save their data in same
directory as user configuration data.
Modified Paths:
--------------
trunk/pywikipedia/casechecker.py
trunk/pywikipedia/category.py
trunk/pywikipedia/config.py
trunk/pywikipedia/interwiki.py
trunk/pywikipedia/version.py
trunk/pywikipedia/welcome.py
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/casechecker.py
===================================================================
--- trunk/pywikipedia/casechecker.py 2007-09-15 19:36:09 UTC (rev 4301)
+++ trunk/pywikipedia/casechecker.py 2007-09-15 21:09:42 UTC (rev 4302)
@@ -42,9 +42,7 @@
# end of console code
-
-
-
+import os
import sys, query, wikipedia, re, codecs
@@ -154,13 +152,20 @@
if len(self.localSuspects) != len(self.latinSuspects):
raise ValueError(u'Suspects must be the same size')
+ if not os.path.isabs(self.wikilogfile):
+ self.wikilogfile = os.path.join(wikipedia.config.base_dir,
+ self.wikilogfile)
try:
self.wikilog = codecs.open(self.wikilogfile, 'a', 'utf-8')
except IOError:
self.wikilog = codecs.open(self.wikilogfile, 'w', 'utf-8')
- self.lclToLatDict = dict([(ord(self.localSuspects[i]), self.latinSuspects[i]) for i in range(len(self.localSuspects))])
- self.latToLclDict = dict([(ord(self.latinSuspects[i]), self.localSuspects[i]) for i in range(len(self.localSuspects))])
+ self.lclToLatDict = dict([(ord(self.localSuspects[i]),
+ self.latinSuspects[i])
+ for i in range(len(self.localSuspects))])
+ self.latToLclDict = dict([(ord(self.latinSuspects[i]),
+ self.localSuspects[i])
+ for i in range(len(self.localSuspects))])
badPtrnStr = u'([%s][%s]|[%s][%s])' % (self.latLtr, self.localLtr, self.localLtr, self.latLtr)
self.badPtrn = re.compile(badPtrnStr)
@@ -487,4 +492,4 @@
bot = CaseChecker()
bot.Run()
finally:
- wikipedia.stopme()
\ No newline at end of file
+ wikipedia.stopme()
Modified: trunk/pywikipedia/category.py
===================================================================
--- trunk/pywikipedia/category.py 2007-09-15 19:36:09 UTC (rev 4301)
+++ trunk/pywikipedia/category.py 2007-09-15 21:09:42 UTC (rev 4302)
@@ -67,7 +67,7 @@
#
# Distributed under the terms of the MIT license.
#
-import re, sys, string, pickle, bz2
+import os, re, sys, string, pickle, bz2
import wikipedia, catlib, config, pagegenerators
# Summary messages
@@ -155,7 +155,9 @@
self.rebuild()
else:
try:
-
+ if not os.path.isabs(filename):
+ filename = os.path.join(wikipedia.config.base_dir,
+ filename)
f = bz2.BZ2File(filename, 'r')
wikipedia.output(u'Reading dump from %s' % filename)
databases = pickle.load(f)
@@ -220,6 +222,8 @@
'''
Saves the contents of the dictionaries superclassDB and catContentDB to disk.
'''
+ if not os.path.isabs(filename):
+ filename = os.path.join(wikipedia.config.base_dir, filename)
wikipedia.output(u'Dumping to %s, please wait...' % filename)
f = bz2.BZ2File(filename, 'w')
databases = {
@@ -674,6 +678,9 @@
def __init__(self, catTitle, catDB, filename = None, maxDepth = 10):
self.catTitle = catTitle
self.catDB = catDB
+ if not os.path.isabs(filename):
+ filename = os.path.join(wikipedia.config.base_dir,
+ filename)
self.filename = filename
# TODO: make maxDepth changeable with a parameter or config file entry
self.maxDepth = maxDepth
@@ -745,10 +752,10 @@
"""
cat = catlib.Category(wikipedia.getSite(), 'Category:' + self.catTitle)
tree = self.treeview(cat)
- if filename:
- wikipedia.output(u'Saving results in %s' % filename)
+ if self.filename:
+ wikipedia.output(u'Saving results in %s' % self.filename)
import codecs
- f = codecs.open(filename, 'a', 'utf-8')
+ f = codecs.open(self.filename, 'a', 'utf-8')
f.write(tree)
f.close()
else:
Modified: trunk/pywikipedia/config.py
===================================================================
--- trunk/pywikipedia/config.py 2007-09-15 19:36:09 UTC (rev 4301)
+++ trunk/pywikipedia/config.py 2007-09-15 21:09:42 UTC (rev 4302)
@@ -417,7 +417,7 @@
print "WARNING: Skipped '%s': writeable by others."%_filename
else:
print "WARNING: Skipped '%s': owned by someone else."%_filename
- del _filemode,_fileuid,_filestatus
+
del os, re
# Test for obsoleted and/or unknown variables.
@@ -451,6 +451,9 @@
console_encoding = 'cp850'
else:
console_encoding = 'iso-8859-1'
+
+# Save base_dir for use by other modules
+base_dir = _base_dir
#
# When called as main program, list all configuration variables
#
@@ -475,4 +478,3 @@
del __sys.modules[__name__].__dict__[__var]
del __var, __sys
-
Modified: trunk/pywikipedia/interwiki.py
===================================================================
--- trunk/pywikipedia/interwiki.py 2007-09-15 19:36:09 UTC (rev 4301)
+++ trunk/pywikipedia/interwiki.py 2007-09-15 21:09:42 UTC (rev 4302)
@@ -1165,7 +1165,7 @@
def dump(self):
site = wikipedia.getSite()
- dumpfn = os.path.join(wikipedia.base_dir,
+ dumpfn = os.path.join(wikipedia.config.base_dir,
'interwiki-dumps',
'interwikidump-%s-%s.txt'
% (site.family.name, site.lang))
@@ -1520,7 +1520,7 @@
if optRestore or optContinue:
site = wikipedia.getSite()
- dumpFileName = os.path.join(wikipedia.base_dir,
+ dumpFileName = os.path.join(wikipedia.config.base_dir,
'interwiki-dumps',
u'interwikidump-%s-%s.txt'
% (site.family.name, site.lang))
Modified: trunk/pywikipedia/version.py
===================================================================
--- trunk/pywikipedia/version.py 2007-09-15 19:36:09 UTC (rev 4301)
+++ trunk/pywikipedia/version.py 2007-09-15 21:09:42 UTC (rev 4302)
@@ -6,9 +6,10 @@
#
__version__ = '$Id$'
-import os.path
+import os
import time
import sys
+import wikipediatools
class ParseError(Exception):
""" Parsing went wrong """
@@ -32,7 +33,7 @@
return {'tag': tag, 'rev': rev, 'date': datestring}
def getversion_svn():
- entries = open(os.path.join(wikipedia.base_dir, '.svn/entries'))
+ entries = open(os.path.join(wikipediatools.get_base_dir, '.svn/entries'))
for i in range(4):
entries.readline()
tag = entries.readline().strip()
@@ -48,7 +49,7 @@
return (tag, rev, date)
def getversion_nightly():
- data = open(os.path.join(wikipedia.base_dir, 'version'))
+ data = open(os.path.join(wikipediatools.get_base_dir(), 'version'))
tag = data.readline().strip()
date = time.strptime(data.readline()[:19],'%Y-%m-%dT%H:%M:%S')
rev = data.readline().strip()
Modified: trunk/pywikipedia/welcome.py
===================================================================
--- trunk/pywikipedia/welcome.py 2007-09-15 19:36:09 UTC (rev 4301)
+++ trunk/pywikipedia/welcome.py 2007-09-15 21:09:42 UTC (rev 4302)
@@ -443,10 +443,10 @@
wikipedia.output(u'Error! - No fileName!')
raise FilenameNotSet("No signature filename specified.")
try:
- f = codecs.open(os.path.join(wikipedia.base_dir, fileSignName), 'r',
+ f = codecs.open(os.path.join(wikipedia.config.base_dir, fileSignName), 'r',
encoding = config.console_encoding)
except:
- f = codecs.open(os.path.join(wikipedia.base_dir, fileSignName), 'r',
+ f = codecs.open(os.path.join(wikipedia.config.base_dir, fileSignName), 'r',
encoding = 'utf-8')
signText = f.read()
f.close()
@@ -623,8 +623,9 @@
welcomer = u'{{subst:Benvenuto}} %s'
welcomed_users = list()
- if savedata == True and os.path.exists(os.path.join(wikipedia.base_dir,
- filename)):
+ if savedata == True and os.path.exists(
+ os.path.join(
+ wikipedia.config.base_dir, filename)):
f = file(filename)
number_user = cPickle.load(f)
yield number_user
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2007-09-15 19:36:09 UTC (rev 4301)
+++ trunk/pywikipedia/wikipedia.py 2007-09-15 21:09:42 UTC (rev 4302)
@@ -132,11 +132,6 @@
# longer needed.
locale.setlocale(locale.LC_ALL, '')
-# Before importing config, determine the user's base directory
-import wikipediatools
-base_dir = wikipediatools.get_base_dir()
-del wikipediatools
-
import config, login
try:
@@ -2435,7 +2430,7 @@
self.setDelay(mindelay)
def logfn(self):
- return os.path.join(base_dir, 'throttle.log')
+ return os.path.join(config.base_dir, 'throttle.log')
def checkMultiplicity(self):
self.lock.acquire()
@@ -3174,7 +3169,7 @@
fam = config.family
try:
# search for family module in the 'families' subdirectory
- sys.path.append(os.path.join(base_dir, 'families'))
+ sys.path.append(os.path.join(config.base_dir, 'families'))
exec "import %s_family as myfamily" % fam
except ImportError:
if fatal:
@@ -3385,7 +3380,7 @@
else:
tmp = '%s-%s-%s-login.data' % (
self.family.name, self.lang, username)
- fn = os.path.join(base_dir, 'login-data', tmp)
+ fn = os.path.join(config.base_dir, 'login-data', tmp)
if not os.path.exists(fn):
self._cookies = None
self.loginStatusKnown = True
@@ -4418,7 +4413,7 @@
#########################
# search for user interface module in the 'userinterfaces' subdirectory
-sys.path.append(os.path.join(base_dir, 'userinterfaces'))
+sys.path.append(os.path.join(config.base_dir, 'userinterfaces'))
exec "import %s_interface as uiModule" % config.userinterface
ui = uiModule.UI()
verbose = 0
@@ -4655,7 +4650,7 @@
if enabled:
if not logname:
logname = '%s.log' % calledModuleName()
- logfn = os.path.join(base_dir, 'logs', logname)
+ logfn = os.path.join(config.base_dir, 'logs', logname)
try:
logfile = codecs.open(logfn, 'a', 'utf-8')
except IOError:
@@ -4932,7 +4927,7 @@
# Special opener in case we are using a site with authentication
if config.authenticate:
import urllib2, cookielib
- COOKIEFILE = os.path.join(base_dir, 'login-data', 'cookies.lwp')
+ COOKIEFILE = os.path.join(config.base_dir, 'login-data', 'cookies.lwp')
cj = cookielib.LWPCookieJar()
if os.path.isfile(COOKIEFILE):
cj.load(COOKIEFILE)