def PACKAGE(): global DONE_PACKAGE global package global filesystem if DONE_PACKAGE: return 0 SETTINGS() debug.message("scanning package in %s ..." % CONFIG.packageroot()) before = time.time() filesystem = scan_filesystem(path=CONFIG.packageroot().split(os.sep)) if CONFIG.overlayroot() is not None: overlayed_filesystem = scan_filesystem( path=CONFIG.overlayroot().split(os.sep)) filesystem = OverlayFileSystem(original=filesystem, overlay=overlayed_filesystem) pass package = LocalPackage(rootdirectory=filesystem.rootdirectory(), setups=None) DONE_PACKAGE = 1 debug.message('done scanning (' + str(time.time() - before) + ' seconds)') return 0
def test__file_add_lines(self): union = OverlayFileSystem(original=self.first(), overlay=self.second()) first_file = union.rootdirectory().find(['first_file']) second_file = union.rootdirectory().find(['second_file']) first_file.add_lines(['']) try: second_file.add_lines(['']) self.fail() except OverlayFile.AddLinesError: pass pass
def test__file_truncate(self): union = OverlayFileSystem(original=self.first(), overlay=self.second()) first_file = union.rootdirectory().find(['first_file']) second_file = union.rootdirectory().find(['second_file']) first_file.truncate() try: second_file.truncate() self.fail() except OverlayFile.TruncateError: pass pass
def test(self): fs_orig = FileSystem(path=[]) fs_overlay = FileSystem(path=[]) fs_overlay.rootdirectory().add(name='dir', entry=Directory()) fs = OverlayFileSystem(original=fs_orig, overlay=fs_overlay) dir = fs.rootdirectory().get('dir') try: dir.add(name='file', entry=File()) self.fail() except OverlayDirectory.OverlayAddError: pass pass
def test__sync_2(self): union = OverlayFileSystem(original=self.first(), overlay=self.second()) # sync the union; first is synced, and second is not. union.sync() self.failUnless( os.path.exists(os.sep.join( self.first().rootdirectory().abspath()))) self.failUnless( os.path.exists(os.sep.join(self.first_first_file().abspath()))) self.failUnless( os.path.exists(os.sep.join(self.first_subdir().abspath()))) self.failUnless( os.path.exists( os.sep.join(self.first_subdir_first_file().abspath()))) self.failIf( os.path.exists(os.sep.join( self.second().rootdirectory().abspath()))) self.failIf( os.path.exists(os.sep.join(self.second_second_file().abspath()))) self.failIf(os.path.exists(os.sep.join( self.second_subdir().abspath()))) self.failIf( os.path.exists( os.sep.join(self.second_subdir_second_file().abspath()))) # add file and dir here and there, sync and check again. union.rootdirectory().add(name='newfile', entry=File()) newdir = union.rootdirectory().add(name='newdir', entry=Directory()) newdir.add(name='newfile', entry=File()) union.sync() self.failUnless( os.path.exists( os.sep.join(self.first().rootdirectory().abspath() + ['newfile']))) self.failUnless( os.path.exists( os.sep.join(self.first().rootdirectory().abspath() + ['newdir']))) self.failUnless( os.path.exists( os.sep.join(self.first().rootdirectory().abspath() + ['newdir', 'newfile']))) self.failIf( os.path.exists( os.sep.join(self.second().rootdirectory().abspath() + ['newfile']))) self.failIf( os.path.exists( os.sep.join(self.second().rootdirectory().abspath() + ['newdir']))) self.failIf( os.path.exists( os.sep.join(self.second().rootdirectory().abspath() + ['newdir', 'newfile']))) pass
def test__add_file(self): # adding a file to a unioned directory always goes to the # first, and not to the second. union = OverlayFileSystem(original=self.first(), overlay=self.second()) union.rootdirectory().add(name='added_file', entry=File()) # the unioned filesystem must have it at the appropriate # place. self.failUnless(union.rootdirectory().get('added_file')) # the first fs must have received it through the union. self.failUnless(self.first().rootdirectory().get('added_file')) # the second is read only. self.failIf(self.second().rootdirectory().get('added_file')) pass
def test__add_directory(self): union = OverlayFileSystem(original=self.first(), overlay=self.second()) # like file addition above, a directory addition must show up # in union and first, but not on second. union_newdir = union.rootdirectory().add(name='newdir', entry=Directory()) first_newdir = self.first().rootdirectory().get('newdir') self.failUnless(first_newdir) self.failIf(self.second().rootdirectory().get('newdir')) # file and directory addition to union_newdir must show up in # but union_newdir and first_newdir (and cannot show up in # second_newdir because by definition that doesn't exist :-). union_newdir_dir = union_newdir.add(name='dir', entry=File()) union_newdir_file = union_newdir.add(name='file', entry=Directory()) self.failUnless(union_newdir.get('dir')) self.failUnless(union_newdir.get('file')) self.failUnless(first_newdir.get('dir')) self.failUnless(first_newdir.get('file')) pass
def test__abspath(self): union = OverlayFileSystem(original=self.first(), overlay=self.second()) # the path of the union filesystem itself is the first. self.failUnlessEqual(union.path(), self.first().path()) # the abspath of the entries is that of their respective # locations. files cannot exist in both filesystems, thus file # unions have their respective file locationin the underlying # filessystems. union directories have their first path if # they exist in both. if they exist in only one filesystem, # ... blah. # <entries of first> union_first_file = union.rootdirectory().find(['first_file']) self.failIf(union_first_file is None) self.failUnlessEqual(self.first_first_file().abspath(), union_first_file.abspath()) union_subdir = union.rootdirectory().find(['subdir']) self.failIf(union_subdir is None) self.failUnlessEqual(self.first_subdir().abspath(), union_subdir.abspath()) union_subdir_first_file = union.rootdirectory().find( ['subdir', 'first_file']) self.failIf(union_subdir_first_file is None) self.failUnlessEqual(self.first_subdir_first_file().abspath(), union_subdir_first_file.abspath()) # </entries of first> # <entries of second> union_second_file = union.rootdirectory().find(['second_file']) self.failIf(union_second_file is None) self.failUnlessEqual(self.second_second_file().abspath(), union_second_file.abspath()) union_subdir_second_file = union.rootdirectory().find( ['subdir', 'second_file']) self.failIf(union_subdir_second_file is None) self.failUnlessEqual(self.second_subdir_second_file().abspath(), union_subdir_second_file.abspath()) # </entries of second> pass
def test__sync_1(self): # all write access goes to first, and so does sync union = OverlayFileSystem(original=self.first(), overlay=self.second()) union.sync() self.failUnless( os.path.exists(os.sep.join(self.first_first_file().abspath()))) self.failUnless( os.path.exists(os.sep.join(self.first_subdir().abspath()))) self.failUnless( os.path.exists( os.sep.join(self.first_subdir_first_file().abspath()))) self.failIf( os.path.exists(os.sep.join(self.second_second_file().abspath()))) self.failIf(os.path.exists(os.sep.join( self.second_subdir().abspath()))) self.failIf( os.path.exists( os.sep.join(self.second_subdir_second_file().abspath()))) pass
def test__basic(self): # (this one doesn't use anything from the base, it's just # there) # The following tree contains two directories, original and # overlay, where overlay is supposed to be 'overlayed' over # original. That is, the union of both directories contains # ... yes ... what one would expect. # . # |-- original # | `-- root # | `-- d10 # | |-- d20 # | `-- f0 # `-- overlayed # `-- root # |-- d10 # | |-- d20 # | `-- f1 # `-- d11 original = FileSystem(path=['dont', 'care', 'original']) original_d10 = original.rootdirectory().add(name='d10', entry=Directory()) original_d10.add(name='f0', entry=File()) original_d20 = original_d10.add(name='d20', entry=Directory()) overlay = FileSystem(path=['dont', 'care', 'overlay']) overlay_d10 = overlay.rootdirectory().add(name='d10', entry=Directory()) overlay_d10.add(name="f1", entry=File()) overlay_d10.add(name='d20', entry=Directory()) overlay.rootdirectory().add(name='d11', entry=Directory()) union = OverlayFileSystem(original=original, overlay=overlay) # root has d10 from original and d11 from overlay self.failUnless(len([e for e in union.rootdirectory().entries()]) == 2) union_d10 = union.rootdirectory().find(['d10']) union_d11 = union.rootdirectory().find(['d11']) self.failIf(union_d10 is None) self.failIf(union_d11 is None) # d10 has d20 and f0 from first and f1 from second. we search # these using three different ways: using the directory # union_d10 directly (get() and find()), and using the root # directory (the "absolute path", so to say) self.failUnless(len([e for e in union_d10.entries()]) == 3) found_f0_0 = union_d10.find(['f0']) found_f0_1 = union_d10.get('f0') found_f0_2 = union.rootdirectory().find(['d10', 'f0']) self.failIf(found_f0_0 is None) self.failIf(found_f0_1 is None) self.failIf(found_f0_2 is None) self.failUnless(isinstance(found_f0_0, VFSFile)) self.failUnless(found_f0_0 is found_f0_1 is found_f0_2) found_f1_0 = union_d10.find(['f1']) found_f1_1 = union_d10.get('f1') found_f1_2 = union.rootdirectory().find(['d10', 'f1']) self.failIf(found_f1_0 is None) self.failIf(found_f1_1 is None) self.failIf(found_f1_2 is None) self.failUnless(isinstance(found_f1_0, VFSFile)) self.failUnless(found_f1_0 is found_f1_1 is found_f1_2) found_d20_0 = union_d10.find(['d20']) found_d20_1 = union_d10.get('d20') found_d20_2 = union.rootdirectory().find(['d10', 'd20']) self.failIf(found_d20_0 is None) self.failIf(found_d20_1 is None) self.failIf(found_d20_2 is None) self.failUnless(isinstance(found_d20_0, VFSDirectory)) self.failUnless(found_d20_0 is found_d20_1 is found_d20_2) pass
def test(self): source = self.rootpath() + ['source'] build = self.rootpath() + ['build'] install = self.rootpath() + ['install'] overlay = self.rootpath() + ['overlay'] # compose the source tree, # source # |-- exe # | `-- main.c # `-- library # |-- library.c # `-- library.h source_fs = FileSystem(path=source) source_library = source_fs.rootdirectory().add(name='library', entry=Directory()) source_library.add(name='library.h', entry=File(lines=[ '#ifndef LIBRARY_H', '#define LIBRARY_H', 'extern void f(void);', '#endif' ])) source_library.add( name='library.c', entry=File(lines=['#include "library.h"', 'void f(void) {}'])) source_exe = source_fs.rootdirectory().add(name='exe', entry=Directory()) source_exe.add( name='main.c', entry=File(lines=[ '// CONFIX:EXENAME("the_exe")', '#include <library.h>', 'int main(void) {', ' f();', ' return 0;', '}' ])) # compose the build instructions, separate from the source # tree, # overlay # |-- Confix2.dir # |-- Confix2.pkg # |-- exe # | `-- Confix2.dir # `-- library # `-- Confix2.dir overlay_fs = FileSystem(path=overlay) overlay_fs.rootdirectory().add( name=const.CONFIX2_PKG, entry=File(lines=[ 'PACKAGE_NAME("' + self.__class__.__name__ + '")', 'PACKAGE_VERSION("1.2.3")' ])) overlay_fs.rootdirectory().add(name=const.CONFIX2_DIR, entry=File()) overlay_library = overlay_fs.rootdirectory().add(name='library', entry=Directory()) overlay_library.add(name=const.CONFIX2_DIR, entry=File()) overlay_exe = overlay_fs.rootdirectory().add(name='exe', entry=Directory()) overlay_exe.add(name=const.CONFIX2_DIR, entry=File()) # union of both, and boil-build-install overlay_fs = OverlayFileSystem(original=source_fs, overlay=overlay_fs) package = LocalPackage(rootdirectory=overlay_fs.rootdirectory(), setups=[ConfixSetup(use_libtool=False)]) package.boil(external_nodes=[]) package.output() # should have checked such thing elsewhwere, but it won't hurt # repeating. self.failUnless( source_fs.rootdirectory().find([const.CONFIX2_PKG]) is None) self.failUnless( source_fs.rootdirectory().find([const.CONFIX2_DIR]) is None) self.failUnless( source_fs.rootdirectory().find(['exe', const.CONFIX2_DIR]) is None) self.failUnless(source_fs.rootdirectory().find( ['library', const.CONFIX2_DIR]) is None) overlay_fs.sync() os.makedirs(os.sep.join(build)) bootstrap.bootstrap(packageroot=overlay_fs.rootdirectory().abspath(), use_kde_hack=False, argv0=sys.argv[0]) configure.configure(packageroot=overlay_fs.rootdirectory().abspath(), builddir=build, prefix=install) make.make(builddir=build, args=['install']) self.failUnless( os.path.exists(os.sep.join(install + ['bin', 'the_exe']))) make.make(builddir=build, args=['dist']) pass