当前位置: 首页>>代码示例>>Python>>正文


Python Utils.splitlines方法代码示例

本文整理汇总了Python中utils.Utils.splitlines方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.splitlines方法的具体用法?Python Utils.splitlines怎么用?Python Utils.splitlines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.Utils的用法示例。


在下文中一共展示了Utils.splitlines方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: view

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import splitlines [as 别名]
 def view(self):
     PACKAGES_TXT = Utils().read_file(self.lib)
     print("")   # new line at start
     count = 0
     if self.repo != "sbo":
         for line in PACKAGES_TXT.splitlines():
             if line.startswith(self.name + ":"):
                 print(self.COLOR + line[len(self.name) + 1:] +
                       self.meta.color["ENDC"])
                 count += 1
                 if count == 11:
                     break
     else:
         for line in PACKAGES_TXT.splitlines():
             if (line.startswith(
                     "SLACKBUILD SHORT DESCRIPTION:  " + self.name + " (")):
                 count += 1
                 print(self.COLOR + line[31:] + self.meta.color["ENDC"])
     if count == 0:
         Msg().pkg_not_found("", self.name, "No matching", "\n")
     else:
         print("")   # new line at end
开发者ID:fatman2021,项目名称:slpkg,代码行数:24,代码来源:desc.py

示例2: slack

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import splitlines [as 别名]
 def slack(self):
     """
     Official slackware repository
     """
     default = "http://mirrors.slackware.com/slackware/"
     if os.path.isfile("/etc/slpkg/slackware-mirrors"):
         mirrors = Utils().read_file(
             self.meta.conf_path + "slackware-mirrors")
         for line in mirrors.splitlines():
             line = line.rstrip()
             if not line.startswith("#") and line:
                 default = line.split()[-1]
     return default
开发者ID:fatman2021,项目名称:slpkg,代码行数:15,代码来源:repositories.py

示例3: view

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import splitlines [as 别名]
 def view(self):
     """
     View slpkg config file
     """
     print("")   # new line at start
     conf_args = [
         "RELEASE",
         "REPOSITORIES",
         "BUILD_PATH",
         "PACKAGES",
         "PATCHES",
         "CHECKMD5",
         "DEL_ALL",
         "DEL_BUILD",
         "SBO_BUILD_LOG",
         "MAKEFLAGS",
         "DEFAULT_ANSWER",
         "REMOVE_DEPS_ANSWER",
         "SKIP_UNST",
         "RSL_DEPS",
         "DEL_DEPS",
         "USE_COLORS",
         "DOWNDER",
         "DOWNDER_OPTIONS",
         "SLACKPKG_LOG",
         "ONLY_INSTALLED"
     ]
     read_conf = Utils().read_file(self.config_file)
     try:
         for line in read_conf.splitlines():
             if not line.startswith("#") and line.split("=")[0] in conf_args:
                 print(line)
             else:
                 print("{0}{1}{2}".format(self.meta.color["CYAN"], line,
                                          self.meta.color["ENDC"]))
     except KeyboardInterrupt:
         print("")
         sys.exit(0)
     print("")   # new line at end
开发者ID:fatman2021,项目名称:slpkg,代码行数:41,代码来源:config.py

示例4: library

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import splitlines [as 别名]
def library(repo):
    """Load packages from slpkg library and from local
    """
    pkg_list, packages = [], ""
    if repo == "sbo":
        if (os.path.isfile(
                _meta_.lib_path + "{0}_repo/SLACKBUILDS.TXT".format(repo))):
            packages = Utils().read_file(_meta_.lib_path + "{0}_repo/"
                                         "SLACKBUILDS.TXT".format(repo))
    else:
        if (os.path.isfile(
                _meta_.lib_path + "{0}_repo/PACKAGES.TXT".format(repo))):
            packages = Utils().read_file(_meta_.lib_path + "{0}_repo/"
                                         "PACKAGES.TXT".format(repo))
    for line in packages.splitlines():
        if repo == "sbo":
            if line.startswith("SLACKBUILD NAME: "):
                pkg_list.append(line[17:].strip())
        elif "local" not in repo:
            if line.startswith("PACKAGE NAME: "):
                pkg_list.append(line[15:].strip())
    if repo == "local":
        pkg_list = find_package("", _meta_.pkg_path)
    return pkg_list
开发者ID:fatman2021,项目名称:slpkg,代码行数:26,代码来源:load.py

示例5: Repo

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import splitlines [as 别名]
class Repo(object):

    def __init__(self):
        self.meta = _meta_
        self.repo_file = "/etc/slpkg/custom-repositories"
        self.repositories_list = Utils().read_file(self.repo_file)

    def add(self, repo, url):
        """
        Write custom repository name and url in a file
        """
        repo_name = []
        if not url.endswith("/"):
            url = url + "/"
        for line in self.repositories_list.splitlines():
            line = line.lstrip()
            if line and not line.startswith("#"):
                repo_name.append(line.split()[0])
        if (repo in self.meta.repositories or repo in repo_name or
                repo in self.meta.default_repositories):
            print("\nRepository name '{0}' exist, select different name.\n"
                  "View all repositories with command 'repo-list'.\n".format(
                      repo))
            sys.exit(0)
        elif len(repo) > 6:
            print("\nMaximum repository name length must be six (6) "
                  "characters\n")
            sys.exit(0)
        with open(self.repo_file, "a") as repos:
            new_line = "  {0}{1}{2}\n".format(repo, " " * (10 - len(repo)), url)
            repos.write(new_line)
        repos.close()
        print("\nRepository '{0}' successfully added\n".format(repo))
        sys.exit(0)

    def remove(self, repo):
        """
        Remove custom repository
        """
        rem_repo = False
        with open(self.repo_file, "w") as repos:
            for line in self.repositories_list.splitlines():
                repo_name = line.split()[0]
                if repo_name != repo:
                    repos.write(line + "\n")
                else:
                    print("\nRepository '{0}' successfully "
                          "removed\n".format(repo))
                    rem_repo = True
            repos.close()
        if not rem_repo:
            print("\nRepository '{0}' doesn't exist\n".format(repo))
        sys.exit(0)

    def custom_repository(self):
        """
        Return dictionary with repo name and url
        """
        dict_repo = {}
        for line in self.repositories_list.splitlines():
            line = line.lstrip()
            if not line.startswith("#"):
                dict_repo[line.split()[0]] = line.split()[1]
        return dict_repo

    def slack(self):
        """
        Official slackware repository
        """
        default = "http://mirrors.slackware.com/slackware/"
        if os.path.isfile("/etc/slpkg/slackware-mirrors"):
            mirrors = Utils().read_file(
                self.meta.conf_path + "slackware-mirrors")
            for line in mirrors.splitlines():
                line = line.rstrip()
                if not line.startswith("#") and line:
                    default = line.split()[-1]
        return default

    def sbo(self):
        """
        SlackBuilds.org repository
        """
        return "http://slackbuilds.org/slackbuilds/"

    def rlw(self):
        """
        Robby"s repoisitory
        """
        return "http://rlworkman.net/pkgs/"

    def alien(self):
        """
        Alien"s slackbuilds repository
        """
        return "http://taper.alienbase.nl/mirrors/people/alien/sbrepos/"

    def slacky(self):
        """
        Slacky.eu repository
#.........这里部分代码省略.........
开发者ID:fatman2021,项目名称:slpkg,代码行数:103,代码来源:repositories.py

示例6: BlackList

# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import splitlines [as 别名]
class BlackList(object):
    """Blacklist class to add, remove or listed packages
    in blacklist file."""
    def __init__(self):
        self.meta = _meta_
        self.quit = False
        self.blackfile = "/etc/slpkg/blacklist"
        self.black_conf = Utils().read_file(self.blackfile)

    def get_black(self):
        """Return blacklist packages from /etc/slpkg/blacklist
        configuration file."""
        blacklist = []
        for read in self.black_conf.splitlines():
            read = read.lstrip()
            if not read.startswith("#"):
                blacklist.append(read.replace("\n", ""))
        return blacklist

    def listed(self):
        """Print blacklist packages
        """
        print("\nPackages in blacklist:\n")
        for black in self.get_black():
            if black:
                print("{0}{1}{2}".format(self.meta.color["GREEN"], black,
                                         self.meta.color["ENDC"]))
                self.quit = True
        if self.quit:
            print("")   # new line at exit

    def add(self, pkgs):
        """Add blacklist packages if not exist
        """
        blacklist = self.get_black()
        pkgs = set(pkgs)
        print("\nAdd packages in blacklist:\n")
        with open(self.blackfile, "a") as black_conf:
            for pkg in pkgs:
                if pkg not in blacklist:
                    print("{0}{1}{2}".format(self.meta.color["GREEN"], pkg,
                                             self.meta.color["ENDC"]))
                    black_conf.write(pkg + "\n")
                    self.quit = True
            black_conf.close()
        if self.quit:
            print("")   # new line at exit

    def remove(self, pkgs):
        """Remove packages from blacklist
        """
        print("\nRemove packages from blacklist:\n")
        with open(self.blackfile, "w") as remove:
            for line in self.black_conf.splitlines():
                if line not in pkgs:
                    remove.write(line + "\n")
                else:
                    print("{0}{1}{2}".format(self.meta.color["RED"], line,
                                             self.meta.color["ENDC"]))
                    self.quit = True
            remove.close()
        if self.quit:
            print("")   # new line at exit

    def packages(self, pkgs, repo):
        """Return packages in blacklist or by repository
        """
        self.black = []
        for bl in self.get_black():
            pr = bl.split(":")
            for pkg in pkgs:
                self.__priority(pr, repo, pkg)
                self.__blackpkg(bl, repo, pkg)
        return self.black

    def __add(self, repo, pkg):
        """Split packages by repository
        """
        if repo == "sbo":
            return pkg
        else:
            return split_package(pkg)[0]

    def __priority(self, pr, repo, pkg):
        """Add packages in blacklist by priority
        """
        if (pr[0] == repo and pr[1].startswith("*") and
                pr[1].endswith("*")):
            if pr[1][1:-1] in pkg:
                self.black.append(self.__add(repo, pkg))
        elif pr[0] == repo and pr[1].endswith("*"):
            if pkg.startswith(pr[1][:-1]):
                self.black.append(self.__add(repo, pkg))
        elif pr[0] == repo and pr[1].startswith("*"):
            if pkg.endswith(pr[1][1:]):
                self.black.append(self.__add(repo, pkg))
        elif pr[0] == repo and "*" not in pr[1]:
            self.black.append(self.__add(repo, pkg))

    def __blackpkg(self, bl, repo, pkg):
#.........这里部分代码省略.........
开发者ID:fatman2021,项目名称:slpkg,代码行数:103,代码来源:blacklist.py


注:本文中的utils.Utils.splitlines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。