Beispiel #1
0
 def parse_traceback(exception_type=None):
     '''Parse exceptions and show nice and more readable error messages'''
     out.write(
         out.color(">>", "brightred") + " %s/%s/%s-%s\n" %
         (self.environment.repo, self.environment.category,
          self.environment.name, self.environment.version))
     exc_type, exc_value, exc_traceback = sys.exc_info()
     formatted_lines = traceback.format_exception(
         exc_type, exc_value, exc_traceback)
     if not self.environment.debug:
         for item in formatted_lines:
             item = item.strip()
             if item.startswith("File"):
                 regex = re.compile(r'(\w+)\S*$')
                 regex = regex.search(item)
                 if regex is None:
                     continue
                 if regex.group() in operation_order:
                     line = re.compile(r'[^\d.]+')
                     line = line.sub('', item)
                     out.write("%s %s " %
                               (out.color("on line %s:" % line,
                                          "red"), formatted_lines[-1]))
                     break
     else:
         traceback.print_exc()
     out.error("an error occurred when running the %s function." %
               out.color(operation, "red"))
     return False
Beispiel #2
0
 def download(self, url, location=None, report_hook=None):
     # ui.debug("URL: "+str(url))
     try:
         response = urllib2.urlopen(url)
     except urllib2.URLError, e:
         out.error("%s cannot be downloaded" % out.color(url, "brightwhite"))
         return False
Beispiel #3
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
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
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
Beispiel #7
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()
Beispiel #8
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)
Beispiel #9
0
 def check_metadata_integrity(self, metadata):
     required_fields = ('summary', 'license', 'arch')
     for field in required_fields:
         if not field in metadata:
             item = self.env.repo + "/" + self.env.category + "/" + self.env.name + "-" + self.env.version
             out.error("An integrity error has been found in %s: %s field must be defined in metadata." \
                     % (item, out.color(field, "red")))
             raise IntegrityError
Beispiel #10
0
 def download(self, url, location=None, report_hook=None):
     # ui.debug("URL: "+str(url))
     try:
         response = urllib2.urlopen(url)
     except urllib2.URLError, e:
         out.error("%s cannot be downloaded" %
                   out.color(url, "brightwhite"))
         return False
Beispiel #11
0
 def check_metadata_integrity(self, metadata):
     required_fields = ('summary', 'license', 'arch')
     for field in required_fields:
         if not field in metadata:
             item = self.env.repo+"/"+self.env.category+"/"+self.env.name+"-"+self.env.version
             out.error("An integrity error has been found in %s: %s field must be defined in metadata." \
                     % (item, out.color(field, "red")))
             raise IntegrityError
Beispiel #12
0
def install_library(source, target, permission=0644):
    if not os.path.isdir(os.path.dirname(target)):
        makedirs(os.path.dirname(target))

    if os.path.islink(source):
        os.symlink(os.path.realpath(source), os.path.join(target, source))
    else:
        if not system("install -m0%o %s %s" % (permission, source, target)):
            out.error("[install_library] %s could not installed to %s." % (source, target))
            return False
Beispiel #13
0
 def get_convenient_slot(self, packages, slot):
     if slot is not None and slot.endswith("*"):
         slots = [ package.slot for package in packages ]
         selected_slots = [ item for item in slots if item.startswith(slot.replace("*", ".")) ]
         if not selected_slots:
             out.error("%s is invalid slot for %s/%s" % (slot, category, name))
             return False
         else:
             return utils.best_version(selected_slots)
     return slot
Beispiel #14
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()
Beispiel #15
0
def install_library(source, target, permission=0644):
    if not os.path.isdir(os.path.dirname(target)):
        makedirs(os.path.dirname(target))

    if os.path.islink(source):
        os.symlink(os.path.realpath(source), os.path.join(target, source))
    else:
        if not system('install -m0%o %s %s' % (permission, source, target)):
            out.error("[install_library] %s could not installed to %s." %
                      (source, target))
            return False
Beispiel #16
0
def install_readable(sources, target):
    # FIXME: Does the function create target directory?
    # what if target value is a file(insfile)??
    for source in sources:
        srcs = glob.glob(source)
        if not srcs:
            out.error("[install_readable] file not found, passing: %s" % source)
            continue
        for src in srcs:
            if not system('install -m0644 "%s" %s' % (src, target)):
                out.error("[install_readable] %s could not installed to %s." % (src, target))
                return False
Beispiel #17
0
def reload_previous_repodb():
    dirname = os.path.dirname(cst.repos)
    for _file in os.listdir(dirname):
        if _file.startswith("repositorydb") and _file.count(".") == 2:
            shelltools.copy(os.path.join(dirname, _file), cst.repositorydb_path)
            from datetime import datetime
            timestamp = _file.split(".")[-1]
            previous_date = datetime.fromtimestamp(float(timestamp)).strftime('%Y-%m-%d %H:%M:%S')
            out.normal("loading previous database copy: %s" %
                    out.color(previous_date, "red"))
            return
    out.error("no repodb backup found.")
Beispiel #18
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")))
Beispiel #19
0
def install_executable(sources, target):
    if not os.path.isdir(os.path.dirname(target)):
        makedirs(os.path.dirname(target))

    for source in sources:
        srcs = glob.glob(source)
        if len(srcs) == 0:
            raise exceptions.BuiltinError("[install_executable] file not found: %s" % source)

        for src in srcs:
            if not system("install -m0755 -o root -g root %s %s" % (src, target)):
                out.error("[install_executable] %s could not installed to %s" % (src, target))
                return False
Beispiel #20
0
def reload_previous_repodb():
    dirname = os.path.dirname(cst.repos)
    for _file in os.listdir(dirname):
        if _file.startswith("repositorydb") and _file.count(".") == 2:
            shelltools.copy(os.path.join(dirname, _file),
                            cst.repositorydb_path)
            from datetime import datetime
            timestamp = _file.split(".")[-1]
            previous_date = datetime.fromtimestamp(
                float(timestamp)).strftime('%Y-%m-%d %H:%M:%S')
            out.normal("loading previous database copy: %s" %
                       out.color(previous_date, "red"))
            return
    out.error("no repodb backup found.")
Beispiel #21
0
def install_readable(sources, target):
    #FIXME: Does the function create target directory?
    # what if target value is a file(insfile)??
    for source in sources:
        srcs = glob.glob(source)
        if not srcs:
            out.error("[install_readable] file not found, passing: %s" %
                      source)
            continue
        for src in srcs:
            if not system('install -m0644 "%s" %s' % (src, target)):
                out.error("[install_readable] %s could not installed to %s." %
                          (src, target))
                return False
Beispiel #22
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]]
Beispiel #23
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]]
Beispiel #24
0
    def initialize(self):
        # Run command line client to drive lpms
        # Run actions, respectively
        if self.request.operations:
            for operation in self.request.operations:
                # TODO: We should use signals to determine behavior of lpms
                # when the process has finished.
                getattr(self, operation)()
            return

        if self.request.names:
            # Now, we can start building packages.
            self.package_mangler()
        else:
            out.error("nothing given.")
            sys.exit(0)
Beispiel #25
0
def remove_dir(source_dir):
    if is_link(source_dir):
        os.unlink(source_dir)
        return

    if is_dir(source_dir):
        try:
            # rmtree gets string
            shutil.rmtree(str(source_dir))
        except OSError as err:
            raise exceptions.BuiltinError("[remove_dir] an error occured while removing: %s" % source_dir)
    elif is_file(source_dir):
        pass
    else:
        out.error("[remove_dir] directory %s doesn't exists." % source_dir)
        return False
Beispiel #26
0
def install_executable(sources, target):
    if not os.path.isdir(os.path.dirname(target)):
        makedirs(os.path.dirname(target))

    for source in sources:
        srcs = glob.glob(source)
        if len(srcs) == 0:
            raise exceptions.BuiltinError(
                "[install_executable] file not found: %s" % source)

        for src in srcs:
            if not system('install -m0755 -o root -g root %s %s' %
                          (src, target)):
                out.error("[install_executable] %s could not installed to %s" %
                          (src, target))
                return False
Beispiel #27
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"),
                                )
                            )
Beispiel #28
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()
Beispiel #29
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()
Beispiel #30
0
 def fetch(command, download_plan, location):
     #current = os.getcwd()
     if location is not None:
         os.chdir(location)
     else:
         os.chdir(config.src_cache)
     for url in download_plan:
         localfile = os.path.basename(url)
         partfile  = localfile+".part"
         output = shelltools.system(command+" "+partfile+" "+url, show=True, sandbox=False)
         if not output:
             out.error(url+" cannot be downloaded")
             return False
         else:
             shelltools.move(partfile, localfile)
     #os.chdir(current)
     return True
Beispiel #31
0
def remove_dir(source_dir):
    if is_link(source_dir):
        os.unlink(source_dir)
        return

    if is_dir(source_dir):
        try:
            # rmtree gets string
            shutil.rmtree(str(source_dir))
        except OSError as err:
            raise exceptions.BuiltinError(
                "[remove_dir] an error occured while removing: %s" %
                source_dir)
    elif is_file(source_dir):
        pass
    else:
        out.error("[remove_dir] directory %s doesn\'t exists." % source_dir)
        return False
Beispiel #32
0
 def check_conflicts(dependency):
     for item in self.conflicts:
         if dependency.pk in self.conflicts[item]:
             out.error("%s/%s/%s-%s has a conflict with %s" % (
                 self.package_heap[item].repo,
                 self.package_heap[item].category,
                 self.package_heap[item].name,
                 self.package_heap[item].version,
                 dependency.pk)
             )
             out.error("on the other hand, %s/%s/%s-%s wants to install with %s" % (
                 package.repo,
                 package.category,
                 package.name,
                 package.version,
                 dependency.pk
             ))
             raise ConflictError
Beispiel #33
0
    def read_news(self, news_id):
        try:
            news_id = int(news_id)
            repo, metadata, message = self.cursor.data[news_id]
        except ValueError:
            out.error("invalid id: %s" % news_id)
            return
        except IndexError:
            out.error("message found not found with this id: %d" % news_id)
            return

        out.write(out.color("from", "green")+": "+metadata["from"]+"\n")
        out.write(out.color("summary", "green")+": "+metadata["summary"]+"\n")
        out.write(out.color("date", "green")+": "+metadata["date"]+"\n")
        out.write(out.color("priority", "green")+": "+metadata["priority"]+"\n")
        out.write(message+"\n")

        self.cursor.mark_as_read("%s/%s" % (repo, metadata["summary"]))
Beispiel #34
0
    def external_fetcher(self, command, download_plan, location):
        # run command
        def fetch(command, download_plan, location):
            #current = os.getcwd()
            if location is not None:
                os.chdir(location)
            else:
                os.chdir(config.src_cache)
            for url in download_plan:
                localfile = os.path.basename(url)
                partfile = localfile + ".part"
                output = shelltools.system(command + " " + partfile + " " +
                                           url,
                                           show=True,
                                           sandbox=False)
                if not output:
                    out.error(url + " cannot be downloaded")
                    return False
                else:
                    shelltools.move(partfile, localfile)
            #os.chdir(current)
            return True

        # parse fetch command
        realcommand = command.split(" ")[0]
        isexist = False
        if realcommand.startswith("/"):
            if not os.path.isfile(realcommand):
                out.error(
                    out.color("EXTERNAL FETCH COMMAND: ", "red") +
                    realcommand + " not found!")
                lpms.terminate()
            return fetch(command, download_plan, location)
        else:
            for syspath in os.environ["PATH"].split(":"):
                if os.path.isfile(os.path.join(syspath, realcommand)):
                    # this is no good
                    isexist = True
                    return fetch(command, download_plan, location)
            if not isexist:
                out.error(
                    out.color("EXTERNAL FETCH COMMAND: ", "red") +
                    realcommand + " not found!")
                lpms.terminate()
Beispiel #35
0
 def fetch(command, download_plan, location):
     #current = os.getcwd()
     if location is not None:
         os.chdir(location)
     else:
         os.chdir(config.src_cache)
     for url in download_plan:
         localfile = os.path.basename(url)
         partfile = localfile + ".part"
         output = shelltools.system(command + " " + partfile + " " +
                                    url,
                                    show=True,
                                    sandbox=False)
         if not output:
             out.error(url + " cannot be downloaded")
             return False
         else:
             shelltools.move(partfile, localfile)
     #os.chdir(current)
     return True
Beispiel #36
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)
Beispiel #37
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)
Beispiel #38
0
def remove_file(pattern):
    src = glob.glob(pattern)
    if len(src) == 0:
        out.error("[remove_file] no file matched pattern: %s." % pattern)
        return False

    for path in src:
        if is_link(path):
            try:
                os.unlink(path)
            except OSError as err:
                raise exceptions.BuiltinError("[remove_file] an error occured: %s" % path)
        elif is_file(path):
            try:
                os.remove(path)
            except OSError as err:
                raise exceptions.BuiltinError("[remove_file] an error occured: %s" % path)
        elif not is_dir(path):
            out.error("[remove_file] file %s doesn't exists." % path)
            return False
Beispiel #39
0
    def select(self):
        preform = self.package.split("/")
        if len(preform) == 3:
            self.repo, self.category, fullname = preform
        elif len(preform) == 2:
            self.category, fullname = preform
        elif len(preform) == 1:
            fullname = self.package

        if cst.slot_indicator in fullname:
            fullname, self.slot = fullname.split(":")

        self.name, self.version = utils.parse_pkgname(fullname)

        packages = self.database.find_package(package_repo=self.repo, package_name=self.name, \
                package_category=self.category, package_version=self.version)

        if not packages:
            raise PackageNotFound(self.package)

        convenient_arches = utils.get_convenient_arches(self.conf.arch)

        try:
            the_package = utils.get_convenient_package(packages, self.locked_packages, \
                    self.custom_arch_request, convenient_arches, self.database, self.slot)
        except UnavailablePackage:
            for package in packages:
                out.error("%s/%s/%s-%s:%s is unavailable for your arch(%s)." % (package.repo, package.category, \
                        package.name, package.version, package.slot, self.conf.arch))
            lpms.terminate()
        except LockedPackage:
            out.error(
                "these package(s) is/are locked by the system administrator:")
            for package in packages:
                out.error_notify("%s/%s/%s-%s:%s" % (package.repo, package.category, \
                        package.name, package.version, package.slot))
            lpms.terminate()

        if the_package is None:
            raise UnavailablePackage(self.package)
        return the_package
Beispiel #40
0
    def read_news(self, news_id):
        try:
            news_id = int(news_id)
            repo, metadata, message = self.cursor.data[news_id]
        except ValueError:
            out.error("invalid id: %s" % news_id)
            return
        except IndexError:
            out.error("message found not found with this id: %d" % news_id)
            return

        out.write(out.color("from", "green") + ": " + metadata["from"] + "\n")
        out.write(
            out.color("summary", "green") + ": " + metadata["summary"] + "\n")
        out.write(out.color("date", "green") + ": " + metadata["date"] + "\n")
        out.write(
            out.color("priority", "green") + ": " + metadata["priority"] +
            "\n")
        out.write(message + "\n")

        self.cursor.mark_as_read("%s/%s" % (repo, metadata["summary"]))
Beispiel #41
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)
Beispiel #42
0
    def main(self):
        if not self.command_line:
            out.error("no command given.")
            return

        for command in self.command_line:
            if command == "list":
                self.list_news()
                return
            elif command == "read":
                id_index = self.command_line.index(command) + 1
                try:
                    self.cursor.get_all_news()
                    news_id = self.command_line[id_index]
                    self.read_news(news_id)
                    return
                except IndexError:
                    out.error("you must give a index number!")
                    return
            elif command in ("--help", "-h"):
                self.usage()
                return
            elif command in ("--help", "-h"):
                out.write("lnews %s\n" % __version__)
                return
            else:
                out.error("invalid command: %s" % command)
                return
Beispiel #43
0
    def select(self):
        preform = self.package.split("/")
        if len(preform) == 3:
            self.repo, self.category, fullname = preform
        elif len(preform) == 2:
            self.category, fullname = preform
        elif len(preform) == 1:
            fullname = self.package

        if cst.slot_indicator in fullname:
            fullname, self.slot = fullname.split(":")
        
        self.name, self.version = utils.parse_pkgname(fullname)
        
        packages = self.database.find_package(package_repo=self.repo, package_name=self.name, \
                package_category=self.category, package_version=self.version)
        
        if not packages:
            raise PackageNotFound(self.package)

        convenient_arches = utils.get_convenient_arches(self.conf.arch)

        try:
            the_package = utils.get_convenient_package(packages, self.locked_packages, \
                    self.custom_arch_request, convenient_arches, self.database, self.slot)
        except UnavailablePackage:
            for package in packages:
                out.error("%s/%s/%s-%s:%s is unavailable for your arch(%s)." % (package.repo, package.category, \
                        package.name, package.version, package.slot, self.conf.arch))
            lpms.terminate()
        except LockedPackage:
            out.error("these package(s) is/are locked by the system administrator:")
            for package in packages:
                out.error_notify("%s/%s/%s-%s:%s" % (package.repo, package.category, \
                        package.name, package.version, package.slot))
            lpms.terminate()

        if the_package is None:
            raise UnavailablePackage(self.package)
        return the_package
Beispiel #44
0
    def main(self):
        if not self.command_line:
            out.error("no command given.")
            return

        for command in self.command_line:
            if command == "list":
                self.list_news()
                return
            elif command == "read":
                id_index = self.command_line.index(command) + 1
                try:
                    self.cursor.get_all_news()
                    news_id = self.command_line[id_index]
                    self.read_news(news_id)
                    return
                except IndexError:
                    out.error("you must give a index number!")
                    return
            elif command in ("--help", "-h"):
                self.usage()
                return
            elif command in ("--help", "-h"):
                out.write("lnews %s\n" % __version__)
                return
            else:
                out.error("invalid command: %s" % command)
                return
Beispiel #45
0
def remove_file(pattern):
    src = glob.glob(pattern)
    if len(src) == 0:
        out.error("[remove_file] no file matched pattern: %s." % pattern)
        return False

    for path in src:
        if is_link(path):
            try:
                os.unlink(path)
            except OSError as err:
                raise exceptions.BuiltinError(
                    "[remove_file] an error occured: %s" % path)
        elif is_file(path):
            try:
                os.remove(path)
            except OSError as err:
                raise exceptions.BuiltinError(
                    "[remove_file] an error occured: %s" % path)
        elif not is_dir(path):
            out.error("[remove_file] file %s doesn\'t exists." % path)
            return False
Beispiel #46
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)
Beispiel #47
0
 def mangle_spec(self):
     # TODO: Use more convenient exceptions for error states.
     '''Compiles the spec file and imports its content to lpms' build environment.'''
     if not os.path.isfile(self.internals.env.spec_file):
         out.error("%s could not be found!" % self.internals.env.spec_file)
         raise BuildError
     elif not os.access(self.internals.env.spec_file, os.R_OK):
         out.error("%s is not readable!" % self.internals.env.spec_file)
         raise BuildError
     # TODO: Use a more proper name for import_script
     if not self.internals.import_script(self.internals.env.spec_file):
         out.error("an error occured while processing the spec: %s" \
                 % out.color(self.internals.env.spec_file, "red"))
         # TODO: Here, show package maintainer and bugs_to 
         out.error("please report the above error messages to the package maintainer.")
         raise BuildError
Beispiel #48
0
 def parse_traceback(exception_type=None):
     '''Parse exceptions and show nice and more readable error messages'''
     out.write(out.color(">>", "brightred")+" %s/%s/%s-%s\n" % (self.environment.repo, self.environment.category, 
         self.environment.name, self.environment.version))
     exc_type, exc_value, exc_traceback = sys.exc_info()
     formatted_lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
     if not self.environment.debug:
         for item in formatted_lines:
             item = item.strip()
             if item.startswith("File"):
                 regex = re.compile(r'(\w+)\S*$')
                 regex = regex.search(item)
                 if regex is None:
                     continue
                 if regex.group() in operation_order:
                     line = re.compile(r'[^\d.]+')
                     line = line.sub('', item)
                     out.write("%s %s " % (out.color("on line %s:" % line, "red"), formatted_lines[-1]))
                     break
     else:
         traceback.print_exc()
     out.error("an error occurred when running the %s function." % out.color(operation, "red"))
     return False
Beispiel #49
0
    def external_fetcher(self, command, download_plan, location):
        # run command
        def fetch(command, download_plan, location):
            #current = os.getcwd()
            if location is not None:
                os.chdir(location)
            else:
                os.chdir(config.src_cache)
            for url in download_plan:
                localfile = os.path.basename(url)
                partfile  = localfile+".part"
                output = shelltools.system(command+" "+partfile+" "+url, show=True, sandbox=False)
                if not output:
                    out.error(url+" cannot be downloaded")
                    return False
                else:
                    shelltools.move(partfile, localfile)
            #os.chdir(current)
            return True

        # parse fetch command
        realcommand = command.split(" ")[0]
        isexist = False
        if realcommand.startswith("/"):
            if not os.path.isfile(realcommand):
                out.error(out.color("EXTERNAL FETCH COMMAND: ", "red")+realcommand+" not found!")
                lpms.terminate()
            return fetch(command, download_plan, location)
        else:
            for syspath in os.environ["PATH"].split(":"):
                if os.path.isfile(os.path.join(syspath, realcommand)):
                    # this is no good
                    isexist = True
                    return fetch(command, download_plan, location)
            if not isexist:
                out.error(out.color("EXTERNAL FETCH COMMAND: ", "red")+realcommand+" not found!")
                lpms.terminate()
Beispiel #50
0
 def mangle_spec(self):
     # TODO: Use more convenient exceptions for error states.
     '''Compiles the spec file and imports its content to lpms' build environment.'''
     if not os.path.isfile(self.internals.env.spec_file):
         out.error("%s could not be found!" % self.internals.env.spec_file)
         raise BuildError
     elif not os.access(self.internals.env.spec_file, os.R_OK):
         out.error("%s is not readable!" % self.internals.env.spec_file)
         raise BuildError
     # TODO: Use a more proper name for import_script
     if not self.internals.import_script(self.internals.env.spec_file):
         out.error("an error occured while processing the spec: %s" \
                 % out.color(self.internals.env.spec_file, "red"))
         # TODO: Here, show package maintainer and bugs_to
         out.error(
             "please report the above error messages to the package maintainer."
         )
         raise BuildError
Beispiel #51
0
def pkgsplit(mypkg, silent=1):
    myparts = string.split(mypkg, '-')
    if len(myparts) < 2:
        if not silent:
            out.error("name error in %s: missing a version or name part." %
                      mypkg)
        return None

    for x in myparts:
        if len(x) == 0:
            if not silent:
                out.error("name error in %s: empty \'-\' part." % mypkg)
            return None

    if revverify(myparts[-1]):
        if ververify(myparts[-2]):
            if len(myparts) == 2:
                return None
            else:
                for x in myparts[:-2]:
                    if ververify(x):
                        return None
                return "-".join(myparts[:-2]), myparts[-2] + "-" + myparts[-1]
        else:
            return None

    elif ververify(myparts[-1], silent):
        if len(myparts) == 1:
            if not silent:
                out.error("name error in %s: missing name part." % mypkg)
            return None
        else:
            for x in myparts[:-1]:
                if ververify(x):
                    if not silent:
                        out.error("name error in %s: multiple version parts." %
                                  mypkg)
                    return None
            return "-".join(myparts[:-1]), myparts[-1]
    else:
        return None
Beispiel #52
0
class URLFetcher:
    def __init__(self):
        self.chunk_size = 8192
        self.begining = time.time()

    def estimated_time(self, current_size, total_size, time):
        # odun, great job! :p
        if current_size == 0:
            current_size = 1
        elapsed = (total_size * (time / current_size) - time)
        # 1 = >> hour
        # 2 = >> minute
        # 3 = >> second
        return "[%.2d:%.2d:%.2d]" % ((elapsed / 3600), ((elapsed % 3600 / 60)),
                                     (elapsed % 60))

    def fetcher_ui(self, bytes_so_far, total_size, filename):
        # our ui :) no progress bar or others...
        sys.stdout.write(
            "\r%s %s/%s (%0.2f%%) %s" %
            (out.color(filename, "brightwhite"),
             str(bytes_so_far / 1024) + "kb", str(total_size / 1024) + "kb",
             round((float(bytes_so_far) / total_size) * 100, 2),
             self.estimated_time((bytes_so_far / 1024), (total_size / 1024),
                                 (time.time() - self.begining))))

        if bytes_so_far >= total_size:
            sys.stdout.write('\n')
        sys.stdout.flush()

    def download(self, url, location=None, report_hook=None):
        # ui.debug("URL: "+str(url))
        try:
            response = urllib2.urlopen(url)
        except urllib2.URLError, e:
            out.error("%s cannot be downloaded" %
                      out.color(url, "brightwhite"))
            return False
        except urllib2.HTTPError, e:
            out.error("%s cannot be downloaded" %
                      out.color(url, "brightwhite"))
            return False
Beispiel #53
0
def pkgsplit(mypkg, silent = 1):
    myparts = string.split(mypkg, '-')
    if len(myparts) < 2:
        if not silent:
            out.error("name error in %s: missing a version or name part." % mypkg)
        return None
    
    for x in myparts:
        if len(x) == 0:
            if not silent:
                out.error("name error in %s: empty \'-\' part." % mypkg)
            return None

    if revverify(myparts[-1]):
        if ververify(myparts[-2]):
            if len(myparts) == 2:
                return None
            else:
                for x in myparts[:-2]:
                    if ververify(x):
                        return None
                return "-".join(myparts[:-2]), myparts[-2]+"-"+myparts[-1]
        else:
            return None

    elif ververify(myparts[-1], silent):
        if len(myparts) == 1:
            if not silent:
                out.error("name error in %s: missing name part." % mypkg)
            return None
        else:
            for x in myparts[:-1]:
                if ververify(x):
                    if not silent:
                        out.error("name error in %s: multiple version parts." % mypkg)
                    return None
            return "-".join(myparts[:-1]), myparts[-1]
    else:
        return None
Beispiel #54
0
def update_info_index(info_path, dir_path="/usr/share/info/dir", delete=False):
    '''Updates GNU Info file index'''
    if os.access(info_path, os.R_OK):
        if not os.access("/usr/bin/install-info", os.X_OK):
            out.error("/usr/bin/install-info seems broken. please check sys-apps/texinfo")
            return False
        if delete:
            command = "/usr/bin/install-info --delete %s %s" % (info_path, dir_path)
        else:
            command = "/usr/bin/install-info %s %s" % (info_path, dir_path)
        if not shelltools.system(command, sandbox=False):
            out.error("%s not updated. info file: %s" % (dir_path, info_path))
            return False
    else:
        out.error("%s not found" % info_path)
        return False
    return True
Beispiel #55
0
    def append_merge_conf(self, item):
        '''Handles merge-conf file'''
        try:
            if not os.access(self.merge_conf_file, os.F_OK) \
                    or os.access(self.merge_conf_file, os.R_OK):
                        self.merge_conf_data = shelve.open(self.merge_conf_file)
            else:
                # TODO: We should develop a message system for warning the user 
                out.error("%s seems not readable." % self.merge_conf_file)
                out.error("Merge process is going to proceed but you must handle configuration files manually.")
                out.error("Please check this file for merging: %s" % item)
                return

            package = str(os.path.join(self.environment.category, self.environment.name, \
                    self.environment.version)+":"+self.environment.slot)
            if package in self.merge_conf_data:
                self.merge_conf_data[package].add(item)
            else:
                self.merge_conf_data[package] = set([item])
        finally:
            self.merge_conf_data.close()