Ejemplo n.º 1
0
    def run_install(self):
        utils.xterm_title("(%s/%s) lpms: installing %s/%s-%s from %s" % (self.environment.index, self.environment.count, 
            self.environment.category, self.environment.name, self.environment.version, self.environment.repo))
        out.normal("installing %s to %s" % (self.environment.fullname, self.environment.install_dir))
        installed_file = os.path.join(os.path.dirname(os.path.dirname(
            self.environment.build_dir)), ".installed")

        if os.path.isfile(installed_file) and self.environment.resume_build:
            out.warn_notify("%s had been already installed." % self.environment.fullname)
            return True
        
        lpms.logger.info("installing to %s" % self.environment.build_dir)

        self.run_stage("install")
        if self.environment.docs is not None:
            for doc in self.environment.docs:
                if isinstance(doc, list) or isinstance(doc, tuple):
                    source_file, target_file = doc
                    namestr = self.environment.fullname if self.environment.slot != "0" else self.environment.name
                    target = self.environment.fix_target_path("/usr/share/doc/%s/%s" % (namestr, target_file))
                    source = os.path.join(self.environment.build_dir, source_file)
                #    self.environment.index, insfile(source, target)
                #else:
                #    self.environment.index, insdoc(doc)
        out.notify("%s has been installed." % self.environment.fullname)
        if not os.path.isfile(installed_file):
            touch(installed_file)
        if self.environment.stage == "install":
            lpms.terminate()
Ejemplo n.º 2
0
def prepare():
    if opt("branding"):
        if not opt("gtk3"):
            import lpms
            lpms.terminate("branding option needs gtk3 option")
    sed("""-i -e "/minimum-uid/s:500:1000:" data/users.conf""")
    sed("""-i -e "s|/usr/sbin/nologin|/sbin/nologin|g" data/users.conf""")
Ejemplo n.º 3
0
    def function_collisions(self):
        '''Checks the build environment to deal with function collisions if primary_library is not defined'''
        if self.environment.primary_library: return
        preserved_names = [
                'extract',
                'prepare',
                'configure',
                'build',
                'install',
                'collision_check',
                'pre_merge',
                'post_install'
                'remove'
        ]

        race_list = {}
        for library in self.environment.libraries:
            for preserved_name in preserved_names:
                if preserved_name in self.environment.raw:
                    continue
                if library+"_"+preserved_name in self.environment.raw:
                    if preserved_name in race_list:
                        if not library in race_list[preserved_name]:
                            race_list[preserved_name].append(library)
                    else:
                        race_list.update({preserved_name: [library]})
                        
        result = [(key, race_list[key]) for key in race_list if len(race_list[key]) > 1]
        if result:
            out.warn("function collision detected in these stages. you should use primary_library keyword.")
            for item in result:
                stage, libraries = item
                out.notify(stage+": "+", ".join(libraries))
            lpms.terminate("please contact the package maintainer.")
Ejemplo n.º 4
0
    def run(self):
        if lpms.getopt("--help") or len(self.params) == 0:
            self.usage()

        for param in self.params:
            param = param.split("/")
            if len(param) == 3:
                myrepo, mycategory, myname = param
                packages = self.repodb.find_package(package_name=myname, \
                        package_repo=myrepo, package_category=mycategory)
            elif len(param) == 2:
                mycategory, myname = param
                packages = self.repodb.find_package(package_name=myname, \
                        package_category=mycategory)
            elif len(param) == 1:
                packages = self.repodb.find_package(package_name=param[0])
            else:
                out.error("%s seems invalid." %
                          out.color("/".join(param), "brightred"))
                lpms.terminate()
            if not packages:
                out.error("%s not found!" %
                          out.color("/".join(param), "brightred"))
                lpms.terminate()

            # Show time!
            self.show_package(packages)
Ejemplo n.º 5
0
def python_utils_configure(*params, **kwargs):
    '''Configures the package using setup.py configure command'''
    python_binary = set_python_binary(kwargs)
    if not system("%s -B setup.py configure %s" %
                  (python_binary, " ".join(params))):
        error("configuration failed.")
        lpms.terminate()
Ejemplo n.º 6
0
    def run_extract(self):
        # if the environment has no extract_plan variable, doesn't run extract function
        if not hasattr(self.environment, "extract_nevertheless"
                       ) or not self.environment.extract_nevertheless:
            if not hasattr(self.environment, "extract_plan"): return
        target = os.path.dirname(self.environment.build_dir)
        extracted_file = os.path.join(os.path.dirname(target), ".extracted")
        if os.path.isfile(extracted_file):
            if self.environment.force_extract:
                shelltools.remove_file(extracted_file)
            else:
                out.write("%s %s/%s-%s had been already extracted.\n" % (out.color(">>", "brightyellow"), \
                    self.environment.category, self.environment.name, self.environment.version))
                return True

        utils.xterm_title("lpms: extracting %s/%s/%s-%s" % (self.environment.repo, self.environment.category, \
                self.environment.name, self.environment.version))
        out.notify("extracting archive(s) to %s" %
                   os.path.dirname(self.environment.build_dir))

        # now, extract the archives
        self.run_stage("extract")
        out.notify("%s has been extracted." % self.environment.fullname)
        shelltools.touch(extracted_file)
        if self.environment.stage == "extract":
            lpms.terminate()
Ejemplo n.º 7
0
    def __init__(self):
        root = cst.root
        for option in sys.argv:
            if option.startswith("--change-root"):
                root = option.replace("--change-root=", "")
                break
        if self.__class__.__module__.endswith(cst.repositorydb):
            self.dbpath = os.path.join(root, cst.db_path, cst.repositorydb)+cst.db_prefix
        elif self.__class__.__module__.endswith(cst.installdb):
            self.dbpath = os.path.join(root, cst.db_path, cst.installdb)+cst.db_prefix
        elif self.__class__.__module__.endswith(cst.filesdb):
            self.dbpath = os.path.join(root, cst.db_path, cst.filesdb)+cst.db_prefix
        elif self.__class__.__module__.endswith(cst.file_relationsdb):
            self.dbpath = os.path.join(root, cst.db_path, cst.file_relationsdb)+cst.db_prefix
        elif self.__class__.__module__.endswith(cst.reverse_dependsdb):
            self.dbpath = os.path.join(root, cst.db_path, cst.reverse_dependsdb)+cst.db_prefix
        else:
            raise Exception("%s seems an invalid child class." % self.__class__.__module__)

        if not os.path.exists(os.path.dirname(self.dbpath)):
            os.makedirs(os.path.dirname(self.dbpath))

        try:
            self.connection = sqlite3.connect(self.dbpath)
        except sqlite3.OperationalError:
            # TODO: Use an exception for this.
            lpms.terminate("lpms could not connected to the database (%s)" % self.dbpath)

        self.cursor = self.connection.cursor()
        table = self.cursor.execute('SELECT * FROM sqlite_master WHERE type = "table"')
        if table.fetchone() is None:
            self.initialize_db()
Ejemplo n.º 8
0
def get_depends(file_path):
    '''Parses ldd's output and returns depends of shared lib or executable file'''
    depends = []
    if not os.access(ldd_path, os.X_OK):
        out.error("%s seems problematic. please check it." % ldd_path)
        lpms.terminate()

    if not os.path.exists(file_path):
        raise FileNotFound("%s not found." % file_path)

    if not utils.get_mimetype(file_path) in ('application/x-executable', \
            'application/x-archive', 'application/x-sharedlib'):
        out.error("%s is invalid for me." % file_path)
        return

    for line in subprocess.Popen([ldd_path, file_path], \
            stdout=subprocess.PIPE).stdout:
        data = line.strip().split("=>")
        if len(data) == 2:
            parsed = data[1].split(" ")
            if parsed[1] != "":
                if shelltools.is_link(parsed[1]):
                    depends.append(shelltools.real_path(parsed[1]))
                else:
                    depends.append(parsed[1])
    return depends
Ejemplo n.º 9
0
def usage():
    out.normal("A tool that creates \'hashes\' file for lpms packages.")
    out.green("General Usage:\n")
    out.write(" $ lhashgen <spec name>\n")
    out.write("\nIf you do not give any package name with command, it scans the directory and operates all valid specs\n")
    out.write("\nUse \'--version\' to see program's version\n")
    lpms.terminate()
Ejemplo n.º 10
0
def configure():
    myconf = ""
    if opt("ssl"):
        if opt("gnutls"):
            myconf += " --with-ssl=\"gnutls\" "
        else:
            myconf += " --with-ssl=\"openssl\" "
    else:
        notify("*** ssl option is highly recommended but you disabled it ***")
        myconf += " --without-ssl "
    
    if opt("ntlm"):
        if opt("gnutls"):
            import lpms
            lpms.terminate("*** You can not use ntlm and gnutls options together, compilation is going to fail ***")

    # fix glibc-2.16 build issue
    system("sed -i -e '/gets is a/d' lib/stdio.in.h")
    conf(
    config_enable("ssl", "opie"),
    config_enable("ssl", "digest"),
    config_enable("debug"),
    config_enable("ipv6"),
    config_enable("idn", "iri"),
    config_enable("ntlm"),
    config_enable("nls"), myconf)
Ejemplo n.º 11
0
def cmake_conf(*params, **kwargs):
    '''Configures the package with given parameters'''
    installdir = kwargs.get("installdir", "/usr")
    sourcedir = kwargs.get("sourcedir", None)
    cmakelist = "CMakeLists.txt"
    if sourcedir:
        cmakelist = os.path.join(sourcedir, "CMakeLists.txt")
    if os.access(cmakelist, os.F_OK):
        if not sourcedir:
            args = 'cmake -DCMAKE_INSTALL_PREFIX=%s \
                    -DCMAKE_C_FLAGS="%s" \
                    -DCMAKE_CXX_FLAGS="%s" \
                    -DCMAKE_LD_FLAGS="%s" \
                    -DCMAKE_BUILD_TYPE=RelWithDebInfo %s %s' % (installdir, 
                            get_env("CFLAGS"),
                            get_env("CXXFLAGS"),
                            get_env("LDFLAGS"), " ".join(params), build_dir)
        else:
            args = 'cmake %s -DCMAKE_INSTALL_PREFIX=%s \
                    -DCMAKE_C_FLAGS="%s" \
                    -DCMAKE_CXX_FLAGS="%s" \
                    -DCMAKE_LD_FLAGS="%s" \
                    -DCMAKE_BUILD_TYPE=RelWithDebInfo %s %s' % (sourcedir, installdir, 
                            get_env("CFLAGS"),
                            get_env("CXXFLAGS"),
                            get_env("LDFLAGS"), " ".join(params), build_dir)
    else:
        error("no configure script found for cmake.")
        lpms.terminate()

    if not system(args):
        error("configuration failed.")
        lpms.terminate()
Ejemplo n.º 12
0
    def function_collisions(self):
        '''Checks the build environment to deal with function collisions if primary_library is not defined'''
        if self.environment.primary_library: return
        preserved_names = [
            'extract', 'prepare', 'configure', 'build', 'install',
            'collision_check', 'pre_merge', 'post_install'
            'remove'
        ]

        race_list = {}
        for library in self.environment.libraries:
            for preserved_name in preserved_names:
                if preserved_name in self.environment.raw:
                    continue
                if library + "_" + preserved_name in self.environment.raw:
                    if preserved_name in race_list:
                        if not library in race_list[preserved_name]:
                            race_list[preserved_name].append(library)
                    else:
                        race_list.update({preserved_name: [library]})

        result = [(key, race_list[key]) for key in race_list
                  if len(race_list[key]) > 1]
        if result:
            out.warn(
                "function collision detected in these stages. you should use primary_library keyword."
            )
            for item in result:
                stage, libraries = item
                out.notify(stage + ": " + ", ".join(libraries))
            lpms.terminate("please contact the package maintainer.")
Ejemplo n.º 13
0
def get_depends(file_path):
    """Parses ldd's output and returns depends of shared lib or executable file"""
    depends = []
    if not os.access(ldd_path, os.X_OK):
        out.error("%s seems problematic. please check it." % ldd_path)
        lpms.terminate()

    if not os.path.exists(file_path):
        raise FileNotFound("%s not found." % file_path)

    if not utils.get_mimetype(file_path) in (
        "application/x-executable",
        "application/x-archive",
        "application/x-sharedlib",
    ):
        out.error("%s is invalid for me." % file_path)
        return

    for line in subprocess.Popen([ldd_path, file_path], stdout=subprocess.PIPE).stdout:
        data = line.strip().split("=>")
        if len(data) == 2:
            parsed = data[1].split(" ")
            if parsed[1] != "":
                if shelltools.is_link(parsed[1]):
                    depends.append(shelltools.real_path(parsed[1]))
                else:
                    depends.append(parsed[1])
    return depends
Ejemplo n.º 14
0
def prepare():
    if opt("branding"):
        if not opt("gtk3"):
            import lpms
            lpms.terminate("branding option needs gtk3 option")
    sed("""-i -e "/minimum-uid/s:500:1000:" data/users.conf""")
    sed("""-i -e "s|/usr/sbin/nologin|/sbin/nologin|g" data/users.conf""")
Ejemplo n.º 15
0
    def calculate_hashes(self):
        def write_archive_hash(urls, file_name):
            name, version = utils.parse_pkgname(file_name)
            for url in utils.parse_url_tag(urls, name, version):
                archive_name = os.path.basename(url)
                archive_path = os.path.join(conf.LPMSConfig().src_cache, archive_name)
                if not os.access(archive_path, os.F_OK):
                    fetcher.URLFetcher().run([url])
                sha1 = utils.sha1sum(archive_path)
                shelltools.echo("hashes", "%s %s %s" % (archive_name, sha1, os.path.getsize(archive_path)))

        excepts = ('hashes')
        shelltools.remove_file("hashes")
        if len(self.files) == 0:
            self.files = os.listdir(self.current_dir)

        for f in self.files:
            if f in excepts:
                continue
            if f.endswith(cst.spec_suffix):
                out.normal("processing %s" % f)
                shelltools.echo("hashes", "%s %s %s" % (f, utils.sha1sum(f), os.path.getsize(f)))
                content = utils.import_script(f)
                if "src_url" in utils.metadata_parser(content["metadata"]).keys():
                    write_archive_hash(utils.metadata_parser(content["metadata"])["src_url"], f)
                elif "src_url" in content.keys():
                    write_archive_hash(content["src_url"], f)
                else:
                    lpms.terminate("src_url was not defined in spec")
                del content
            elif os.path.isdir(f):
                for l in os.listdir(os.path.join(self.current_dir, f)):
                    path = os.path.join(f, l)
                    out.normal("processing %s" % path)
                    shelltools.echo("hashes", "%s %s %s" %  (path, utils.sha1sum(path), os.path.getsize(path)))
Ejemplo n.º 16
0
def run(repo, remote):
    obj = GITSync(repo, remote)
    if not os.access("%s" % obj.git_binary, os.X_OK):
        lpms.terminate("%s seems not executable or not exist. Please check dev-vcs/git." % obj.git_binary)

    obj.parse_uri()
    obj.sync()
Ejemplo n.º 17
0
    def run_configure(self):
        utils.xterm_title("(%s/%s) lpms: configuring %s/%s-%s from %s" %
                          (self.environment.index, self.environment.count,
                           self.environment.category, self.environment.name,
                           self.environment.version, self.environment.repo))

        out.normal("configuring source in %s" % self.environment.build_dir)

        configured_file = os.path.join(
            os.path.dirname(os.path.dirname(self.environment.build_dir)),
            ".configured")

        if os.path.isfile(configured_file) and self.environment.resume_build:
            out.warn_notify("%s had been already configured." %
                            self.environment.fullname)
            return True

        lpms.logger.info("configuring in %s" % self.environment.build_dir)

        self.run_stage("configure")
        out.notify("%s has been configured." % self.environment.fullname)

        if not os.path.isfile(configured_file):
            touch(configured_file)
        if self.environment.stage == "configure":
            lpms.terminate()
Ejemplo n.º 18
0
def cmake_conf(*params, **kwargs):
    '''Configures the package with given parameters'''
    installdir = kwargs.get("installdir", "/usr")
    sourcedir = kwargs.get("sourcedir", None)
    cmakelist = "CMakeLists.txt"
    if sourcedir:
        cmakelist = os.path.join(sourcedir, "CMakeLists.txt")
    if os.access(cmakelist, os.F_OK):
        if not sourcedir:
            args = 'cmake -DCMAKE_INSTALL_PREFIX=%s \
                    -DCMAKE_C_FLAGS="%s" \
                    -DCMAKE_CXX_FLAGS="%s" \
                    -DCMAKE_LD_FLAGS="%s" \
                    -DCMAKE_BUILD_TYPE=RelWithDebInfo %s %s' % (
                installdir, get_env("CFLAGS"), get_env("CXXFLAGS"),
                get_env("LDFLAGS"), " ".join(params), build_dir)
        else:
            args = 'cmake %s -DCMAKE_INSTALL_PREFIX=%s \
                    -DCMAKE_C_FLAGS="%s" \
                    -DCMAKE_CXX_FLAGS="%s" \
                    -DCMAKE_LD_FLAGS="%s" \
                    -DCMAKE_BUILD_TYPE=RelWithDebInfo %s %s' % (
                sourcedir, installdir, get_env("CFLAGS"), get_env("CXXFLAGS"),
                get_env("LDFLAGS"), " ".join(params), build_dir)
    else:
        error("no configure script found for cmake.")
        lpms.terminate()

    if not system(args):
        error("configuration failed.")
        lpms.terminate()
Ejemplo n.º 19
0
def waf_configure(*args):
    if check_waf_binary():
        if not system("./waf configure --prefix=/usr %s" % " ".join(args)):
            out.error("waf configure failed.")
            lpms.terminate()
    else:
        conf()
Ejemplo n.º 20
0
def waf_install():
    if check_waf_binary():
        if not system("./waf install --destdir=%s" %  install_dir):
            out.error("waf install failed.")
            lpms.terminate()
    else:
        raw_install("DESTDIR=%s" % install_dir)
Ejemplo n.º 21
0
def configure():
    myconf = ""
    if opt("ssl"):
        if opt("gnutls"):
            myconf += " --with-ssl=\"gnutls\" "
        else:
            myconf += " --with-ssl=\"openssl\" "
    else:
        notify("*** ssl option is highly recommended but you disabled it ***")
        myconf += " --without-ssl "
    
    if opt("ntlm"):
        if opt("gnutls"):
            import lpms
            lpms.terminate("*** You can not use ntlm and gnutls options together, compilation is going to fail ***")

    # fix glibc-2.16 build issue
    system("sed -i -e '/gets is a/d' lib/stdio.in.h")
    conf(
    config_enable("ssl", "opie"),
    config_enable("ssl", "digest"),
    config_enable("debug"),
    config_enable("ipv6"),
    config_enable("idn", "iri"),
    config_enable("ntlm"),
    config_enable("nls"), myconf)
Ejemplo n.º 22
0
    def run(self):
        if lpms.getopt("--help") or len(self.params) == 0:
            self.usage()

        for param in self.params:
            param = param.split("/")
            if len(param) == 3:
                myrepo, mycategory, myname = param
                packages = self.repodb.find_package(
                    package_name=myname, package_repo=myrepo, package_category=mycategory
                )
            elif len(param) == 2:
                mycategory, myname = param
                packages = self.repodb.find_package(package_name=myname, package_category=mycategory)
            elif len(param) == 1:
                packages = self.repodb.find_package(package_name=param[0])
            else:
                out.error("%s seems invalid." % out.color("/".join(param), "brightred"))
                lpms.terminate()
            if not packages:
                out.error("%s not found!" % out.color("/".join(param), "brightred"))
                lpms.terminate()

            # Show time!
            self.show_package(packages)
Ejemplo n.º 23
0
def python_utils_build(*params, **kwargs):
    '''Builds the package by running setup.py build with given parameters'''
    python_binary = set_python_binary(kwargs)
    if not system("%s -B setup.py build %s" %
                  (python_binary, " ".join(params))):
        error("building failed.")
        lpms.terminate()
Ejemplo n.º 24
0
 def commit(self):
     try:
         return self.connection.commit()
     except sqlite3.OperationalError as err:
         # TODO: Parse the exception and show it to the user in a suitable form
         print(err)
         self.cursor.close()
         lpms.terminate()
Ejemplo n.º 25
0
 def commit(self):
     try:
         return self.connection.commit()
     except sqlite3.OperationalError as err:
         # TODO: Parse the exception and show it to the user in a suitable form
         print(err)
         self.cursor.close()
         lpms.terminate()
Ejemplo n.º 26
0
def usage():
    out.normal("A tool that creates \'hashes\' file for lpms packages.")
    out.green("General Usage:\n")
    out.write(" $ lhashgen <spec name>\n")
    out.write(
        "\nIf you do not give any package name with command, it scans the directory and operates all valid specs\n"
    )
    out.write("\nUse \'--version\' to see program's version\n")
    lpms.terminate()
Ejemplo n.º 27
0
def run(repo, remote):
    obj = GITSync(repo, remote)
    if not os.access("%s" % obj.git_binary, os.X_OK):
        lpms.terminate(
            "%s seems not executable or not exist. Please check dev-vcs/git." %
            obj.git_binary)

    obj.parse_uri()
    obj.sync()
Ejemplo n.º 28
0
def perl_utils_build(*params):
    '''Builds the package using make or perl Build commands'''
    if os.path.isfile("Makefile"):
        if not system("make %s" % " ".join(params)):
            error("make failed.")
            lpms.terminate()
    else:
        if not system("perl Build %s" % " ".join(params)):
            error("perl Build failed.")
            lpms.terminate()
Ejemplo n.º 29
0
def waf_build(*args, **kwargs):
    if "j" in kwargs:
        export("JOBS", kwargs["j"])

    if check_waf_binary():
        if not system("./waf build"):
            out.error("waf build failed.")
            lpms.terminate()
    else:
        make()
Ejemplo n.º 30
0
def perl_utils_install(arg = "install"):
    '''Installs the package using make or perl Build install commands'''
    if os.path.isfile("Makefile"):
        if not system("make %s" % arg):
            error("make failed.")
            lpms.terminate()
    else:
        if not system("perl Build install"):
            error("perl install failed.")
            lpms.terminate()
Ejemplo n.º 31
0
def perl_utils_build(*params):
    '''Builds the package using make or perl Build commands'''
    if os.path.isfile("Makefile"):
        if not system("make %s" % " ".join(params)):
            error("make failed.")
            lpms.terminate()
    else:
        if not system("perl Build %s" % " ".join(params)):
            error("perl Build failed.")
            lpms.terminate()
Ejemplo n.º 32
0
def perl_utils_install(arg="install"):
    '''Installs the package using make or perl Build install commands'''
    if os.path.isfile("Makefile"):
        if not system("make %s" % arg):
            error("make failed.")
            lpms.terminate()
    else:
        if not system("perl Build install"):
            error("perl install failed.")
            lpms.terminate()
Ejemplo n.º 33
0
 def usage(self):
     out.normal("Search given keywords in database")
     out.green("General Usage:\n")
     out.write(" $ lpms -s <keyword>\n")
     out.write("\nOther options:\n")
     for item in help_output:
         if len(item) == 2:
             out.write("%-28s: %s\n" %
                       (out.color(item[0], "green"), item[1]))
     lpms.terminate()
Ejemplo n.º 34
0
 def __init__(self):
     data = []
     lpms_conf_file = os.path.join(cst.config_dir, cst.lpms_conf_file)
     build_conf_file = os.path.join(cst.config_dir, cst.build_conf_file)
     for path in (lpms_conf_file, build_conf_file):
         if not os.path.isfile(path):
             print("FATAL ERROR: %s not found." % path)
             lpms.terminate()
         else:
             with open(path) as file_data:
                 data.extend(file_data.read().splitlines())
     super(LPMSConfig, self).__init__(data)
Ejemplo n.º 35
0
 def run_prepare(self):
     out.normal("preparing source...")
     prepared_file = os.path.join(os.path.dirname(os.path.dirname(self.environment.build_dir)), ".prepared")
     if os.path.isfile(prepared_file):
         out.warn_notify("%s had been already prepared." % self.environment.fullname)
         return True
     self.run_stage("prepare")
     out.notify("%s has been prepared." % self.environment.fullname)
     if not os.path.isfile(prepared_file):
         touch(prepared_file)
     if self.environment.stage == "prepare":
         lpms.terminate()
Ejemplo n.º 36
0
    def main(self):
        parsed = self.pkgname.split("/")
        if len(parsed) == 3:
            repo, category, name = parsed
            name, version = utils.parse_pkgname(name)
            packages = self.instdb.find_package(
                    package_repo=repo,
                    package_category=category,
                    package_name=name,
                    package_version=version
                    )
        elif len(parsed) == 2:
            category, name = parsed
            name, version = utils.parse_pkgname(name)
            packages = self.instdb.find_package(
                    package_category=category,
                    package_name=name,
                    package_version=version
                    )
        elif len(parsed) == 1:
            name, version = utils.parse_pkgname(self.pkgname)
            packages = self.instdb.find_package(
                    package_name=name,
                    package_version=version
                    )
        else:
            out.error("%s could not be recognized." % self.pkgname)
            lpms.terminate()

        if not packages:
            out.error("%s not installed." % self.pkgname)
            lpms.terminate()
        
        for package in packages:        
            symdirs = {}
            out.normal("%s/%s/%s-%s" % (package.repo, package.category, \
                    package.name, package.version))
            content = self.filesdb.get_paths_by_package(package.name, \
                    category=package.category, version=package.version)
            for item in content:
                item = item[0].encode('UTF-8')
                if os.path.islink(item):
                    out.write("%s -> %s\n" % (out.color(item, "green"), os.readlink(item)))
                    if os.path.isdir(os.path.realpath(item)):
                        symdirs[os.path.realpath(item)+"/"] = item+"/"
                else:
                    out.write(item+"\n")
                if symdirs:
                    for symdir in symdirs:
                        if item.startswith(symdir):
                            out.write("%s -> %s\n" % (out.color(item.replace(symdir, \
                                    symdirs[symdir]), "brightwhite"), out.color(item, "brightwhite")))
Ejemplo n.º 37
0
def perl_utils_configure(*params):
    '''Configures the package using perl specific ways'''
    export("PERL_MM_USE_DEFAULT", "1")

    if os.path.isfile("Build.PL"):
        if not system("perl Build.PL installdirs=vendor destdir=%s" % install_dir):
            error("configure failed.")
            lpms.terminate()
    else:
        if not system("perl Makefile.PL %s PREFIX=/usr \
                INSTALLDIRS=vendor DESTDIR=%s" % (" ".join(params), install_dir)):
            error("configure failed.")
            lpms.terminate()
Ejemplo n.º 38
0
def select_repo(data):
    available_repositories =  available_repositories()

    if not available_repositories:
        out.error("repo.conf is empty or not found. Please check it.")
        lpms.terminate()

    sorting = []
    
    for item in data:
        if item in available_repositories:
            sorting.append(valid.index(item))
    if not sorting:
        return sorting
    return valid[sorted(sorting)[0]]
Ejemplo n.º 39
0
def select_repo(data):
    available_repositories = available_repositories()

    if not available_repositories:
        out.error("repo.conf is empty or not found. Please check it.")
        lpms.terminate()

    sorting = []

    for item in data:
        if item in available_repositories:
            sorting.append(valid.index(item))
    if not sorting:
        return sorting
    return valid[sorted(sorting)[0]]
Ejemplo n.º 40
0
def perl_utils_configure(*params):
    '''Configures the package using perl specific ways'''
    export("PERL_MM_USE_DEFAULT", "1")

    if os.path.isfile("Build.PL"):
        if not system(
                "perl Build.PL installdirs=vendor destdir=%s" % install_dir):
            error("configure failed.")
            lpms.terminate()
    else:
        if not system("perl Makefile.PL %s PREFIX=/usr \
                INSTALLDIRS=vendor DESTDIR=%s" %
                      (" ".join(params), install_dir)):
            error("configure failed.")
            lpms.terminate()
Ejemplo n.º 41
0
 def run_prepare(self):
     out.normal("preparing source...")
     prepared_file = os.path.join(
         os.path.dirname(os.path.dirname(self.environment.build_dir)),
         ".prepared")
     if os.path.isfile(prepared_file):
         out.warn_notify("%s had been already prepared." %
                         self.environment.fullname)
         return True
     self.run_stage("prepare")
     out.notify("%s has been prepared." % self.environment.fullname)
     if not os.path.isfile(prepared_file):
         touch(prepared_file)
     if self.environment.stage == "prepare":
         lpms.terminate()
Ejemplo n.º 42
0
    def get_build_libraries(self):
        result = set()
        lib_index = None
        current_length = first_length = len(self.environment.libraries)

        for lib in self.environment.libraries:
            if len(lib.split("/")) == 2:
                lib_source, lib_name = lib.split("/")
                libfile = os.path.join(cst.repos, lib_source, "libraries",
                                       lib_name + ".py")
                result.add(lib_name)
            else:
                if len(self.environment.libraries) > first_length:
                    parent = self.environment.libraries[lib_index]
                    if len(parent.split("/")) == 2:
                        parents_repo = parent.split("/")[0]
                        result.add(lib)
                        libfile = os.path.join(cst.repos, parents_repo,
                                               "libraries", lib + ".py")
                    else:
                        result.add(lib)
                        libfile = os.path.join(cst.repos,
                                               self.environment.repo,
                                               "libraries", lib + ".py")
                else:
                    result.add(lib)
                    libfile = os.path.join(cst.repos, self.environment.repo,
                                           "libraries", lib + ".py")

            if not os.path.isfile(libfile):
                out.error("build library not found: %s" %
                          out.color(libfile, "red"))
                lpms.terminate()

            # import the script
            if not self.import_script(libfile):
                out.error("an error occured while processing the library: %s" \
                        % out.color(libfile, "red"))
                out.error(
                    "please report the above error messages to the library maintainer."
                )
                lpms.terminate()

            if len(self.environment.libraries) > current_length:
                lib_index = self.environment.libraries.index(lib)
                current_length = len(self.environment.libraries)

        self.environment.libraries = list(result)
Ejemplo n.º 43
0
def python_utils_install(*params, **kwargs):
    '''Installs the package with given parameters'''
    python_binary = set_python_binary(kwargs)
    if not system("%s -B setup.py install --root=%s \
            --no-compile -O0 %s" % (python_binary, install_dir, " ".join(params))):
        error("installation failed.")
        lpms.terminate()

    # This part is borrowed from PiSi
    # BEGIN
    doc_files = ('AUTHORS', 'CHANGELOG', 'CONTRIBUTORS', 'COPYING*', 'COPYRIGHT',
            'Change*', 'KNOWN_BUGS', 'LICENSE', 'MAINTAINERS', 'NEWS',
            'README*', 'PKG-INFO')

    for doc_file in doc_files:
        insdoc(doc_file)
Ejemplo n.º 44
0
    def main(self):
        parsed = self.pkgname.split("/")
        if len(parsed) == 3:
            repo, category, name = parsed
            name, version = utils.parse_pkgname(name)
            packages = self.instdb.find_package(
                package_repo=repo, package_category=category, package_name=name, package_version=version
            )
        elif len(parsed) == 2:
            category, name = parsed
            name, version = utils.parse_pkgname(name)
            packages = self.instdb.find_package(package_category=category, package_name=name, package_version=version)
        elif len(parsed) == 1:
            name, version = utils.parse_pkgname(self.pkgname)
            packages = self.instdb.find_package(package_name=name, package_version=version)
        else:
            out.error("%s could not be recognized." % self.pkgname)
            lpms.terminate()

        if not packages:
            out.error("%s not installed." % self.pkgname)
            lpms.terminate()

        for package in packages:
            symdirs = {}
            out.normal("%s/%s/%s-%s" % (package.repo, package.category, package.name, package.version))
            content = self.filesdb.get_paths_by_package(
                package.name, category=package.category, version=package.version
            )
            for item in content:
                item = item[0].encode("UTF-8")
                if os.path.islink(item):
                    out.write("%s -> %s\n" % (out.color(item, "green"), os.readlink(item)))
                    if os.path.isdir(os.path.realpath(item)):
                        symdirs[os.path.realpath(item) + "/"] = item + "/"
                else:
                    out.write(item + "\n")
                if symdirs:
                    for symdir in symdirs:
                        if item.startswith(symdir):
                            out.write(
                                "%s -> %s\n"
                                % (
                                    out.color(item.replace(symdir, symdirs[symdir]), "brightwhite"),
                                    out.color(item, "brightwhite"),
                                )
                            )
Ejemplo n.º 45
0
    def extract_tar(self, path):
        if not tarfile.is_tarfile(path):
            out.error("%s is not a valid tar file." % path)
            lpms.terminate()

        archive = tarfile.open(path, "r")
        if isinstance(self.partial, list):
            for name in archive.getnames():
                if name in self.partial:
                    archive.extract(name, path=self.location)
                else:
                    for partial in self.partial:
                        if len(name.split(partial, 1)) == 2:
                            archive.extract(name, path=self.location)
        else:
            archive.extractall(self.location)
        archive.close()
Ejemplo n.º 46
0
def python_utils_install(*params, **kwargs):
    '''Installs the package with given parameters'''
    python_binary = set_python_binary(kwargs)
    if not system("%s -B setup.py install --root=%s \
            --no-compile -O0 %s" %
                  (python_binary, install_dir, " ".join(params))):
        error("installation failed.")
        lpms.terminate()

    # This part is borrowed from PiSi
    # BEGIN
    doc_files = ('AUTHORS', 'CHANGELOG', 'CONTRIBUTORS', 'COPYING*',
                 'COPYRIGHT', 'Change*', 'KNOWN_BUGS', 'LICENSE',
                 'MAINTAINERS', 'NEWS', 'README*', 'PKG-INFO')

    for doc_file in doc_files:
        insdoc(doc_file)
Ejemplo n.º 47
0
def set_parser(set_name):
    sets = []
    for repo in available_repositories():
        repo_set_file = os.path.join(cst.repos, repo, "info/sets",
                                     "%s.set" % set_name)
        if os.path.isfile((repo_set_file)):
            sets.append(repo_set_file)

    user_set_file = "%s/%s.set" % (cst.user_sets_dir, set_name)

    if os.path.isfile(user_set_file):
        sets.append(user_set_file)

    if len(sets) > 1:
        out.normal("ambiguous for %s\n" % out.color(set_name, "green"))

        def ask():
            for c, s in enumerate(sets):
                out.write("	" + out.color(str(c + 1), "green") + ") " + s +
                          "\n")
            out.write("\nselect one of them:\n")
            out.write("to exit, press Q or q.\n")

        while True:
            ask()
            answer = sys.stdin.readline().strip()
            if answer == "Q" or answer == "q":
                lpms.terminate()
            elif answer.isalpha():
                out.warn("please give a number.")
                continue

            try:
                set_file = sets[int(answer) - 1]
                break
            except (IndexError, ValueError):
                out.warn("invalid command.")
                continue
    elif len(sets) == 1:
        set_file = sets[0]
    else:
        out.warn("%s not found!" % out.color(set_name, "red"))
        return []

    return [line for line in file(set_file).read().strip().split("\n") \
            if not line.startswith("#") and line != ""]
Ejemplo n.º 48
0
    def extract_tar(self, path):
        if not tarfile.is_tarfile(path):
            out.error("%s is not a valid tar file." % path)
            lpms.terminate()

        archive = tarfile.open(path, 'r')
        if isinstance(self.partial, list):
            for name in archive.getnames():
                if name in self.partial:
                    archive.extract(name, path=self.location)
                else:
                    for partial in self.partial:
                        if len(name.split(partial, 1)) == 2:
                            archive.extract(name, path=self.location)
        else:
            archive.extractall(self.location)
        archive.close()
Ejemplo n.º 49
0
    def calculate_hashes(self):
        def write_archive_hash(urls, file_name):
            name, version = utils.parse_pkgname(file_name)
            for url in utils.parse_url_tag(urls, name, version):
                archive_name = os.path.basename(url)
                archive_path = os.path.join(conf.LPMSConfig().src_cache,
                                            archive_name)
                if not os.access(archive_path, os.F_OK):
                    fetcher.URLFetcher().run([url])
                sha1 = utils.sha1sum(archive_path)
                shelltools.echo(
                    "hashes", "%s %s %s" %
                    (archive_name, sha1, os.path.getsize(archive_path)))

        excepts = ('hashes')
        shelltools.remove_file("hashes")
        if len(self.files) == 0:
            self.files = os.listdir(self.current_dir)

        for f in self.files:
            if f in excepts:
                continue
            if f.endswith(cst.spec_suffix):
                out.normal("processing %s" % f)
                shelltools.echo(
                    "hashes",
                    "%s %s %s" % (f, utils.sha1sum(f), os.path.getsize(f)))
                content = utils.import_script(f)
                if "src_url" in utils.metadata_parser(
                        content["metadata"]).keys():
                    write_archive_hash(
                        utils.metadata_parser(content["metadata"])["src_url"],
                        f)
                elif "src_url" in content.keys():
                    write_archive_hash(content["src_url"], f)
                else:
                    lpms.terminate("src_url was not defined in spec")
                del content
            elif os.path.isdir(f):
                for l in os.listdir(os.path.join(self.current_dir, f)):
                    path = os.path.join(f, l)
                    out.normal("processing %s" % path)
                    shelltools.echo(
                        "hashes", "%s %s %s" %
                        (path, utils.sha1sum(path), os.path.getsize(path)))
Ejemplo n.º 50
0
def extract(file_path, location, partial=False):
    if not os.path.isfile(file_path):
        lpms.terminate("%s could not found!" % file_path)
    valid_types = OrderedDict([
            ('tar.bz2', 'extract_tar'),
            ('tgz',  'extract_tar'),
            ('zip', 'extract_zip'), 
            ('lzma', 'extract_lzma'),
            ('xz', 'extract_lzma'),
            ('tar.gz', 'extract_tar'),
            ('gz', 'extract_gz')
    ])

    churchkey = Archive(location, partial)
    for file_type in valid_types:
        if file_path.endswith(file_type):
            getattr(churchkey, valid_types[file_type])(file_path)
            return
Ejemplo n.º 51
0
    def run_build(self):
        utils.xterm_title("(%s/%s) lpms: building %s/%s-%s from %s" % (self.environment.index, self.environment.count, 
            self.environment.category, self.environment.name, self.environment.version, self.environment.repo))
        out.normal("compiling source in %s" % self.environment.build_dir)
        built_file = os.path.join(os.path.dirname(os.path.dirname(
            self.environment.build_dir)), ".built")
        if os.path.isfile(built_file) and self.environment.resume_build:
            out.warn_notify("%s had been already built." % self.environment.fullname)
            return True
        
        lpms.logger.info("building in %s" % self.environment.build_dir)

        self.run_stage("build")
        out.notify("%s has been built." % self.environment.fullname)
        if not os.path.isfile(built_file):
            touch(built_file)
        if self.environment.stage == "build":
            lpms.terminate()
Ejemplo n.º 52
0
def set_parser(set_name):
    sets = []
    for repo in available_repositories():
        repo_set_file = os.path.join(cst.repos, repo, "info/sets", "%s.set" % set_name)
        if os.path.isfile((repo_set_file)):
            sets.append(repo_set_file)
            
    user_set_file = "%s/%s.set" % (cst.user_sets_dir, set_name)

    if os.path.isfile(user_set_file):
        sets.append(user_set_file)

    if len(sets) > 1:
        out.normal("ambiguous for %s\n" % out.color(set_name, "green"))
        def ask():
            for c, s in enumerate(sets):
                out.write("	"+out.color(str(c+1), "green")+") "+s+"\n")
            out.write("\nselect one of them:\n")
            out.write("to exit, press Q or q.\n")
            
        while True:
            ask()
            answer = sys.stdin.readline().strip()
            if answer == "Q" or answer == "q":
                lpms.terminate()
            elif answer.isalpha():
                out.warn("please give a number.")
                continue
            
            try:
                set_file = sets[int(answer)-1]
                break
            except (IndexError, ValueError):
                out.warn("invalid command.")
                continue
    elif len(sets) == 1:
        set_file = sets[0]
    else:
        out.warn("%s not found!" % out.color(set_name, "red"))
        return []
    
    return [line for line in file(set_file).read().strip().split("\n") \
            if not line.startswith("#") and line != ""]
Ejemplo n.º 53
0
def cmake_utils_install(*params, **kwargs):
    '''Installs the package with given parameters'''
    argument = kwargs.get("argument", "install")
    builddir = kwargs.get("builddir", None)
    currentdir = os.getcwd()
    if builddir: cd(builddir)
    args = 'make DESTDIR="%(destdir)s" \
                 %(parameters)s \
                 %(argument)s' % {
                                     'destdir'      : install_dir,
                                     'parameters'   : " ".join(params),
                                     'argument'     : argument,
                                }
    
    if not system(args):
        error("installation failed.")
        lpms.terminate()

    if builddir: cd(currentdir)
Ejemplo n.º 54
0
    def run(self):
        package = self.package.split("/")
        if len(package) == 3:
            myrepo, mycategory, myname = package
            packages = self.instdb.find_package(package_name=myname, package_repo=myrepo, package_category=mycategory)
        elif len(package) == 2:
            mycategory, myname = package
            packages = self.instdb.find_package(package_name=myname, package_category=mycategory)
        elif len(package) == 1:
            packages = self.instdb.find_package(package_name=package[0])
        else:
            out.error("%s seems invalid." % out.color("/".join(package), "brightred"))
            lpms.terminate()

        if not packages:
            out.error("%s not found!" % out.color("/".join(package), "brightred"))
            lpms.terminate()

        for package in packages:
            self.show_info(package)
Ejemplo n.º 55
0
def extract(file_path, location, partial=False):
    if not os.path.isfile(file_path):
        lpms.terminate("%s could not found!" % file_path)
    valid_types = OrderedDict(
        [
            ("tar.bz2", "extract_tar"),
            ("tgz", "extract_tar"),
            ("zip", "extract_zip"),
            ("lzma", "extract_lzma"),
            ("xz", "extract_lzma"),
            ("tar.gz", "extract_tar"),
            ("gz", "extract_gz"),
        ]
    )

    churchkey = Archive(location, partial)
    for file_type in valid_types:
        if file_path.endswith(file_type):
            getattr(churchkey, valid_types[file_type])(file_path)
            return
Ejemplo n.º 56
0
    def extract_lzma(self, path):
        if not utils.executable_path("tar"):
            lpms.terminate("please check app-arch/tar package")

        current = os.getcwd()
        os.chdir(self.location)
        cmd = utils.executable_path("tar") + " --lzma xvf %s" % path
        if path.endswith(".xz"):
            cmd = utils.executable_path("tar") + " Jxvf %s" % path

        stdout = subprocess.PIPE
        stderr = subprocess.PIPE
        result = subprocess.Popen(cmd, shell=True, stdout=stdout, stderr=stderr)
        output, err = result.communicate()
        if result.returncode != 0:
            out.error("could not extract: %s" % out.color(path, "red"))
            print(output + err)
            os.chdir(current)
            lpms.terminate()

        os.chdir(current)
Ejemplo n.º 57
0
    def get_build_libraries(self):
        result = set()
        lib_index = None
        current_length = first_length = len(self.environment.libraries)

        for lib in self.environment.libraries:
            if len(lib.split("/")) == 2:
                lib_source, lib_name = lib.split("/")
                libfile = os.path.join(cst.repos, lib_source, "libraries", lib_name+".py")
                result.add(lib_name)
            else: 
                if len(self.environment.libraries) > first_length:
                    parent = self.environment.libraries[lib_index]
                    if len(parent.split("/")) == 2:
                        parents_repo = parent.split("/")[0]
                        result.add(lib)
                        libfile = os.path.join(cst.repos, parents_repo, "libraries", lib+".py")
                    else:
                        result.add(lib)
                        libfile = os.path.join(cst.repos, self.environment.repo, "libraries", lib+".py")
                else:
                    result.add(lib)
                    libfile = os.path.join(cst.repos, self.environment.repo, "libraries", lib+".py")

            if not os.path.isfile(libfile):
                out.error("build library not found: %s" % out.color(libfile, "red"))
                lpms.terminate()

            # import the script
            if not self.import_script(libfile):
                out.error("an error occured while processing the library: %s" \
                        % out.color(libfile, "red"))
                out.error("please report the above error messages to the library maintainer.")
                lpms.terminate()

            if len(self.environment.libraries) > current_length:
                lib_index = self.environment.libraries.index(lib)
                current_length = len(self.environment.libraries)

        self.environment.libraries = list(result)