Back to index

moin  1.9.0~rc2
Functions | Variables
MoinMoin.script.old.migration.12_to_13_mig08 Namespace Reference

Functions

def gather_editlog
def gather_pagedirs
def generate_pages
def generate_editlog

Variables

dictionary info = {}
string origdir = 'data.pre-mig8'

Function Documentation

def MoinMoin.script.old.migration.12_to_13_mig08.gather_editlog (   el_from,
  forcepagename = None 
)
this gathers everything that is in edit-log into internal
    data structures, converting to the future format

Definition at line 59 of file 12_to_13_mig08.py.

00059 
00060 def gather_editlog(el_from, forcepagename=None):
00061     """ this gathers everything that is in edit-log into internal
00062         data structures, converting to the future format
00063     """
00064     if not os.path.exists(el_from):
00065         return
00066     for l in open(el_from):
00067         data = l.rstrip('\n').rstrip('\r').split('\t')
00068         while len(data) < 9:
00069             data.append('')
00070         (timestampstr, revstr, action, pagename, ip, host, id, extra, comment) = data
00071 
00072         if forcepagename: # we use this for edit-log in pagedirs (for renamed pages!)
00073             pagename = forcepagename
00074 
00075         if not action: # FIX: sometimes action is empty ...
00076             action = 'SAVE'
00077 
00078         if action in ['ATTNEW', 'ATTDRW', 'ATTDEL', ]:
00079             revstr = '99999999' # FIXES revno
00080             # use reserved value, ATT action doesn't create new rev of anything
00081 
00082         if (comment == '' and extra == '' and id == 'missing editlog entry for this page version') or \
00083            (extra == '' and id == '' and comment == 'missing editlog entry for this page version'):
00084             # FIX omitted field bug on fake entries
00085             comment = 'missing edit-log entry for this revision' # more precise
00086             extra = ''
00087             id = ''
00088 
00089         rev = int(revstr)
00090         data = [timestampstr, rev, action, pagename, ip, host, id, extra, comment]
00091 
00092         entry = info.get(pagename, {})
00093         timestamp = long(timestampstr) # must be long for py 2.2.x
00094         entry[timestamp] = [99999999, data] # new revno, data
00095         info[pagename] = entry

Here is the caller graph for this function:

this gathers edit-log information from the pagedirs, just to make sure

Definition at line 96 of file 12_to_13_mig08.py.

00096 
00097 def gather_pagedirs(dir_from):
00098     """ this gathers edit-log information from the pagedirs, just to make sure
00099     """
00100     pagedir = opj(dir_from, 'pages')
00101     pagelist = listdir(pagedir)
00102     for pagename in pagelist:
00103         editlog_from = opj(pagedir, pagename, 'edit-log')
00104         gather_editlog(editlog_from, pagename)
00105 

Here is the call graph for this function:

Definition at line 173 of file 12_to_13_mig08.py.

00173 
00174 def generate_editlog(dir_from, dir_to):
00175     editlog = {}
00176     for pagename in info:
00177         entry = info.get(pagename, {})
00178         for ts in entry:
00179             file_from, data = entry[ts]
00180             editlog[ts] = data
00181 
00182     tslist = editlog.keys()
00183     tslist.sort()
00184 
00185     editlog_file = opj(dir_to, 'edit-log')
00186     f = open(editlog_file, 'w')
00187     for ts in tslist:
00188         datatmp = editlog[ts][:]
00189         rev = datatmp[1]
00190         datatmp[1] = '%08d' % rev
00191         f.write('\t'.join(datatmp)+'\n')
00192     f.close()
00193 

Definition at line 106 of file 12_to_13_mig08.py.

00106 
00107 def generate_pages(dir_from, dir_to):
00108     revactions = ['SAVE', 'SAVENEW', 'SAVE/REVERT', ] # these actions create revisions
00109     for pn in info:
00110         entry = info.get(pn, {})
00111         tslist = entry.keys()
00112         if tslist:
00113             pagedir = opj(dir_to, 'pages', pn)
00114             revdir = opj(pagedir, 'revisions')
00115             os.makedirs(revdir)
00116             editlog_file = opj(pagedir, 'edit-log')
00117             f = open(editlog_file, 'w')
00118             revnew = 0
00119             tslist.sort()
00120             for ts in tslist:
00121                 data = entry[ts][1]
00122                 datanew = data[:]
00123                 (timestamp, rev, action, pagename, ip, host, id, extra, comment) = data
00124                 revstr = '%08d' % rev
00125                 if action in revactions:
00126                     revnew += 1
00127                     revnewstr = '%08d' % revnew
00128                     entry[ts][0] = revnew # remember what new revno we chose
00129                 else: # ATTNEW,ATTDRW,ATTDEL
00130                     revnewstr = '99999999'
00131                 if action.endswith('/REVERT'):
00132                     # replace the old revno with the correct new revno
00133                     revertrevold = int(extra)
00134                     revertrevnew = 0
00135                     for ts2 in tslist:
00136                         data2 = entry[ts2][1]
00137                         (timestamp2, rev2, action2, pagename2, ip2, host2, id2, extra2, comment2) = data2
00138                         if rev2 == revertrevold:
00139                             revertrevnew = entry[ts2][0]
00140                     datanew[7] = '%08d' % revertrevnew
00141 
00142                 datanew[1] = revnewstr
00143                 f.write('\t'.join(datanew)+'\n') # does make a CRLF on win32 in the file
00144 
00145                 if action in revactions: # we DO have a page rev for this one
00146                     file_from = opj(dir_from, 'pages', pn, 'revisions', revstr)
00147                     file_to = opj(revdir, revnewstr)
00148                     copy_file(file_from, file_to)
00149             f.close()
00150 
00151             # check if page exists or is deleted in orig dir
00152             pagedir_from = opj(dir_from, 'pages', pn)
00153             revdir_from = opj(pagedir_from, 'revisions')
00154             try:
00155                 curr_file_from = opj(pagedir_from, 'current')
00156                 currentfrom = open(curr_file_from).read().strip() # try to access it
00157                 page_exists = 1
00158             except:
00159                 page_exists = 0
00160 
00161             # re-make correct DELETED status!
00162             if page_exists:
00163                 curr_file = opj(pagedir, 'current')
00164                 f = open(curr_file, 'w')
00165                 f.write("%08d\n" % revnew) # we add a \n, so it is easier to hack in there manually
00166                 f.close()
00167 
00168         att_from = opj(dir_from, 'pages', pn, 'attachments')
00169         if os.path.exists(att_from):
00170             att_to = opj(pagedir, 'attachments')
00171             copy_dir(att_from, att_to)
00172 

Here is the call graph for this function:


Variable Documentation

Definition at line 57 of file 12_to_13_mig08.py.

Definition at line 194 of file 12_to_13_mig08.py.