예제 #1
0
파일: todo.py 프로젝트: ssi-schaefer/confix
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
예제 #2
0
    def test__sync_file_truncate_persistent(self):

        fs = FileSystem(path=self.rootpath())
        file = File(lines=['line'])
        fs.rootdirectory().add(name='file', entry=file)
        fs.sync()

        fs = scan_filesystem(path=self.rootpath())
        file = fs.rootdirectory().find(['file'])
        file.truncate()
        fs.sync()

        fs = scan_filesystem(path=self.rootpath())
        file = fs.rootdirectory().find(['file'])
        self.failUnless(file.lines() == [])
        pass
예제 #3
0
파일: repo.py 프로젝트: ssi-schaefer/confix
    def __init__(self, prefix):
        assert type(prefix) in [types.ListType, types.TupleType], prefix

        CompositePackageRepository.__init__(self, [])

        repodir = prefix+self.REPO_FULL_PATH
        if not os.path.isdir(os.sep.join(repodir)):
            debug.warn('No repository directory '+os.sep.join(repodir))
            return
        
        fs = scan_filesystem(path=repodir)

        errlist = []

        for name, entry in fs.rootdirectory().entries():
            if not isinstance(entry, VFSFile):
                continue
            if _re_repo.match(name):
                try:
                    self.add_repo(PackageFileRepository(file=entry))
                except Error, e:
                    errlist.append(Error('Error reading file "'+os.sep.join(entry.abspath()), [e]))
                except Exception, e:
                    errlist.append(Error('Error reading file "'+os.sep.join(entry.abspath()), [e]))
                    pass
                pass
예제 #4
0
def main():
    try:
        config = CompositeConfiguration()
        (cmdlinecfg, actions) = cmdline.parse(sys.argv[1:])
        config.add(cmdlinecfg)

        configfile = cmdlinecfg.configfile()
        configfileobj = None

        if configfile is not None:
            configfileobj = FileSystem(path=os.path.dirname(configfile).split(
                os.sep)).rootdirectory().add(
                    name=os.path.basename(configfile),
                    entry=File(state=FileState.SYNC_CLEAR))
        else:
            configdir = cmdlinecfg.configdir()
            if configdir is None:
                candidate = os.path.expanduser('~/.confix2')
                if os.path.exists(candidate):
                    configdir = candidate
                    pass
                pass
            if configdir is not None:
                if not os.path.exists(configdir):
                    raise Error('Directory "' + configdir + '" does not exist')
                if not os.path.isdir(configdir):
                    raise Error('"' + configdir +
                                '" exists but is not a directory')
                confixfs = scan_filesystem(path=configdir.split(os.sep))
                configfileobj = confixfs.rootdirectory().find(['config'])
                pass
            pass

        if configfileobj is not None:
            configfile = ConfigFile(file=configfileobj)
            if cmdlinecfg.profile() is not None:
                profilename = cmdlinecfg.profile()
            else:
                profilename = 'default'
                pass
            config.add(configfile.get_profile(profilename))
            pass

        config.add(DefaultConfiguration())

        todo.TODO = actions
        todo.CONFIG = config

        # normally todo failures will throw exceptions, but this is in here just
        # as a safety measure.
        if todo.todo():
            sys.exit(1)
            pass
        pass

    except Error, e:
        sys.stderr.write('***ERROR***\n')
        sys.stderr.write(str(e) + '\n')
        sys.exit(1)
예제 #5
0
    def test__new_directory(self):
        fs_orig = FileSystem(self.rootpath())
        fs_orig.sync()

        fs_dup = scan.scan_filesystem(self.rootpath())

        fs_orig.rootdirectory().add(name='dir', entry=Directory())
        fs_orig.sync()

        scan.rescan_dir(fs_dup.rootdirectory())
        self.failUnless(fs_dup.rootdirectory().get('dir'))
        pass
예제 #6
0
    def test__new_file_in_existing_directory(self):
        fs_orig = FileSystem(self.rootpath())
        orig_dir = fs_orig.rootdirectory().add(name='dir', entry=Directory())
        fs_orig.sync()

        fs_dup = scan.scan_filesystem(self.rootpath())

        orig_dir.add(name='file', entry=File())
        fs_orig.sync()

        scan.rescan_dir(fs_dup.rootdirectory())
        self.failUnless(fs_dup.rootdirectory().find(['dir', 'file']))
        pass
예제 #7
0
    def test__sync_filechange(self):
        # build up filesystem with our test file and sync it.
        fs = FileSystem(path=self.rootpath())
        file = File(lines=['line 0'])
        fs.rootdirectory().add(name='file', entry=file)
        file.add_lines(['line 1', 'line 2', 'line 3'])
        fs.sync()

        # re-read our file and see if everything is there
        fs = scan_filesystem(path=self.rootpath())
        file = fs.rootdirectory().find(['file'])
        lines = file.lines()
        self.failUnlessEqual(lines[0], 'line 0')
        self.failUnlessEqual(lines[1], 'line 1')
        self.failUnlessEqual(lines[2], 'line 2')
        self.failUnlessEqual(lines[3], 'line 3')
        file.add_lines(['line 4'])
        fs.sync()

        # append to our file without explicitly reading it.
        fs = scan_filesystem(path=self.rootpath())
        file = fs.rootdirectory().find(['file'])
        file.add_lines(['line 5'])
        fs.sync()

        # see if there's still everything there.
        fs = scan_filesystem(path=self.rootpath())
        file = fs.rootdirectory().find(['file'])
        lines = file.lines()
        self.failUnlessEqual(lines[0], 'line 0')
        self.failUnlessEqual(lines[1], 'line 1')
        self.failUnlessEqual(lines[2], 'line 2')
        self.failUnlessEqual(lines[3], 'line 3')
        self.failUnlessEqual(lines[4], 'line 4')
        self.failUnlessEqual(lines[5], 'line 5')
        pass
예제 #8
0
    def test__new_file(self):
        # use a filesystem instance to conveniently create the initial
        # directory.
        fs_orig = FileSystem(self.rootpath())
        fs_orig.rootdirectory().add(name='file1', entry=File())
        fs_orig.sync()

        # we have synced the fs_orig, so a scan should see file1
        fs_dup = scan.scan_filesystem(self.rootpath())
        self.failUnless(fs_dup.rootdirectory().get('file1'))

        # now add a file to the directory, via fs_orig
        fs_orig.rootdirectory().add(name='file2', entry=File())
        fs_orig.sync()

        # rescan the fs_dup's rootdirectory. the file must be seen.
        scan.rescan_dir(fs_dup.rootdirectory())
        self.failUnless(fs_dup.rootdirectory().get('file2'))
        pass
예제 #9
0
from libconfix.core.filesys import scan

import sys
import os

for filename in sys.argv[1:]:
    if not os.path.isfile(filename):
        debug.die(filename + " is not a file")
        pass

    # this could certainly be done simpler :-}
    dirname = os.path.dirname(filename)
    if len(dirname) == 0:
        dirname = '.'
        pass
    filesystem = scan.scan_filesystem(dirname.split(os.sep))
    file_object = filesystem.rootdirectory().get(os.path.basename(filename))
    assert file_object is not None

    repo = PackageFileRepository(file_object)

    for package in repo.iter_packages():
        print 'Package: ' + package.name() + ' ' + package.version()
        for m in package.nodes():
            print '  Module: ' + str(m)
            print '    Provides: '
            for p in m.provides():
                print '      ' + str(p)
                pass
            print '    Requires: '
            for r in m.requires():
예제 #10
0
    def test__basic(self):
        dirstructure = DirectoryStructure(path=self.rootpath())

        # bootstrap&&configure&&build&&install packages in order
        first_local_package = LocalPackage(rootdirectory=dirstructure.first_source(),
                                           setups=[ConfixSetup(use_libtool=False)])
        first_local_package.boil(external_nodes=[])
        first_local_package.output()
        dirstructure.sync()
        bootstrap.bootstrap(
            packageroot=dirstructure.first_source().abspath(),
            path=None,
            use_kde_hack=False,
            argv0=sys.argv[0])
        configure.configure(
            packageroot=dirstructure.first_source().abspath(),
            builddir=dirstructure.first_build().abspath(),
            prefix=dirstructure.first_install().abspath(),
            readonly_prefixes=None)
        make.make(
            builddir=dirstructure.first_build().abspath(),
            args=['install'])


        second_local_package = LocalPackage(rootdirectory=dirstructure.second_source(),
                                            setups=[ConfixSetup(use_libtool=False)])
        second_local_package.boil(external_nodes=AutomakePackageRepository(prefix=dirstructure.first_install().abspath()).iter_nodes())
        second_local_package.output()
        dirstructure.sync()
        bootstrap.bootstrap(
            packageroot=dirstructure.second_source().abspath(),
            path=None,
            use_kde_hack=False,
            argv0=sys.argv[0])
        configure.configure(
            packageroot=dirstructure.second_source().abspath(),
            builddir=dirstructure.second_build().abspath(),
            prefix=dirstructure.second_install().abspath(),
            readonly_prefixes=[dirstructure.first_install().abspath()])
        make.make(
            builddir=dirstructure.second_build().abspath(),
            args=['install'])


        third_local_package = LocalPackage(rootdirectory=dirstructure.third_source(),
                                           setups=[ConfixSetup(use_libtool=False)])
        third_local_package.boil(external_nodes=itertools.chain(
            AutomakePackageRepository(prefix=dirstructure.first_install().abspath()).iter_nodes(),
            AutomakePackageRepository(prefix=dirstructure.second_install().abspath()).iter_nodes()))
        third_local_package.output()
        dirstructure.sync()
        bootstrap.bootstrap(
            packageroot=dirstructure.third_source().abspath(),
            path=None,
            use_kde_hack=False,
            argv0=sys.argv[0])
        configure.configure(
            packageroot=dirstructure.third_source().abspath(),
            builddir=dirstructure.third_build().abspath(),
            prefix=None,
            readonly_prefixes=[dirstructure.first_install().abspath(),
                               dirstructure.second_install().abspath()])
        make.make(
            builddir=dirstructure.third_build().abspath(),
            args=None)

        # so here, finally, go the tests.

        fs = scan.scan_filesystem(path=self.rootpath())

        first_library = fs.rootdirectory().find(dirstructure.first_install().relpath(self.rootpath())+['lib', 'libFirstPackage.a'])
        second_library = fs.rootdirectory().find(dirstructure.second_install().relpath(self.rootpath())+['lib', 'libSecondPackage.a'])
        third_library = fs.rootdirectory().find(dirstructure.third_build().relpath(self.rootpath())+['library', 'libThirdPackage_library.a'])
        third_exe_Makefile = fs.rootdirectory().find(dirstructure.third_build().relpath(self.rootpath())+['exe', 'Makefile'])
        self.failIf(first_library is None)
        self.failIf(second_library is None)
        self.failIf(third_library is None)
        self.failIf(third_exe_Makefile is None)

        elements = makefile.parse_makefile(third_exe_Makefile.lines())
        deps = makefile.find_list(name='ThirdPackage_exe_exe_DEPENDENCIES',
                                  elements=elements)
        self.failIf(deps is None)

        self.failUnless(os.sep.join(first_library.abspath()) in deps)
        self.failUnless(os.sep.join(second_library.abspath()) in deps)
        self.failUnless('$(top_builddir)/library/libThirdPackage_library.a' in deps)
        
        pass
예제 #11
0
                  help='read package information from DIR/share/confix2/repo.')
parser.add_option('--readonly-prefixes',
                  metavar='DIR',
                  help='list of additional prefixes.')

options, rest = parser.parse_args(sys.argv[1:])

if len(rest) > 1:
    raise Error('Only one package at a time can be massaged')
if len(rest) == 1:
    os.chdir(rest[0])
    pass

packageroot = os.getcwd().split(os.sep)

fs = scan.scan_filesystem(packageroot)
package = LocalPackage(rootdirectory=fs.rootdirectory(), setups=[])

prefix = options.prefix

readonly_prefixes = []
if options.readonly_prefixes is not None:
    for p in options.readonly_prefixes.split(','):
        readonly_prefixes.append(p.split(os.sep))
        pass
    pass

external_nodes = []
for p in AutomakeCascadedPackageRepository(
        prefix=prefix.split(os.sep),
        readonly_prefixes=readonly_prefixes).iter_packages():