示例#1
0
def git_clone(*params, **kwargs):
    '''Clone or update a local git repository'''
    if not 'subdir' in kwargs:
        raise BuiltinError("you must give subdir parameter.")
    subdir = kwargs['subdir']
    clone_dir = joinpath(src_cache, fullname)
    shelltools.makedirs(clone_dir)
    current_dir = pwd()
    cd(clone_dir)
    if isdir(subdir):
        if not isempty(subdir):
            cd(subdir)
            notify("updating %s" % subdir)
            notify("running git pull %s" % " ".join(params))
            if not shelltools.system("git pull", sandbox=False):
                raise BuiltinError("git pull failed")
            copy_to_build_dir(joinpath(clone_dir, subdir))
            cd(current_dir)
            return True
    notify("cloning into %s" % pwd())
    notify("running git clone %s" % " ".join(params))
    if not shelltools.system("git clone " + " ".join(params), sandbox=False):
        raise BuiltinError("git clone failed")
    copy_to_build_dir(joinpath(clone_dir, subdir))
    cd(current_dir)
    return True
示例#2
0
def git_clone(*params, **kwargs):
    '''Clone or update a local git repository'''
    if not 'subdir' in kwargs:
        raise BuiltinError("you must give subdir parameter.")
    subdir = kwargs['subdir']
    clone_dir = joinpath(src_cache, fullname)
    shelltools.makedirs(clone_dir)
    current_dir = pwd()
    cd(clone_dir)
    if isdir(subdir):
        if not isempty(subdir):
            cd(subdir)
            notify("updating %s" % subdir)
            notify("running git pull %s" % " ".join(params))
            if not shelltools.system("git pull", sandbox=False):
                raise BuiltinError("git pull failed")
            copy_to_build_dir(joinpath(clone_dir, subdir))
            cd(current_dir)
            return True
    notify("cloning into %s" % pwd())
    notify("running git clone %s" % " ".join(params))
    if not shelltools.system("git clone "+" ".join(params), sandbox=False):
        raise BuiltinError("git clone failed")
    copy_to_build_dir(joinpath(clone_dir, subdir))
    cd(current_dir)
    return True
示例#3
0
    def run_post_install(self):
        if self.environment.no_configure or self.environment.real_root != cst.root:
            out.warn_notify("skipping post_install function...")
            pkg_data = (self.environment.repo, self.environment.category, \
                    self.environment.name, self.environment.version)
            pending_file = os.path.join(self.environment.real_root,
                                        cst.configure_pending_file)
            shelltools.makedirs(os.path.dirname(pending_file))
            if not os.path.exists(pending_file):
                with open(pending_file, "wb") as _data:
                    pickle.dump([pkg_data], _data)
            else:
                data = []
                with open(pending_file, "rb") as _data:
                    pending_packages = pickle.load(_data)
                    if not pkg_data in pending_packages:
                        data.append(pkg_data)

                    data.extend(pending_packages)
                shelltools.remove_file(pending_file)
                with open(pending_file, "wb") as _data:
                    pickle.dump(data, _data)
            return

        # sandbox must be disabled
        self.environment.sandbox = False
        self.run_stage("post_install")
示例#4
0
    def run_post_install(self):
        if self.environment.no_configure or self.environment.real_root != cst.root:
            out.warn_notify("skipping post_install function...")
            pkg_data = (self.environment.repo, self.environment.category, \
                    self.environment.name, self.environment.version)
            pending_file = os.path.join(self.environment.real_root, cst.configure_pending_file)
            shelltools.makedirs(os.path.dirname(pending_file))
            if not os.path.exists(pending_file):
                with open(pending_file, "wb") as _data:
                    pickle.dump([pkg_data], _data)
            else:
                data = []
                with open(pending_file, "rb") as _data:
                    pending_packages = pickle.load(_data)
                    if not pkg_data in pending_packages:
                        data.append(pkg_data)

                    data.extend(pending_packages)
                shelltools.remove_file(pending_file)
                with open(pending_file, "wb") as _data:
                    pickle.dump(data, _data)
            return

        # sandbox must be disabled
        self.environment.sandbox = False
        self.run_stage("post_install")
示例#5
0
def makesym(source, target, ignore_fix_target=False):
    if not ignore_fix_target:
        target = fix_target_path(target)
    if len(target.split("/")) > 1:
        shelltools.makedirs(os.path.dirname(target))
    # Remove the target if it is already a symlink
    # TODO: Should we remove the file if it is a regular file or directory?
    if os.path.islink(target):
        shelltools.remove_file(target)
    shelltools.make_symlink(source, target)
示例#6
0
def insdoc(*sources):
    if slot != "0":
        target = fix_target_path("/usr/share/doc/%s" % fullname)
    else:
        target = fix_target_path("/usr/share/doc/%s" % name)
    shelltools.makedirs(target)
    srcs = []
    for source in sources:
        srcs.extend(glob.glob(joinpath(build_dir, source)))
    return shelltools.install_readable(srcs, target)
示例#7
0
    def merge_package(self):
        '''Moves files to the target destination in the most safest way.'''
        def get_perms(path):
            '''Get permissions of given path, it may be file or directory'''
            return {"uid": utils.get_uid(path),
                    "gid": utils.get_gid(path),
                    "mod": utils.get_mod(path)
            }
        out.normal("%s/%s/%s-%s:%s is merging to %s" % (self.environment.repo, self.environment.category, \
                self.environment.name, self.environment.version, self.environment.slot, \
                self.environment.real_root))
        # Remove files db entries for this package:slot if it exists
        self.filesdb.delete_item_by_pkgdata(self.environment.category, self.environment.name, \
            self.environment.previous_version, commit=True)

        # Remove file_relations db entries for this package:slot if it exists
        self.file_relationsdb.delete_item_by_pkgdata(self.environment.category, \
                self.environment.name, self.environment.previous_version, commit=True)

        # Merge the package, now
        walk_iter = os.walk(self.environment.install_dir, followlinks=True)
        while True:
            try:
                parent, directories, files = next(walk_iter)
                # TODO: Check the target path's permissions for writing or reading
                # Remove install_dir from parent to get real parent path
                pruned_parent = parent.replace(self.environment.install_dir, "")
                # create directories
                for directory in directories:
                    source = os.path.join(parent, directory)
                    target = os.path.join(self.environment.real_root, pruned_parent, directory)
                    real_target = "/".join([pruned_parent, directory])
                    if self.is_parent_symlink(target):
                        break
                    if os.path.islink(source):
                        self.symlinks.append(target+"/")
                        realpath = os.path.realpath(source)
                        if os.path.islink(target):
                            shelltools.remove_file(target)
                        # create real directory
                        if len(realpath.split(self.environment.install_dir)) > 1:
                            realpath = realpath.split(self.environment.install_dir)[1][1:]

                        shelltools.makedirs(os.path.join(self.environment.real_root, realpath))
                        # make symlink
                        if os.path.isdir(target):
                            shelltools.remove_dir(target)
                        elif os.path.isfile(target):
                            shelltools.remove_file(target)
                        shelltools.make_symlink(os.readlink(source), target)
                    else:
                        if os.path.isfile(target):
                            # TODO: Rename this file and warn the user
                            shelltools.remove_file(target)
                        shelltools.makedirs(target)
                    # Get permissions
                    perms = get_perms(source)
                    # if path is a symlink, pass permission mumbo-jumbos
                    if not os.path.islink(source):
                        # Set permissions
                        shelltools.set_id(target, perms["uid"], perms["gid"])
                        shelltools.set_mod(target, perms["mod"])
                        # TODO: Common items?
                        # Add the item to filesdb
                        self.append_filesdb("dir", real_target, perms)
                    else:
                        # Add the item to filesdb
                        self.append_filesdb("link", real_target, perms, \
                                realpath=os.path.realpath(source))

                # Merge regular files to the target
                # Firstly, handle reserved files
                reserve_files = []
                if self.environment.reserve_files:
                    if isinstance(self.environment.reserve_files, basestring):
                        reserve_files.extend([f_item for f_item in self.environment.reserve_files.split(" ") \
                                if f_item != ""])
                    elif isinstance(self.environment.reserve_files, list) or isinstance(self.environment.reserve_files, tuple):
                        reserve_files.extend(self.environment.reserve_files)

                if os.path.isfile(os.path.join(cst.user_dir, cst.protect_file)):
                    with open(os.path.join(cst.user_dir, cst.protect_file)) as data:
                        for rf in data.readlines():
                            if not rf.startswith("#"):
                                reserve_files.append(rf.strip())

                # Here we are starting to merge
                for _file in files:
                    source = os.path.join(parent, _file)
                    target = os.path.join(self.environment.real_root, pruned_parent, _file)
                    real_target = "/".join([pruned_parent, _file])
                    if self.is_parent_symlink(target):
                        break
                    # Keep file relations for using after to handle reverse dependencies
                    if os.path.exists(source) and os.access(source, os.X_OK):
                        if utils.get_mimetype(source) in self.binary_filetypes:
                            self.file_relationsdb.append_query((
                                self.environment.repo,
                                self.environment.category,
                                self.environment.name,
                                self.environment.version,
                                target,
                                file_relations.get_depends(source))
                            )
                    # Strip binary files and keep them smaller
                    if self.strip_debug_symbols and utils.get_mimetype(source) in self.binary_filetypes:
                        utils.run_strip(source)
                    if self.environment.ignore_reserve_files:
                        reserve_files = []
                        self.environment.reserve_files = True

                    def add_file_item():
                        # Prevent code duplication
                        if not os.path.islink(target):
                            shelltools.set_id(target, perms["uid"], perms["gid"])
                            shelltools.set_mod(target, perms["mod"])
                            self.append_filesdb("file", real_target, perms, \
                                    sha1sum=utils.sha1sum(target),
                                    size = utils.get_size(source, dec=True)
                            )
                        else:
                            self.append_filesdb("link", real_target, perms,\
                                    realpath=os.path.realpath(source))

                    if self.environment.reserve_files is not False:
                        conf_file = os.path.join(pruned_parent, _file)
                        isconf = (_file.endswith(".conf") or _file.endswith(".cfg"))
                        def is_reserve():
                            if self.environment.ignore_reserve_files:
                                return False
                            elif not conf_file in reserve_files:
                                return False
                            return True

                        if os.path.exists(target) and not is_reserve():
                            if pruned_parent[0:4] == "/etc" or isconf:
                                if os.path.isfile(conf_file) and utils.sha1sum(source) != utils.sha1sum(conf_file):
                                    self.append_merge_conf(conf_file)
                                    target = target+".lpms-backup" 
                                    self.backup.append(target)

                        if os.path.exists(target) and is_reserve():
                            # The file is reserved.
                            # Adds to filesdb
                            add_file_item()
                            # We don't need the following operations
                            continue

                    if os.path.islink(source):
                        sha1 = False
                        realpath = os.readlink(source)
                        if self.environment.install_dir in realpath:
                            realpath = realpath.split(self.environment.install_dir)[1]

                        if os.path.isdir(target):
                            shelltools.remove_dir(target)
                        elif os.path.isfile(target) or os.path.islink(target):
                            shelltools.remove_file(target)
                        shelltools.make_symlink(realpath, target)
                    else:
                        sha1 = utils.sha1sum(source)
                        perms = get_perms(source)
                        shelltools.move(source, target)
                    # Adds to filesdb
                    add_file_item()
            except StopIteration as err:
                break

        self.file_relationsdb.insert_query(commit=True)
        self.filesdb.insert_query(commit=True)

        lpms.logger.info("%s/%s has been merged to %s." % (self.environment.category, self.environment.fullname, \
                self.environment.real_root))
示例#8
0
    def merge_package(self):
        '''Moves files to the target destination in the most safest way.'''
        def get_perms(path):
            '''Get permissions of given path, it may be file or directory'''
            return {
                "uid": utils.get_uid(path),
                "gid": utils.get_gid(path),
                "mod": utils.get_mod(path)
            }
        out.normal("%s/%s/%s-%s:%s is merging to %s" % (self.environment.repo, self.environment.category, \
                self.environment.name, self.environment.version, self.environment.slot, \
                self.environment.real_root))
        # Remove files db entries for this package:slot if it exists
        self.filesdb.delete_item_by_pkgdata(self.environment.category, self.environment.name, \
            self.environment.previous_version, commit=True)

        # Remove file_relations db entries for this package:slot if it exists
        self.file_relationsdb.delete_item_by_pkgdata(self.environment.category, \
                self.environment.name, self.environment.previous_version, commit=True)

        # Merge the package, now
        walk_iter = os.walk(self.environment.install_dir, followlinks=True)
        while True:
            try:
                parent, directories, files = next(walk_iter)
                # TODO: Check the target path's permissions for writing or reading
                # Remove install_dir from parent to get real parent path
                pruned_parent = parent.replace(self.environment.install_dir,
                                               "")
                # create directories
                for directory in directories:
                    source = os.path.join(parent, directory)
                    target = os.path.join(self.environment.real_root,
                                          pruned_parent, directory)
                    real_target = "/".join([pruned_parent, directory])
                    if self.is_parent_symlink(target):
                        break
                    if os.path.islink(source):
                        self.symlinks.append(target + "/")
                        realpath = os.path.realpath(source)
                        if os.path.islink(target):
                            shelltools.remove_file(target)
                        # create real directory
                        if len(realpath.split(
                                self.environment.install_dir)) > 1:
                            realpath = realpath.split(
                                self.environment.install_dir)[1][1:]

                        shelltools.makedirs(
                            os.path.join(self.environment.real_root, realpath))
                        # make symlink
                        if os.path.isdir(target):
                            shelltools.remove_dir(target)
                        elif os.path.isfile(target):
                            shelltools.remove_file(target)
                        shelltools.make_symlink(os.readlink(source), target)
                    else:
                        if os.path.isfile(target):
                            # TODO: Rename this file and warn the user
                            shelltools.remove_file(target)
                        shelltools.makedirs(target)
                    # Get permissions
                    perms = get_perms(source)
                    # if path is a symlink, pass permission mumbo-jumbos
                    if not os.path.islink(source):
                        # Set permissions
                        shelltools.set_id(target, perms["uid"], perms["gid"])
                        shelltools.set_mod(target, perms["mod"])
                        # TODO: Common items?
                        # Add the item to filesdb
                        self.append_filesdb("dir", real_target, perms)
                    else:
                        # Add the item to filesdb
                        self.append_filesdb("link", real_target, perms, \
                                realpath=os.path.realpath(source))

                # Merge regular files to the target
                # Firstly, handle reserved files
                reserve_files = []
                if self.environment.reserve_files:
                    if isinstance(self.environment.reserve_files, basestring):
                        reserve_files.extend([f_item for f_item in self.environment.reserve_files.split(" ") \
                                if f_item != ""])
                    elif isinstance(self.environment.reserve_files,
                                    list) or isinstance(
                                        self.environment.reserve_files, tuple):
                        reserve_files.extend(self.environment.reserve_files)

                if os.path.isfile(os.path.join(cst.user_dir,
                                               cst.protect_file)):
                    with open(os.path.join(cst.user_dir,
                                           cst.protect_file)) as data:
                        for rf in data.readlines():
                            if not rf.startswith("#"):
                                reserve_files.append(rf.strip())

                # Here we are starting to merge
                for _file in files:
                    source = os.path.join(parent, _file)
                    target = os.path.join(self.environment.real_root,
                                          pruned_parent, _file)
                    real_target = "/".join([pruned_parent, _file])
                    if self.is_parent_symlink(target):
                        break
                    # Keep file relations for using after to handle reverse dependencies
                    if os.path.exists(source) and os.access(source, os.X_OK):
                        if utils.get_mimetype(source) in self.binary_filetypes:
                            self.file_relationsdb.append_query(
                                (self.environment.repo,
                                 self.environment.category,
                                 self.environment.name,
                                 self.environment.version, target,
                                 file_relations.get_depends(source)))
                    # Strip binary files and keep them smaller
                    if self.strip_debug_symbols and utils.get_mimetype(
                            source) in self.binary_filetypes:
                        utils.run_strip(source)
                    if self.environment.ignore_reserve_files:
                        reserve_files = []
                        self.environment.reserve_files = True

                    def add_file_item():
                        # Prevent code duplication
                        if not os.path.islink(target):
                            shelltools.set_id(target, perms["uid"],
                                              perms["gid"])
                            shelltools.set_mod(target, perms["mod"])
                            self.append_filesdb("file", real_target, perms, \
                                    sha1sum=utils.sha1sum(target),
                                    size = utils.get_size(source, dec=True)
                            )
                        else:
                            self.append_filesdb("link", real_target, perms,\
                                    realpath=os.path.realpath(source))

                    if self.environment.reserve_files is not False:
                        conf_file = os.path.join(pruned_parent, _file)
                        isconf = (_file.endswith(".conf")
                                  or _file.endswith(".cfg"))

                        def is_reserve():
                            if self.environment.ignore_reserve_files:
                                return False
                            elif not conf_file in reserve_files:
                                return False
                            return True

                        if os.path.exists(target) and not is_reserve():
                            if pruned_parent[0:4] == "/etc" or isconf:
                                if os.path.isfile(conf_file) and utils.sha1sum(
                                        source) != utils.sha1sum(conf_file):
                                    self.append_merge_conf(conf_file)
                                    target = target + ".lpms-backup"
                                    self.backup.append(target)

                        if os.path.exists(target) and is_reserve():
                            # The file is reserved.
                            # Adds to filesdb
                            add_file_item()
                            # We don't need the following operations
                            continue

                    if os.path.islink(source):
                        sha1 = False
                        realpath = os.readlink(source)
                        if self.environment.install_dir in realpath:
                            realpath = realpath.split(
                                self.environment.install_dir)[1]

                        if os.path.isdir(target):
                            shelltools.remove_dir(target)
                        elif os.path.isfile(target) or os.path.islink(target):
                            shelltools.remove_file(target)
                        shelltools.make_symlink(realpath, target)
                    else:
                        sha1 = utils.sha1sum(source)
                        perms = get_perms(source)
                        shelltools.move(source, target)
                    # Adds to filesdb
                    add_file_item()
            except StopIteration as err:
                break

        self.file_relationsdb.insert_query(commit=True)
        self.filesdb.insert_query(commit=True)

        lpms.logger.info("%s/%s has been merged to %s." % (self.environment.category, self.environment.fullname, \
                self.environment.real_root))
示例#9
0
def insexe(source, target='/usr/bin'):
    target = fix_target_path(target)
    shelltools.makedirs(os.path.dirname(target))
    source = fix_source_path(source, allowed_paths=[filesdir, src_cache])
    return shelltools.install_executable([source], target)
示例#10
0
def insfile(source, target):
    target = fix_target_path(target)
    source = fix_source_path(source, allowed_paths=[filesdir, src_cache])
    shelltools.makedirs(os.path.dirname(target))
    return shelltools.install_readable([source], target)
示例#11
0
def insinto(source, target, target_file='', sym=True):
    target = fix_target_path(target)
    shelltools.makedirs(os.path.dirname(target))
    shelltools.insinto(fix_source_path(source, allowed_paths=[filesdir, src_cache]), \
            target, install_dir, target_file, sym)
示例#12
0
def makedirs(target):
    shelltools.makedirs(fix_target_path(target))
示例#13
0
def inslib(source, target='/usr/lib', permission=0755):
    target = fix_target_path(target)
    shelltools.makedirs(os.path.dirname(target))
    return shelltools.install_library(source, target, permission)
示例#14
0
def insinfo(*sources):
    target = fix_target_path("/usr/share/info")
    shelltools.makedirs(os.path.dirname(target))
    return shelltools.install_readable(sources, target)