Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.script.migration._conv160.Page Class Reference

List of all members.

Public Member Functions

def __init__
def read
def write
def copy

Public Attributes

 request
 name
 name_old
 page_dir
 current
 editlog
 revlist
 revisions
 attachments
 renames
 is_deleted

Detailed Description

represents a page with all related data 

Definition at line 252 of file _conv160.py.


Constructor & Destructor Documentation

def MoinMoin.script.migration._conv160.Page.__init__ (   self,
  request,
  pages_dir,
  qpagename 
)

Definition at line 254 of file _conv160.py.

00254 
00255     def __init__(self, request, pages_dir, qpagename):
00256         self.request = request
00257         self.name = wikiutil.unquoteWikiname(qpagename)
00258         self.name_old = self.name # renaming: still original name when self.name has the new name
00259         self.page_dir = opj(pages_dir, qpagename)
00260         self.current = None # int current
00261         self.editlog = None # dict (see read_editlog)
00262         self.revlist = None # list of ints (page text revisions)
00263         self.revisions = None # dict int: pagerev obj
00264         self.attachments = None # dict of unicode fname: full path
00265         self.renames = {} # info for renaming pages/attachments


Member Function Documentation

def MoinMoin.script.migration._conv160.Page.copy (   self,
  pages_dir,
  renames 
)

Definition at line 358 of file _conv160.py.

00358 
00359     def copy(self, pages_dir, renames):
00360         self.renames = renames
00361         self.read()
00362         self.write(pages_dir)
00363 

Here is the caller graph for this function:

read a page, including revisions, log, attachments from disk 

Definition at line 266 of file _conv160.py.

00266 
00267     def read(self):
00268         """ read a page, including revisions, log, attachments from disk """
00269         page_dir = self.page_dir
00270         # read current file
00271         current_fname = opj(page_dir, 'current')
00272         if os.path.exists(current_fname):
00273             current_file = file(current_fname, "r")
00274             current_rev = current_file.read()
00275             current_file.close()
00276             try:
00277                 self.current = int(current_rev)
00278             except ValueError:
00279                 print "Error: invalid current file %s, SKIPPING THIS PAGE!" % current_fname
00280                 return
00281         # read edit-log
00282         editlog_fname = opj(page_dir, 'edit-log')
00283         if os.path.exists(editlog_fname):
00284             self.editlog = EditLog(self.request, editlog_fname)
00285         # read page revisions
00286         rev_dir = opj(page_dir, 'revisions')
00287         if os.path.exists(rev_dir):
00288             revlist = listdir(rev_dir)
00289             revlist = [int(rev) for rev in revlist]
00290             revlist.sort()
00291             self.revlist = revlist
00292             self.revisions = {}
00293             for rev in revlist:
00294                 self.revisions[rev] = PageRev(self.request, self.name_old, rev_dir, rev)
00295         # set deleted status
00296         self.is_deleted = not self.revisions or self.current not in self.revisions
00297         # read attachment filenames
00298         attach_dir = opj(page_dir, 'attachments')
00299         if os.path.exists(attach_dir):
00300             self.attachments = {}
00301             attlist = listdir(attach_dir)
00302             for attfile in attlist:
00303                 a = Attachment(self.request, attach_dir, attfile)
00304                 self.attachments[a.name] = a

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.script.migration._conv160.Page.write (   self,
  pages_dir 
)
write a page, including revisions, log, attachments to disk 

Definition at line 305 of file _conv160.py.

00305 
00306     def write(self, pages_dir):
00307         """ write a page, including revisions, log, attachments to disk """
00308         if ('PAGE', self.name) in self.renames:
00309             name_new = self.renames[('PAGE', self.name)]
00310             if name_new != self.name:
00311                 print "Renaming page %r -> %r" % (self.name, name_new)
00312                 self.name_old = self.name
00313                 self.name = name_new
00314         qpagename = wikiutil.quoteWikinameFS(self.name)
00315         page_dir = opj(pages_dir, qpagename)
00316         os.makedirs(page_dir)
00317         # write current file
00318         current = self.current
00319         if current is not None:
00320             if create_rev and not self.is_deleted:
00321                 current += 1
00322             current_fname = opj(page_dir, 'current')
00323             current_file = file(current_fname, "w")
00324             current_str = '%08d\n' % current
00325             current_file.write(current_str)
00326             current_file.close()
00327         # copy edit-log
00328         if self.editlog is not None:
00329             editlog_fname = opj(page_dir, 'edit-log')
00330             self.editlog.copy(editlog_fname, self.renames, deleted=self.is_deleted)
00331         # copy page revisions
00332         if self.revisions is not None:
00333             rev_dir = opj(page_dir, 'revisions')
00334             os.makedirs(rev_dir)
00335             for rev in self.revlist:
00336                 if create_rev:
00337                     self.revisions[rev].copy(rev_dir, self.renames)
00338                 else:
00339                     if int(rev) == self.current:
00340                         self.revisions[rev].copy(rev_dir, self.renames, convert=True)
00341                     else:
00342                         self.revisions[rev].copy(rev_dir, self.renames)
00343             if create_rev and not self.is_deleted:
00344                 self.revisions[rev].copy(rev_dir, self.renames, convert=True, new_rev=rev+1)
00345 
00346         # copy attachments
00347         if self.attachments is not None:
00348             attach_dir = opj(page_dir, 'attachments')
00349             os.makedirs(attach_dir)
00350             for fn, att in self.attachments.items():
00351                 # we have to check for renames here because we need the (old) pagename, too:
00352                 if ('FILE', self.name_old, fn) in self.renames:
00353                     fn_new = self.renames[('FILE', self.name_old, fn)]
00354                     if fn_new != fn:
00355                         print "Renaming file %r %r -> %r" % (self.name_old, fn, fn_new)
00356                         att.name = fn_new
00357                 att.copy(attach_dir)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 263 of file _conv160.py.

Definition at line 259 of file _conv160.py.

Definition at line 260 of file _conv160.py.

Definition at line 295 of file _conv160.py.

Definition at line 256 of file _conv160.py.

Definition at line 257 of file _conv160.py.

Definition at line 258 of file _conv160.py.

Definition at line 264 of file _conv160.py.

Definition at line 255 of file _conv160.py.

Definition at line 262 of file _conv160.py.

Definition at line 261 of file _conv160.py.


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