Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes
MoinMoin.script.migration._conv160a.DataConverter Class Reference
Collaboration diagram for MoinMoin.script.migration._conv160a.DataConverter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def pass1
def save_list
def load_list
def pass2
def read_src
def write_dest
def init_dest

Public Attributes

 request
 sdata
 ddata
 pages
 users
 complete
 renames
 complete_fname
 rename_fname1
 rename_fname2
 editlog
 eventlog

Static Public Attributes

string LIST_FIELDSEP = u'|'

Detailed Description

Definition at line 436 of file _conv160a.py.


Constructor & Destructor Documentation

def MoinMoin.script.migration._conv160a.DataConverter.__init__ (   self,
  request,
  src_data_dir,
  dest_data_dir 
)

Definition at line 437 of file _conv160a.py.

00437 
00438     def __init__(self, request, src_data_dir, dest_data_dir):
00439         self.request = request
00440         self.sdata = src_data_dir
00441         self.ddata = dest_data_dir
00442         self.pages = {}
00443         self.users = {}
00444         self.complete = {}
00445         self.renames = {}
00446         self.complete_fname = opj(self.sdata, 'complete.txt')
00447         self.rename_fname1 = opj(self.sdata, 'rename1.txt')
00448         self.rename_fname2 = opj(self.sdata, 'rename2.txt')


Member Function Documentation

Definition at line 564 of file _conv160a.py.

00564 
00565     def init_dest(self):
00566         try:
00567             os.makedirs(self.ddata)
00568         except:
00569             pass
00570         os.makedirs(opj(self.ddata, 'pages'))
00571         os.makedirs(opj(self.ddata, 'user'))
00572         copy_dir(opj(self.sdata, 'plugin'), opj(self.ddata, 'plugin'))
00573         copy_file(opj(self.sdata, 'intermap.txt'), opj(self.ddata, 'intermap.txt'))
00574 
00575 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 504 of file _conv160a.py.

00504 
00505     def load_list(self, fname, what):
00506         f = codecs.open(fname, 'r', 'utf-8')
00507         for line in f:
00508             line = line.rstrip()
00509             if not line:
00510                 continue
00511             t = line.split(self.LIST_FIELDSEP)
00512             rtype, p1, p2, p3 = (t + [None]*3)[:4]
00513             if rtype == u'PAGE':
00514                 what[(str(rtype), p1)] = p2
00515             elif rtype == u'FILE':
00516                 what[(str(rtype), p1, p2)] = p3
00517         f.close()

Here is the caller graph for this function:

First create the rename list - the user has to review/edit it as
    we can't decide about page/attachment names automatically.

Definition at line 449 of file _conv160a.py.

00449 
00450     def pass1(self):
00451         """ First create the rename list - the user has to review/edit it as
00452             we can't decide about page/attachment names automatically.
00453         """
00454         self.read_src()
00455         # pages
00456         for pn, p in self.pages.items():
00457             p.read()
00458             if not p.revisions:
00459                 continue # we don't care for pages with no revisions (trash)
00460             if pn.endswith('/MoinEditorBackup'):
00461                 continue # we don't care for old editor backups
00462             self.complete[('PAGE', pn)] = None
00463             if "_" in pn:
00464                 # log all pagenames with underscores
00465                 self.renames[('PAGE', pn)] = None
00466             if p.attachments is not None:
00467                 for fn in p.attachments:
00468                     try:
00469                         fn_str = fn.encode('ascii')
00470                         log = False # pure ascii filenames are no problem
00471                     except UnicodeEncodeError:
00472                         log = True # this file maybe has a strange representation in wiki markup
00473                     else:
00474                         if ' ' in fn_str or '%' in fn_str: # files with blanks need quoting
00475                             log = True
00476                     self.complete[('FILE', pn, fn)] = None
00477                     if log:
00478                         # log all strange attachment filenames
00479                         fn_str = fn.encode('utf-8')
00480                         self.renames[('FILE', pn, fn)] = None
00481         self.save_list(self.complete_fname, self.complete)
00482         self.save_list(self.rename_fname1, self.renames)

Here is the call graph for this function:

Second, read the (user edited) rename list and do the renamings everywhere. 

Definition at line 518 of file _conv160a.py.

00518 
00519     def pass2(self):
00520         """ Second, read the (user edited) rename list and do the renamings everywhere. """
00521         self.read_src()
00522         #self.load_list(self.complete_fname, self.complete)
00523         self.load_list(self.rename_fname2, self.renames)
00524         self.write_dest()

Here is the call graph for this function:

Definition at line 525 of file _conv160a.py.

00525 
00526     def read_src(self):
00527         # create Page objects in memory
00528         pages_dir = opj(self.sdata, 'pages')
00529         pagelist = listdir(pages_dir)
00530         for qpagename in pagelist:
00531             p = Page(self.request, pages_dir, qpagename)
00532             self.pages[p.name] = p
00533 
00534         # create User objects in memory
00535         users_dir = opj(self.sdata, 'user')
00536         user_re = re.compile(r'^\d+\.\d+(\.\d+)?$')
00537         userlist = listdir(users_dir)
00538         userlist = [f for f in userlist if user_re.match(f)]
00539         for userid in userlist:
00540             u = User(self.request, users_dir, userid)
00541             self.users[u.uid] = u
00542 
00543         # create log objects in memory
00544         self.editlog = EditLog(self.request, opj(self.sdata, 'edit-log'))
00545         self.eventlog = EventLog(self.request, opj(self.sdata, 'event-log'))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 485 of file _conv160a.py.

00485 
00486     def save_list(self, fname, what):
00487         what_sorted = what.keys()
00488         # make sure we have 3-tuples:
00489         what_sorted = [(k + (None, ))[:3] for k in what_sorted]
00490         # we only have python 2.3, thus no cmp keyword for the sort() call,
00491         # thus we need to do it the more complicated way:
00492         what_sorted = [(pn, fn, rtype) for rtype, pn, fn in what_sorted] # shuffle
00493         what_sorted.sort() # sort
00494         what_sorted = [(rtype, pn, fn) for pn, fn, rtype in what_sorted] # shuffle
00495         f = codecs.open(fname, 'w', 'utf-8')
00496         for rtype, pn, fn in what_sorted:
00497             if rtype == 'PAGE':
00498                 line = (rtype, pn, pn)
00499             elif rtype == 'FILE':
00500                 line = (rtype, pn, fn, fn)
00501             line = self.LIST_FIELDSEP.join(line)
00502             f.write(line + u'\n')
00503         f.close()

Here is the caller graph for this function:

Definition at line 546 of file _conv160a.py.

00546 
00547     def write_dest(self):
00548         self.init_dest()
00549         # copy pages
00550         pages_dir = opj(self.ddata, 'pages')
00551         for pn, page in self.pages.items():
00552             if pn.endswith('/MoinEditorBackup'):
00553                 continue # we don't care for old editor backups
00554             page.copy(pages_dir, self.renames)
00555 
00556         # copy users
00557         users_dir = opj(self.ddata, 'user')
00558         for user in self.users.values():
00559             user.copy(users_dir, self.renames)
00560 
00561         # copy logs
00562         self.editlog.copy(opj(self.ddata, 'edit-log'), self.renames)
00563         self.eventlog.copy(opj(self.ddata, 'event-log'), self.renames)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 443 of file _conv160a.py.

Definition at line 445 of file _conv160a.py.

Definition at line 440 of file _conv160a.py.

Definition at line 543 of file _conv160a.py.

Definition at line 544 of file _conv160a.py.

Definition at line 483 of file _conv160a.py.

Definition at line 441 of file _conv160a.py.

Definition at line 446 of file _conv160a.py.

Definition at line 447 of file _conv160a.py.

Definition at line 444 of file _conv160a.py.

Definition at line 438 of file _conv160a.py.

Definition at line 439 of file _conv160a.py.

Definition at line 442 of file _conv160a.py.


The documentation for this class was generated from the following file: