コード例 #1
0
ファイル: build.py プロジェクト: hknyldz/pisitools
    def fetch_component(self):
        if self.spec.source.partOf:
            return

        diruri = util.parenturi(self.specuri.get_uri())
        parentdir = util.parenturi(diruri)
        url = util.join_path(parentdir, "component.xml")
        progress = ctx.ui.Progress
        if pisilinux.uri.URI(url).is_remote_file():
            try:
                pisilinux.fetcher.fetch_url(url, self.pkg_work_dir(), progress)
            except pisilinux.fetcher.FetchError:
                ctx.ui.warning(
                    _("Cannot find component.xml in remote " "directory, Source is now part of " "unknown component")
                )
                self.spec.source.partOf = "unknown"
                return
            path = util.join_path(self.pkg_work_dir(), "component.xml")
        else:
            if not os.path.exists(url):
                ctx.ui.warning(
                    _("Cannot find component.xml in upper " "directory, Source is now part of " "unknown component")
                )
                self.spec.source.partOf = "unknown"
                return
            path = url
        comp = component.CompatComponent()
        comp.read(path)
        self.spec.source.partOf = comp.name
コード例 #2
0
ファイル: delta.py プロジェクト: hknyldz/pisitools
def create_delta_packages(old_packages, new_package):
    if new_package in old_packages:
        ctx.ui.warning(_("New package '%s' exists in the list of old "
                         "packages. Skipping it...") % new_package)
        while new_package in old_packages:
            old_packages.remove(new_package)

    new_pkg_name = os.path.splitext(os.path.basename(new_package))[0]
    new_pkg_path = util.join_path(ctx.config.tmp_dir(), new_pkg_name)

    new_pkg = pisilinux.package.Package(new_package, tmp_dir=new_pkg_path)
    new_pkg.read()

    # Unpack new package to temp
    new_pkg.extract_pisilinux_files(new_pkg_path)
    new_pkg.extract_dir("comar", new_pkg_path)

    install_dir = util.join_path(new_pkg_path, "install")
    util.clean_dir(install_dir)
    os.mkdir(install_dir)
    new_pkg.extract_install(install_dir)

    delta_packages = create_delta_packages_from_obj(old_packages,
                                                    new_pkg,
                                                    new_pkg_path)

    # Remove temp dir
    util.clean_dir(new_pkg_path)

    # Return delta package names
    return delta_packages
コード例 #3
0
ファイル: build.py プロジェクト: hknyldz/pisitools
    def pkg_src_dir(self):
        """Returns the real path of WorkDir for an unpacked archive."""

        dirname = self.actionGlobals.get("WorkDir")
        if dirname:
            return util.join_path(self.pkg_work_dir(), dirname)

        dirname = self.spec.source.name + "-" + self.spec.getSourceVersion()
        src_dir = util.join_path(self.pkg_work_dir(), dirname)

        if not os.path.exists(src_dir):
            archive = self.spec.source.archive[0]

            # For binary types, WorkDir is usually "."
            if archive.type == "binary":
                return self.pkg_work_dir()

            basename = os.path.basename(archive.uri)
            dirname = os.path.splitext(basename)[0]
            src_dir = util.join_path(self.pkg_work_dir(), dirname)

            while not os.path.exists(src_dir):
                src_dir, ext = os.path.splitext(src_dir)
                if not ext:
                    break
            if not os.path.exists(src_dir):
                src_dir = util.join_path(
                    self.pkg_work_dir(), [d for d in os.walk(self.pkg_work_dir()).next()[1] if not d.startswith(".")][0]
                )
                if self.get_state() == "unpack":
                    ctx.ui.debug("Using %s as  WorkDir" % src_dir)

        return src_dir
コード例 #4
0
ファイル: pisitools.py プロジェクト: hknyldz/pisitools
def dohtml(*sourceFiles, **kw):
    '''inserts the files in the list of files into /usr/share/doc/PACKAGE/html'''

    ''' example call: pisilinuxtools.dohtml("doc/doxygen/html/*")'''
    destDir = kw.get("destDir", get.srcNAME())
    destionationDirectory = join_path(get.installDIR(), get.docDIR(), destDir, 'html')

    if not can_access_directory(destionationDirectory):
        makedirs(destionationDirectory)

    allowed_extensions = ['.png', '.gif', '.html', '.htm', '.jpg', '.css', '.js']
    disallowed_directories = ['CVS', '.git', '.svn', '.hg']

    for sourceFile in sourceFiles:
        sourceFileGlob = glob.glob(sourceFile)
        if len(sourceFileGlob) == 0:
            raise FileError(_("No file matched pattern \"%s\"") % sourceFile)

        for source in sourceFileGlob:
            if os.path.isfile(source) and os.path.splitext(source)[1] in allowed_extensions:
                system('install -m0644 "%s" %s' % (source, destionationDirectory))
            if os.path.isdir(source) and os.path.basename(source) not in disallowed_directories:
                eraser = os.path.split(source)[0]
                for root, dirs, files in os.walk(source):
                    newRoot = remove_prefix(eraser, root)
                    for sourcename in files:
                        if os.path.splitext(sourcename)[1] in allowed_extensions:
                            makedirs(join_path(destionationDirectory, newRoot))
                            system('install -m0644 %s %s' % (join_path(root, sourcename), join_path(destionationDirectory, newRoot, sourcename)))
コード例 #5
0
ファイル: build.py プロジェクト: hknyldz/pisitools
 def fetch_additionalFiles(self):
     for pkg in self.spec.packages + [self.spec.source]:
         for afile in pkg.additionalFiles:
             file_name = os.path.basename(afile.filename)
             dir_name = os.path.dirname(afile.filename)
             afileuri = util.join_path(self.specdiruri, ctx.const.files_dir, dir_name, file_name)
             self.download(afileuri, util.join_path(self.destdir, ctx.const.files_dir, dir_name))
コード例 #6
0
ファイル: pisitools.py プロジェクト: hknyldz/pisitools
def doman(*sourceFiles):
    '''inserts the man pages in the list of files into /usr/share/man/'''

    '''example call: pisilinuxtools.doman("man.1", "pardus.*")'''
    manDIR = join_path(get.installDIR(), get.manDIR())
    if not can_access_directory(manDIR):
        makedirs(manDIR)

    for sourceFile in sourceFiles:
        sourceFileGlob = glob.glob(sourceFile)
        if len(sourceFileGlob) == 0:
            raise FileError(_("No file matched pattern \"%s\"") % sourceFile)

        for source in sourceFileGlob:
            compressed = source.endswith("gz") and source
            if compressed:
                source = source[:-3]
            try:
                pageName, pageDirectory = source[:source.rindex('.')], \
                                          source[source.rindex('.')+1:]
            except ValueError:
                error(_('ActionsAPI [doman]: Wrong man page file: %s') % (source))

            manPDIR = join_path(manDIR, '/man%s' % pageDirectory)
            makedirs(manPDIR)
            if not compressed:
                system('install -m0644 %s %s' % (source, manPDIR))
            else:
                uncompress(compressed, targetDir=manPDIR)
コード例 #7
0
ファイル: build.py プロジェクト: hknyldz/pisitools
    def generate_static_package_object(self):
        ar_files = []
        for root, dirs, files in os.walk(self.pkg_install_dir()):
            for f in files:
                if f.endswith(ctx.const.ar_file_suffix) and util.is_ar_file(util.join_path(root, f)):
                    ar_files.append(util.join_path(root, f))

        if not len(ar_files):
            return None

        static_package_obj = pisilinux.specfile.Package()
        static_package_obj.name = self.spec.source.name + ctx.const.static_name_suffix
        # FIXME: find a better way to deal with the summary and description constants.
        static_package_obj.summary["en"] = "Ar files for %s" % (self.spec.source.name)
        static_package_obj.description["en"] = "Ar files for %s" % (self.spec.source.name)
        static_package_obj.partOf = self.spec.source.partOf
        for f in ar_files:
            static_package_obj.files.append(
                pisilinux.specfile.Path(path=f[len(self.pkg_install_dir()) :], fileType="library")
            )

        # append all generated packages to dependencies
        for p in self.spec.packages:
            static_package_obj.packageDependencies.append(pisilinux.dependency.Dependency(package=p.name))

        return static_package_obj
コード例 #8
0
ファイル: pisitools.py プロジェクト: hknyldz/pisitools
def dolib_so(sourceFile, destinationDirectory = '/usr/lib'):
    '''insert the dynamic library into /usr/lib with permission 0755'''

    '''example call: pisilinuxtools.dolib_so("pppd/plugins/minconn.so")'''
    sourceFile = join_path(os.getcwd(), sourceFile)
    destinationDirectory = join_path(get.installDIR(), destinationDirectory)

    lib_insinto(sourceFile, destinationDirectory, 0o755)
コード例 #9
0
ファイル: pisitools.py プロジェクト: hknyldz/pisitools
def dolib_a(sourceFile, destinationDirectory = '/usr/lib'):
    '''insert the static library into /usr/lib with permission 0644'''

    '''example call: pisilinuxtools.dolib_a("staticlib/libvga.a")'''
    sourceFile = join_path(os.getcwd(), sourceFile)
    destinationDirectory = join_path(get.installDIR(), destinationDirectory)

    lib_insinto(sourceFile, destinationDirectory, 0o644)
コード例 #10
0
ファイル: pisitools.py プロジェクト: hknyldz/pisitools
def dolib(sourceFile, destinationDirectory = '/usr/lib'):
    '''insert the library into /usr/lib'''

    '''example call: pisilinuxtools.dolib("libz.a")'''
    '''example call: pisilinuxtools.dolib("libz.so")'''
    sourceFile = join_path(os.getcwd(), sourceFile)
    destinationDirectory = join_path(get.installDIR(), destinationDirectory)

    lib_insinto(sourceFile, destinationDirectory, 0o755)
コード例 #11
0
ファイル: build.py プロジェクト: hknyldz/pisitools
    def check_patches(self):
        """check existence of patch files and their sizes."""

        files_dir = os.path.abspath(util.join_path(self.specdir, ctx.const.files_dir))
        for patch in self.spec.source.patches:
            patchFile = util.join_path(files_dir, patch.filename)
            if not os.access(patchFile, os.F_OK):
                raise Error(_("Patch file is missing: %s\n") % patch.filename)
            if os.stat(patchFile).st_size == 0:
                ctx.ui.warning(_("Patch file is empty: %s") % patch.filename)
コード例 #12
0
ファイル: pisitools.py プロジェクト: hknyldz/pisitools
def dosym(sourceFile, destinationFile):
    '''creates soft link between sourceFile and destinationFile'''

    ''' example call: pisilinuxtools.dosym("/usr/bin/bash", "/bin/bash")'''
    makedirs(join_path(get.installDIR(), os.path.dirname(destinationFile)))

    try:
        os.symlink(sourceFile, join_path(get.installDIR() ,destinationFile))
    except OSError:
        error(_('ActionsAPI [dosym]: File already exists: %s') % (destinationFile))
コード例 #13
0
ファイル: build.py プロジェクト: hknyldz/pisitools
    def get_abandoned_files(self):
        # return the files those are not collected from the install dir

        install_dir = self.pkg_install_dir()
        abandoned_files = []
        all_paths_in_packages = []
        skip_paths = []

        for package in self.spec.packages:
            for path in package.files:
                path = util.join_path(install_dir, path.path)
                all_paths_in_packages.append(path)

        def is_included(path1, path2):
            "Return True if path2 includes path1"
            return (
                path1 == path2
                or fnmatch.fnmatch(path1, path2)
                or (not os.path.isfile(path2) and fnmatch.fnmatch(path1, util.join_path(path2, "*")))
            )

        for root, dirs, files in os.walk(install_dir):
            if not dirs and not files:
                for _path in all_paths_in_packages:
                    if is_included(root, _path):
                        break
                else:
                    abandoned_files.append(root)

            if root in all_paths_in_packages:
                skip_paths.append(root)
                continue

            skip = False
            for skip_path in skip_paths:
                if root.startswith(skip_path):
                    skip = True
                    break
            if skip:
                continue

            for file_ in files:
                fpath = util.join_path(root, file_)
                for _path in all_paths_in_packages:
                    if is_included(fpath, _path):
                        if os.path.isfile(_path):
                            all_paths_in_packages.pop(all_paths_in_packages.index(_path))
                        break
                else:
                    abandoned_files.append(fpath)

        len_install_dir = len(install_dir)
        return [x[len_install_dir:] for x in abandoned_files]
コード例 #14
0
ファイル: pisitools.py プロジェクト: hknyldz/pisitools
def rename(sourceFile, destinationFile):
    ''' renames sourceFile as destinationFile'''

    ''' example call: pisilinuxtools.rename("/usr/bin/bash", "bash.old") '''
    ''' the result of the previous example would be "/usr/bin/bash.old" '''

    baseDir = os.path.dirname(sourceFile)

    try:
        os.rename(join_path(get.installDIR(), sourceFile), join_path(get.installDIR(), baseDir, destinationFile))
    except OSError as e:
        error(_('ActionsAPI [rename]: %s: %s') % (e, sourceFile))
コード例 #15
0
ファイル: pisitools.py プロジェクト: hknyldz/pisitools
def insinto(destinationDirectory, sourceFile,  destinationFile = '', sym = True):
    '''insert a sourceFile into destinationDirectory as a destinationFile with same uid/guid/permissions'''
    makedirs(join_path(get.installDIR(), destinationDirectory))

    if not destinationFile:
        sourceFileGlob = glob.glob(sourceFile)
        if len(sourceFileGlob) == 0:
            raise FileError(_("No file matched pattern \"%s\".") % sourceFile)

        for filePath in sourceFileGlob:
            if can_access_file(filePath):
                copy(filePath, join_path(get.installDIR(), join_path(destinationDirectory, os.path.basename(filePath))), sym)
    else:
        copy(sourceFile, join_path(get.installDIR(), join_path(destinationDirectory, destinationFile)), sym)
コード例 #16
0
ファイル: build.py プロジェクト: hknyldz/pisitools
 def fetch_translationsfile(self):
     translationsuri = util.join_path(self.specdiruri, ctx.const.translations_file)
     try:
         self.download(translationsuri, self.destdir)
     except pisilinux.fetcher.FetchError:
         # translations.xml is not mandatory for pisilinux
         pass
コード例 #17
0
ファイル: shelltools.py プロジェクト: hknyldz/pisitools
def copytree(source, destination, sym = True):
    '''recursively copy an entire directory tree rooted at source'''
    if isDirectory(source):
        if os.path.exists(destination):
            if isDirectory(destination):
                copytree(source, join_path(destination, os.path.basename(source.strip('/'))))
                return
            else:
                copytree(source, join_path(destination, os.path.basename(source)))
                return
        try:
            shutil.copytree(source, destination, sym)
        except OSError as e:
            error(_('ActionsAPI [copytree] %s to %s: %s') % (source, destination, e))
    else:
        error(_('ActionsAPI [copytree]: Directory %s doesn\'t exists.') % (source))
コード例 #18
0
ファイル: build.py プロジェクト: hknyldz/pisitools
 def is_included(path1, path2):
     "Return True if path2 includes path1"
     return (
         path1 == path2
         or fnmatch.fnmatch(path1, path2)
         or (not os.path.isfile(path2) and fnmatch.fnmatch(path1, util.join_path(path2, "*")))
     )
コード例 #19
0
ファイル: build.py プロジェクト: hknyldz/pisitools
    def apply_patches(self):
        files_dir = os.path.abspath(util.join_path(self.specdir, ctx.const.files_dir))

        for patch in self.spec.source.patches:
            patchFile = util.join_path(files_dir, patch.filename)
            relativePath = patch.filename
            reverseApply = patch.reverse and patch.reverse.lower() == "true"
            if patch.compressionType:
                patchFile = util.uncompress(
                    patchFile, compressType=patch.compressionType, targetDir=ctx.config.tmp_dir()
                )
                relativePath = relativePath.rsplit(".%s" % patch.compressionType, 1)[0]

            ctx.ui.action(_("Applying patch: %s") % patch.filename)
            util.do_patch(self.pkg_src_dir(), patchFile, level=patch.level, name=relativePath, reverse=reverseApply)
        return True
コード例 #20
0
ファイル: shelltools.py プロジェクト: hknyldz/pisitools
def copy(source, destination, sym = True):
    '''recursively copy a "source" file or directory to "destination"'''
    sourceGlob = glob.glob(source)
    if len(sourceGlob) == 0:
        error(_("ActionsAPI [copy]: No file matched pattern \"%s\".") % source)

    for filePath in sourceGlob:
        if isFile(filePath) and not isLink(filePath):
            try:
                shutil.copy(filePath, destination)
            except IOError:
                error(_('ActionsAPI [copy]: Permission denied: %s to %s') % (filePath, destination))
        elif isLink(filePath) and sym:
            if isDirectory(destination):
                os.symlink(os.readlink(filePath), join_path(destination, os.path.basename(filePath)))
            else:
                if isFile(destination):
                    os.remove(destination)
                os.symlink(os.readlink(filePath), destination)
        elif isLink(filePath) and not sym:
            if isDirectory(filePath):
                copytree(filePath, destination)
            else:
                shutil.copy(filePath, destination)
        elif isDirectory(filePath):
            copytree(filePath, destination, sym)
        else:
            error(_('ActionsAPI [copy]: File %s does not exist.') % filePath)
コード例 #21
0
ファイル: pisitools.py プロジェクト: hknyldz/pisitools
def removeDir(destinationDirectory):
    '''removes destinationDirectory and its subtrees'''
    destdirGlob = glob.glob(join_path(get.installDIR(), destinationDirectory))
    if len(destdirGlob) == 0:
        raise FileError(_("No directory matched pattern \"%s\". Remove directory operation failed.") % destinationDirectory)

    for directory in destdirGlob:
        unlinkDir(directory)
コード例 #22
0
ファイル: pisitools.py プロジェクト: hknyldz/pisitools
def remove(sourceFile):
    '''removes sourceFile'''
    sourceFileGlob = glob.glob(join_path(get.installDIR(), sourceFile))
    if len(sourceFileGlob) == 0:
        raise FileError(_("No file matched pattern \"%s\". Remove operation failed.") % sourceFile)

    for filePath in sourceFileGlob:
        unlink(filePath)
コード例 #23
0
ファイル: pisitools.py プロジェクト: hknyldz/pisitools
def newdoc(sourceFile, destinationFile):
    '''inserts a sourceFile into /usr/share/doc/PACKAGE/ directory as a destinationFile'''
    destinationDirectory = '' #490
    destinationDirectory = os.path.dirname(destinationFile)
    destinationFile = os.path.basename(destinationFile)
    # Use copy instead of move or let build-install scream like file not found!
    copy(sourceFile, destinationFile)
    readable_insinto(join_path(get.installDIR(), 'usr/share/doc', get.srcNAME(), destinationDirectory), destinationFile)
コード例 #24
0
ファイル: build.py プロジェクト: hknyldz/pisitools
 def find_old_package(filename, search_paths):
     for package_dir in search_paths:
         path = util.join_path(package_dir, filename)
         if os.path.exists(path):
             return path
         else:
             path = os.path.join(package_dir, util.parse_package_dir_path(filename), filename)
             if os.path.exists(path):
                 return path
コード例 #25
0
ファイル: libtools.py プロジェクト: hknyldz/pisitools
def gnuconfig_update():
    ''' copy newest config.* onto source\'s '''
    for root, dirs, files in os.walk(os.getcwd()):
        for fileName in files:
            if fileName in ['config.sub', 'config.guess']:
                targetFile = os.path.join(root, fileName)
                if os.path.islink(targetFile):
                    unlink(targetFile)
                copy('/usr/share/gnuconfig/%s' % fileName, join_path(root, fileName))
                ctx.ui.info(_('GNU Config Update Finished.'))
コード例 #26
0
ファイル: package.py プロジェクト: hknyldz/pisitools
    def extract_file_synced(self, path, outdir):
        """Extract file with path to outdir"""
        data = self.impl.read_file(path)
        fpath = util.join_path(outdir, path)
        util.ensure_dirs(os.path.dirname(fpath))

        with open(fpath, "wb") as f:
            f.write(data)
            f.flush()
            os.fsync(f.fileno())
コード例 #27
0
ファイル: build.py プロジェクト: hknyldz/pisitools
    def compile_action_script(self):
        """Compiles the action script and returns a code object"""

        fname = util.join_path(self.specdir, ctx.const.actions_file)
        try:
            buf = open(fname).read()
            return compile(buf, fname, "exec")
        except IOError as e:
            raise Error(_("Unable to read Actions Script (%s): %s") % (fname, e))
        except SyntaxError as e:
            raise Error(_("SyntaxError in Actions Script (%s): %s") % (fname, e))
コード例 #28
0
ファイル: package.py プロジェクト: hknyldz/pisitools
    def add_to_install(self, name, arcname=None):
        """Add the file 'name' to the install archive"""

        if arcname is None:
            arcname = name

        if self.format == "1.0":
            arcname = util.join_path("install", arcname)
            self.add_to_package(name, arcname)
            return

        if self.install_archive is None:
            archive_name, archive_format = \
                    self.archive_name_and_format(self.format)
            self.install_archive_path = util.join_path(self.tmp_dir,
                                                       archive_name)
            ctx.build_leftover = self.install_archive_path
            self.install_archive = archive.ArchiveTar(
                                            self.install_archive_path,
                                            archive_format)

        self.install_archive.add_to_archive(name, arcname)
コード例 #29
0
ファイル: build.py プロジェクト: hknyldz/pisitools
    def compile_comar_script(self):
        """Compiles comar scripts to check syntax errors"""
        for package in self.spec.packages:
            for pcomar in package.providesComar:
                fname = util.join_path(self.specdir, ctx.const.comar_dir, pcomar.script)

                try:
                    buf = open(fname).read()
                    compile(buf, "error", "exec")
                except IOError as e:
                    raise Error(_("Unable to read COMAR script (%s): %s") % (fname, e))
                except SyntaxError as e:
                    raise Error(_("SyntaxError in COMAR file (%s): %s") % (fname, e))
コード例 #30
0
ファイル: archive.py プロジェクト: hknyldz/pisitools
    def unpack_dir(self, target_dir):
        """Unpack Gzip archive to a given target directory(target_dir)."""

        output_path = util.join_path(target_dir,
                                     os.path.basename(self.file_path))
        if output_path.endswith(".gz"):
            output_path = output_path[:-3]

        import gzip
        gzip_file = gzip.GzipFile(self.file_path, "r")
        output = open(output_path, "w")
        output.write(gzip_file.read())
        output.close()
        gzip_file.close()