Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Attributes
GenericSetup.differ.ConfigDiff Class Reference

List of all members.

Public Member Functions

def __init__
def compareDirectories
def compareFiles
def compare

Static Public Attributes

tuple security = ClassSecurityInfo()

Private Attributes

 _lhs
 _rhs
 _missing_as_empty
 _ignore_blanks
 _skip

Detailed Description

Definition at line 91 of file differ.py.


Constructor & Destructor Documentation

def GenericSetup.differ.ConfigDiff.__init__ (   self,
  lhs,
  rhs,
  missing_as_empty = False,
  ignore_blanks = False,
  skip = SKIPPED_FILES 
)

Definition at line 101 of file differ.py.

00101 
00102                 ):
00103         self._lhs = lhs
00104         self._rhs = rhs
00105         self._missing_as_empty = missing_as_empty
00106         self._ignore_blanks=ignore_blanks
00107         self._skip = skip


Member Function Documentation

Definition at line 228 of file differ.py.

00228 
00229     def compare( self ):
00230         return '\n'.join( [str(line) for line in self.compareDirectories()] )
00231 
00232 InitializeClass( ConfigDiff )

Here is the call graph for this function:

Here is the caller graph for this function:

def GenericSetup.differ.ConfigDiff.compareDirectories (   self,
  subdir = None 
)

Definition at line 109 of file differ.py.

00109 
00110     def compareDirectories( self, subdir=None ):
00111 
00112         lhs_files = self._lhs.listDirectory( subdir, self._skip )
00113         if lhs_files is None:
00114             lhs_files = []
00115 
00116         rhs_files = self._rhs.listDirectory( subdir, self._skip )
00117         if rhs_files is None:
00118             rhs_files = []
00119 
00120         added = [ f for f in rhs_files if f not in lhs_files ]
00121         removed = [ f for f in lhs_files if f not in rhs_files ]
00122         all_files = lhs_files + added
00123         all_files.sort()
00124 
00125         result = []
00126 
00127         for filename in all_files:
00128 
00129             if subdir is None:
00130                 pathname = filename
00131             else:
00132                 pathname = '%s/%s' % ( subdir, filename )
00133 
00134             if filename not in added:
00135                 isDirectory = self._lhs.isDirectory( pathname )
00136             else:
00137                 isDirectory = self._rhs.isDirectory( pathname )
00138 
00139             if not self._missing_as_empty and filename in removed:
00140 
00141                 if isDirectory:
00142                     result.append( '** Directory %s removed\n' % pathname )
00143                     result.extend( self.compareDirectories( pathname ) )
00144                 else:
00145                     result.append( '** File %s removed\n' % pathname )
00146 
00147             elif not self._missing_as_empty and filename in added:
00148 
00149                 if isDirectory:
00150                     result.append( '** Directory %s added\n' % pathname )
00151                     result.extend( self.compareDirectories( pathname ) )
00152                 else:
00153                     result.append( '** File %s added\n' % pathname )
00154 
00155             elif isDirectory:
00156 
00157                 result.extend( self.compareDirectories( pathname ) )
00158 
00159                 if ( filename not in added + removed and
00160                     not self._rhs.isDirectory( pathname ) ):
00161 
00162                     result.append( '** Directory %s replaced with a file of '
00163                                    'the same name\n' % pathname )
00164 
00165                     if self._missing_as_empty:
00166                         result.extend( self.compareFiles( filename, subdir ) )
00167             else:
00168                 if ( filename not in added + removed and
00169                      self._rhs.isDirectory( pathname ) ):
00170 
00171                     result.append( '** File %s replaced with a directory of '
00172                                    'the same name\n' % pathname )
00173 
00174                     if self._missing_as_empty:
00175                         result.extend( self.compareFiles( filename, subdir ) )
00176 
00177                     result.extend( self.compareDirectories( pathname ) )
00178                 else:
00179                     result.extend( self.compareFiles( filename, subdir ) )
00180 
00181         return result

Here is the call graph for this function:

Here is the caller graph for this function:

def GenericSetup.differ.ConfigDiff.compareFiles (   self,
  filename,
  subdir = None 
)

Definition at line 183 of file differ.py.

00183 
00184     def compareFiles( self, filename, subdir=None ):
00185 
00186         if subdir is None:
00187             path = filename
00188         else:
00189             path = '%s/%s' % ( subdir, filename )
00190 
00191         lhs_file = self._lhs.readDataFile( filename, subdir )
00192         lhs_time = self._lhs.getLastModified( path )
00193 
00194         if lhs_file is None:
00195             assert self._missing_as_empty
00196             lhs_file = ''
00197             lhs_time = 0
00198 
00199         rhs_file = self._rhs.readDataFile( filename, subdir )
00200         rhs_time = self._rhs.getLastModified( path )
00201 
00202         if rhs_file is None:
00203             assert self._missing_as_empty
00204             rhs_file = ''
00205             rhs_time = 0
00206 
00207         if lhs_file == rhs_file:
00208             diff_lines = []
00209         else:
00210             diff_lines = unidiff( lhs_file
00211                                 , rhs_file
00212                                 , filename_a=path
00213                                 , timestamp_a=lhs_time
00214                                 , filename_b=path
00215                                 , timestamp_b=rhs_time
00216                                 , ignore_blanks=self._ignore_blanks
00217                                 )
00218             diff_lines = list( diff_lines ) # generator
00219 
00220         if len( diff_lines ) == 0: # No *real* difference found
00221             return []
00222 
00223         diff_lines.insert( 0, 'Index: %s' % path )
00224         diff_lines.insert( 1, '=' * 67 )
00225 
00226         return diff_lines

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 105 of file differ.py.

Definition at line 102 of file differ.py.

Definition at line 104 of file differ.py.

Definition at line 103 of file differ.py.

Definition at line 106 of file differ.py.

tuple GenericSetup.differ.ConfigDiff.security = ClassSecurityInfo() [static]

Definition at line 93 of file differ.py.


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