Back to index

moin  1.9.0~rc2
Functions | Variables
MoinMoin.script.old.repair_language Namespace Reference

Functions

def listdir
def repairText
def processPages

Variables

tuple valid_languages = i18n.wikiLanguages()
tuple path = os.path.abspath('pages')
dictionary options = {'verify': 0, 'repair': 1, }

Function Documentation

Return list of files in path, filtering certain files 

Definition at line 60 of file repair_language.py.

00060 
00061 def listdir(path):
00062     """ Return list of files in path, filtering certain files """
00063     names = [name for name in os.listdir(path)
00064              if not name.startswith('.') and
00065              not name.endswith('.pickle') and
00066              name != 'CVS']
00067     return names
00068 

Here is the caller graph for this function:

Process page directory

@param repair: repair or just test

Definition at line 112 of file repair_language.py.

00112 
00113 def processPages(path, repair):
00114     """ Process page directory
00115 
00116     @param repair: repair or just test
00117     """
00118     charset = 'utf-8'
00119 
00120     pages = [p for p in listdir(path) if os.path.isdir(os.path.join(path, p))]
00121     for page in pages:
00122         revdir = os.path.join(path, page, 'revisions')
00123         if not os.path.isdir(revdir):
00124             print 'Error: %s: missing revisions directory' % page
00125             continue
00126 
00127         for rev in listdir(revdir):
00128             revpath = os.path.join(revdir, rev)
00129             # Open file, read text
00130             f = codecs.open(revpath, 'rb', charset)
00131             text = f.read()
00132             f.close()
00133             text, changed = repairText(text)
00134 
00135             if changed and repair:
00136                 # Save converted text
00137                 f = codecs.open(revpath, 'wb', charset)
00138                 f.write(text)
00139                 f.close()
00140                 print 'Repaired %s revision %s' % (page, rev)
00141             elif changed:
00142                 print 'Should repair %s revision %s' % (page, rev)
00143 

Here is the call graph for this function:

Repair page text

We change only this type of lines that currently are in moinmaster
##language:\s*xx

Warning: will not repair the language if there is more text on the
same line, e.g. ##language:fr make it french!

@param text: the page text, unicode
@rtype: 2 tuple, (unicode, int)
@return: text after replacement, lines changed

Definition at line 69 of file repair_language.py.

00069 
00070 def repairText(text):
00071     """ Repair page text
00072 
00073     We change only this type of lines that currently are in moinmaster
00074     ##language:\s*xx
00075 
00076     Warning: will not repair the language if there is more text on the
00077     same line, e.g. ##language:fr make it french!
00078 
00079     @param text: the page text, unicode
00080     @rtype: 2 tuple, (unicode, int)
00081     @return: text after replacement, lines changed
00082     """
00083     lineend = u'\r\n'
00084     needle = u'##language:'
00085     changed = 0
00086 
00087     # Get text lines
00088     lines = text.splitlines()
00089 
00090     # Look in page header
00091     for i in range(len(lines)):
00092         line = lines[i]
00093         if not line.startswith(u'#'):
00094             break # end of header
00095 
00096         if line.startswith(needle):
00097             # Get language from rest of line
00098             lang = line[len(needle):].strip()
00099 
00100             # Validate lang, make new style language processing
00101             # instruction.
00102             if lang in valid_languages:
00103                 line = u'#language %s' % lang
00104                 lines[i] = line
00105                 changed += 1
00106 
00107     if changed:
00108         # Join lines back, make sure there is trailing line end
00109         text = lineend.join(lines) + lineend
00110     return text, changed
00111 

Here is the caller graph for this function:


Variable Documentation

dictionary MoinMoin.script.old.repair_language.options = {'verify': 0, 'repair': 1, }

Definition at line 154 of file repair_language.py.

tuple MoinMoin.script.old.repair_language.path = os.path.abspath('pages')

Definition at line 147 of file repair_language.py.

Definition at line 57 of file repair_language.py.