Revision: 4309
Author: russblau
Date: 2007-09-16 16:07:09 +0000 (Sun, 16 Sep 2007)
Log Message:
-----------
Further efforts to standardize access to bot data files.
Modified Paths:
--------------
trunk/pywikipedia/casechecker.py
trunk/pywikipedia/category.py
trunk/pywikipedia/config.py
trunk/pywikipedia/copyright.py
trunk/pywikipedia/interwiki.py
trunk/pywikipedia/welcome.py
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/casechecker.py
===================================================================
--- trunk/pywikipedia/casechecker.py 2007-09-16 14:51:43 UTC (rev 4308)
+++ trunk/pywikipedia/casechecker.py 2007-09-16 16:07:09 UTC (rev 4309)
@@ -153,8 +153,7 @@
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)
+ self.wikilogfile = wikipedia.datafilepath(self.wikilogfile)
try:
self.wikilog = codecs.open(self.wikilogfile, 'a', 'utf-8')
except IOError:
Modified: trunk/pywikipedia/category.py
===================================================================
--- trunk/pywikipedia/category.py 2007-09-16 14:51:43 UTC (rev 4308)
+++ trunk/pywikipedia/category.py 2007-09-16 16:07:09 UTC (rev 4309)
@@ -156,8 +156,7 @@
else:
try:
if not os.path.isabs(filename):
- filename = os.path.join(wikipedia.config.base_dir,
- filename)
+ filename = wikipedia.datafilepath(filename)
f = bz2.BZ2File(filename, 'r')
wikipedia.output(u'Reading dump from %s' % filename)
databases = pickle.load(f)
@@ -223,7 +222,7 @@
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)
+ filename = wikipedia.datafilepath(filename)
wikipedia.output(u'Dumping to %s, please wait...' % filename)
f = bz2.BZ2File(filename, 'w')
databases = {
@@ -679,8 +678,7 @@
self.catTitle = catTitle
self.catDB = catDB
if not os.path.isabs(filename):
- filename = os.path.join(wikipedia.config.base_dir,
- filename)
+ filename = wikipedia.datafilepath(filename)
self.filename = filename
# TODO: make maxDepth changeable with a parameter or config file entry
self.maxDepth = maxDepth
Modified: trunk/pywikipedia/config.py
===================================================================
--- trunk/pywikipedia/config.py 2007-09-16 14:51:43 UTC (rev 4308)
+++ trunk/pywikipedia/config.py 2007-09-16 16:07:09 UTC (rev 4309)
@@ -43,6 +43,7 @@
usernames = {}
sysopnames = {}
disambiguation_comment = {}
+gdab_namespaces = {}
# Some sites will require password identication to access the HTML pages at
# the site. If you have any such site, add lines to your user-config.py of
Modified: trunk/pywikipedia/copyright.py
===================================================================
--- trunk/pywikipedia/copyright.py 2007-09-16 14:51:43 UTC (rev 4308)
+++ trunk/pywikipedia/copyright.py 2007-09-16 16:07:09 UTC (rev 4309)
@@ -86,8 +86,8 @@
# No checks if the page is a disambiguation page.
skip_disambig = True
-appdir = os.path.join(wikipedia.config.base_dir, "copyright")
-output_file = os.path.join(appdir, "output.txt")
+appdir = "copyright"
+output_file = wikipedia.datafilepath(appdir, "output.txt")
pages_for_exclusion_database = [
('it', 'User:RevertBot/Lista_di_esclusione', 'exclusion_list.txt'),
@@ -242,7 +242,7 @@
def exclusion_file_list():
for i in pages_for_exclusion_database:
- path = os.path.join(appdir, i[0], i[2])
+ path = wikipedia.datafilepath(appdir, i[0], i[2])
wikipedia.makepath(path)
p = wikipedia.Page(wikipedia.getSite(i[0]), i[1])
yield p, path
@@ -325,7 +325,7 @@
result_list.append(entry)
result_list += read_file(
- os.path.join(appdir, 'exclusion_list.txt'),
+ wikipedia.datafilepath(appdir, 'exclusion_list.txt'),
cut_comment = True, cut_newlines = True
).splitlines()
@@ -455,7 +455,7 @@
print "** " + entry
def exclusion_list_dump():
- f = open(appdir + 'exclusion_list.dump', 'w')
+ f = open(wikipedia.datafilepath(appdir, 'exclusion_list.dump', 'w'))
f.write('\n'.join(excl_list))
f.close()
print "Exclusion list dump saved."
@@ -851,7 +851,7 @@
% (title.replace(" ", "_").replace("\"", "%22"),
id, "author")
+ output,
- os.path.join(appdir, "ID_output.txt"))
+ wikipedia.datafilepath(appdir, "ID_output.txt"))
class CheckRobot:
def __init__(self, generator):
Modified: trunk/pywikipedia/interwiki.py
===================================================================
--- trunk/pywikipedia/interwiki.py 2007-09-16 14:51:43 UTC (rev 4308)
+++ trunk/pywikipedia/interwiki.py 2007-09-16 16:07:09 UTC (rev 4309)
@@ -208,7 +208,6 @@
#
import sys, copy, re
-import os.path
import time
import codecs
import socket
@@ -1165,10 +1164,9 @@
def dump(self):
site = wikipedia.getSite()
- dumpfn = os.path.join(wikipedia.config.base_dir,
- 'interwiki-dumps',
- 'interwikidump-%s-%s.txt'
- % (site.family.name, site.lang))
+ dumpfn = wikipedia.datafilepath(
+ 'interwiki-dumps',
+ 'interwikidump-%s-%s.txt' % (site.family.name, site.lang))
f = codecs.open(dumpfn, 'w', 'utf-8')
for subj in self.subjects:
f.write(subj.originPage.aslink(None)+'\n')
@@ -1520,10 +1518,10 @@
if optRestore or optContinue:
site = wikipedia.getSite()
- dumpFileName = os.path.join(wikipedia.config.base_dir,
- 'interwiki-dumps',
- u'interwikidump-%s-%s.txt'
- % (site.family.name, site.lang))
+ dumpFileName = wikipedia.datafilepath(
+ 'interwiki-dumps',
+ u'interwikidump-%s-%s.txt'
+ % (site.family.name, site.lang))
hintlessPageGen = pagegenerators.TextfilePageGenerator(dumpFileName)
if optContinue:
# We waste this generator to find out the last page's title
Modified: trunk/pywikipedia/welcome.py
===================================================================
--- trunk/pywikipedia/welcome.py 2007-09-16 14:51:43 UTC (rev 4308)
+++ trunk/pywikipedia/welcome.py 2007-09-16 16:07:09 UTC (rev 4309)
@@ -443,11 +443,11 @@
wikipedia.output(u'Error! - No fileName!')
raise FilenameNotSet("No signature filename specified.")
try:
- f = codecs.open(os.path.join(wikipedia.config.base_dir, fileSignName), 'r',
- encoding = config.console_encoding)
+ f = codecs.open(wikipedia.datafilepath(fileSignName), 'r',
+ encoding=config.console_encoding)
except:
- f = codecs.open(os.path.join(wikipedia.config.base_dir, fileSignName), 'r',
- encoding = 'utf-8')
+ f = codecs.open(wikipedia.datafilepath(fileSignName), 'r',
+ encoding='utf-8')
signText = f.read()
f.close()
@@ -623,9 +623,7 @@
welcomer = u'{{subst:Benvenuto}} %s'
welcomed_users = list()
- if savedata == True and os.path.exists(
- os.path.join(
- wikipedia.config.base_dir, filename)):
+ if savedata == True and os.path.exists(wikipedia.datafilepath(filename)):
f = file(filename)
number_user = cPickle.load(f)
yield number_user
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2007-09-16 14:51:43 UTC (rev 4308)
+++ trunk/pywikipedia/wikipedia.py 2007-09-16 16:07:09 UTC (rev 4309)
@@ -2441,7 +2441,7 @@
self.setDelay(mindelay)
def logfn(self):
- return os.path.join(config.base_dir, 'throttle.log')
+ return datafilepath('throttle.log')
def checkMultiplicity(self):
self.lock.acquire()
@@ -3180,7 +3180,7 @@
fam = config.family
try:
# search for family module in the 'families' subdirectory
- sys.path.append(os.path.join(config.base_dir, 'families'))
+ sys.path.append(datafilepath('families'))
exec "import %s_family as myfamily" % fam
except ImportError:
if fatal:
@@ -3391,7 +3391,7 @@
else:
tmp = '%s-%s-%s-login.data' % (
self.family.name, self.lang, username)
- fn = os.path.join(config.base_dir, 'login-data', tmp)
+ fn = datafilepath('login-data', tmp)
if not os.path.exists(fn):
self._cookies = None
self.loginStatusKnown = True
@@ -4419,12 +4419,40 @@
nonGlobalArgs.append(arg)
return nonGlobalArgs
+def makepath(path):
+ """ creates missing directories for the given path and
+ returns a normalized absolute version of the path.
+
+ - if the given path already exists in the filesystem
+ the filesystem is not modified.
+
+ - otherwise makepath creates directories along the given path
+ using the dirname() of the path. You may append
+ a '/' to the path if you want it to be a directory path.
+
+ from holger(a)trillke.net 2002/03/18
+ """
+ from os import makedirs
+ from os.path import normpath,dirname,exists,abspath
+
+ dpath = normpath(dirname(path))
+ if not exists(dpath): makedirs(dpath)
+ return normpath(abspath(path))
+
+def datafilepath(*filename):
+ """Returns an absolute path to a data file, offset from the bot's
+ base directory.
+ Argument(s) are zero or more directory names, followed by a data file
+ name.
+ """
+ return os.path.join(config.base_dir, *filename)
+
#########################
# Interpret configuration
#########################
# search for user interface module in the 'userinterfaces' subdirectory
-sys.path.append(os.path.join(config.base_dir, 'userinterfaces'))
+sys.path.append(datafilepath('userinterfaces'))
exec "import %s_interface as uiModule" % config.userinterface
ui = uiModule.UI()
verbose = 0
@@ -4636,32 +4664,12 @@
result += diff[i]
output(result)
-def makepath(path):
- """ creates missing directories for the given path and
- returns a normalized absolute version of the path.
-
- - if the given path already exists in the filesystem
- the filesystem is not modified.
-
- - otherwise makepath creates directories along the given path
- using the dirname() of the path. You may append
- a '/' to the path if you want it to be a directory path.
-
- from holger(a)trillke.net 2002/03/18
- """
- from os import makedirs
- from os.path import normpath,dirname,exists,abspath
-
- dpath = normpath(dirname(path))
- if not exists(dpath): makedirs(dpath)
- return normpath(abspath(path))
-
def setLogfileStatus(enabled, logname = None):
global logfile
if enabled:
if not logname:
logname = '%s.log' % calledModuleName()
- logfn = os.path.join(config.base_dir, 'logs', logname)
+ logfn = datafiledpath('logs', logname)
try:
logfile = codecs.open(logfn, 'a', 'utf-8')
except IOError:
@@ -4938,7 +4946,7 @@
# Special opener in case we are using a site with authentication
if config.authenticate:
import urllib2, cookielib
- COOKIEFILE = os.path.join(config.base_dir, 'login-data', 'cookies.lwp')
+ COOKIEFILE = datafilepath('login-data', 'cookies.lwp')
cj = cookielib.LWPCookieJar()
if os.path.isfile(COOKIEFILE):
cj.load(COOKIEFILE)