def it_self_update():
    """Check from GitHub slpkg repository if new version is available
    download and update itself
    """
    __new_version__ = ""
    repository = "github"
    branch = "master"
    ver_link = ("https://raw.{0}usercontent.com/{1}/{2}/"
                "{3}/{4}/__metadata__.py".format(repository, _meta_.__author__,
                                                 _meta_.__all__, branch,
                                                 _meta_.__all__))
    version_data = URL(ver_link).reading()
    for line in version_data.splitlines():
        line = line.strip()
        if line.startswith("__version_info__"):
            __new_version__ = ".".join(re.findall(r"\d+", line))
    if __new_version__ > _meta_.__version__:
        if _meta_.default_answer in ["y", "Y"]:
            answer = _meta_.default_answer
        else:
            print("\nNew version '{0}-{1}' is available !\n".format(
                _meta_.__all__, __new_version__))
            try:
                answer = raw_input("Would you like to upgrade [y/N]? ")
            except EOFError:
                print("")
                raise SystemExit()
        if answer in ["y", "Y"]:
            print("")  # new line after answer
        else:
            raise SystemExit()
        dwn_link = [
            "https://{0}.com/{1}/{2}/archive/"
            "v{3}.tar.gz".format(repository, _meta_.__author__, _meta_.__all__,
                                 __new_version__)
        ]
        if not os.path.exists(_meta_.build_path):
            os.makedirs(_meta_.build_path)
        Download(_meta_.build_path, dwn_link, repo="").start()
        os.chdir(_meta_.build_path)
        slpkg_tar_file = "v" + __new_version__ + ".tar.gz"
        tar = tarfile.open(slpkg_tar_file)
        tar.extractall()
        tar.close()
        file_name = "{0}-{1}".format(_meta_.__all__, __new_version__)
        os.chdir(file_name)
        check_md5(
            pkg_checksum(_meta_.__all__ + "-" + slpkg_tar_file[1:],
                         _meta_.__all__), _meta_.build_path + slpkg_tar_file)
        subprocess.call("chmod +x {0}".format("install.sh"), shell=True)
        subprocess.call("sh install.sh", shell=True)
    else:
        print("\n{0}: There is no new version, already used the last !"
              "\n".format(_meta_.__all__))
    raise SystemExit()
Exemple #2
0
def it_self_update():
    """
    Check from GitHub slpkg repository if new version is available
    download and update itself
    """
    __new_version__ = ""
    repository = "github"
    branch = "master"
    ver_link = ("https://raw.{0}usercontent.com/{1}/{2}/"
                "{3}/{4}/__metadata__.py".format(repository, _meta_.__author__,
                                                 _meta_.__all__, branch,
                                                 _meta_.__all__))
    version_data = URL(ver_link).reading()
    for line in version_data.splitlines():
        line = line.strip()
        if line.startswith("__version_info__"):
            __new_version__ = ".".join(re.findall(r"\d+", line))
    if __new_version__ > _meta_.__version__:
        if _meta_.default_answer in ["y", "Y"]:
            answer = _meta_.default_answer
        else:
            print("\nNew version '{0}-{1}' is available !\n".format(
                _meta_.__all__, __new_version__))
            try:
                answer = raw_input("Would you like to upgrade [y/N]? ")
            except EOFError:
                print("")
                raise SystemExit()
        if answer in ["y", "Y"]:
            print("")   # new line after answer
        else:
            raise SystemExit()
        dwn_link = ["https://{0}.com/{1}/{2}/archive/"
                    "v{3}.tar.gz".format(repository, _meta_.__author__,
                                         _meta_.__all__,
                                         __new_version__)]
        if not os.path.exists(_meta_.build_path):
            os.makedirs(_meta_.build_path)
        Download(_meta_.build_path, dwn_link, repo="").start()
        os.chdir(_meta_.build_path)
        slpkg_tar_file = "v" + __new_version__ + ".tar.gz"
        tar = tarfile.open(slpkg_tar_file)
        tar.extractall()
        tar.close()
        file_name = "{0}-{1}".format(_meta_.__all__, __new_version__)
        os.chdir(file_name)
        check_md5(pkg_checksum(_meta_.__all__ + "-" + slpkg_tar_file[1:],
                               _meta_.__all__),
                  _meta_.build_path + slpkg_tar_file)
        subprocess.call("chmod +x {0}".format("install.sh"), shell=True)
        subprocess.call("sh install.sh", shell=True)
    else:
        print("\n{0}: There is no new version, already used the last !"
              "\n".format(_meta_.__all__))
    raise SystemExit()
Exemple #3
0
 def get(self):
     num = "NO_BUILD"
     if self.sbo_url:
         SlackBuild = URL("{0}{1}.SlackBuild".format(
             self.sbo_url, self.pkg)).reading()
     else:
         SlackBuild = Utils().read_file("{0}{1}/{2}.SlackBuild".format(
             self.meta.build_path, self.pkg, self.pkg))
     for line in SlackBuild.splitlines():
         line = line.lstrip()
         if line.startswith("BUILD="):
             num = re.findall(r"\d+", line)
             break
     return "".join(num)
Exemple #4
0
 def get(self):
     num = "NO_BUILD"
     if self.sbo_url:
         SlackBuild = URL("{0}{1}.SlackBuild".format(
             self.sbo_url, self.pkg)).reading()
     else:
         SlackBuild = Utils().read_file("{0}{1}/{2}.SlackBuild".format(
             self.meta.build_path, self.pkg, self.pkg))
     for line in SlackBuild.splitlines():
         line = line.lstrip()
         if line.startswith("BUILD="):
             num = re.findall(r"\d+", line)
             break
     return "".join(num)
Exemple #5
0
 def __init__(self, slack_pkg, version):
     self.slack_pkg = slack_pkg
     self.version = version
     self.tmp_path = slpkg_tmp + "packages/"
     print("\nPackages with name matching [ {0}{1}{2} ]\n".format(
         CYAN, self.slack_pkg, ENDC))
     sys.stdout.write("{0}Reading package lists ...{1}".format(GREY, ENDC))
     sys.stdout.flush()
     if not os.path.exists(slpkg_tmp):
         os.mkdir(slpkg_tmp)
     if not os.path.exists(self.tmp_path):
         os.mkdir(self.tmp_path)
     PACKAGES = URL(mirrors("PACKAGES.TXT", "", self.version)).reading()
     EXTRA = URL(mirrors("PACKAGES.TXT", "extra/", self.version)).reading()
     PASTURE = URL(mirrors("PACKAGES.TXT", "pasture/",
                           self.version)).reading()
     self.PACKAGES_TXT = PACKAGES + EXTRA + PASTURE
Exemple #6
0
 def __init__(self, version):
     self.version = version
     self.patch_path = slpkg_tmp + "patches/"
     sys.stdout.write("{0}Reading package lists ...{1}".format(GREY, ENDC))
     sys.stdout.flush()
     if not os.path.exists(slpkg_tmp):
         os.mkdir(slpkg_tmp)
     if not os.path.exists(self.patch_path):
         os.mkdir(self.patch_path)
     if version == "stable":
         self.PACKAGES_TXT = URL(
             mirrors("PACKAGES.TXT", "patches/", version)).reading()
         self.step = 100
     else:
         self.PACKAGES_TXT = URL(mirrors("PACKAGES.TXT", "",
                                         version)).reading()
         self.step = 700
Exemple #7
0
def pkg_checksum(binary, repo):
    """Return checksum from CHECKSUMS.md5 file by repository
    """
    md5 = "None"
    if repo == "slack_patches" and _meta_.slack_rel == "stable":
        CHECKSUMS_md5 = URL(mirrors("CHECKSUMS.md5", "patches/")).reading()
    elif repo == "slack_patches" and _meta_.slack_rel == "current":
        CHECKSUMS_md5 = URL(mirrors("CHECKSUMS.md5", "")).reading()
    elif repo == "slpkg":
        CHECKSUMS_md5 = URL(_meta_.CHECKSUMS_link).reading()
    else:
        lib = "{0}{1}_repo/CHECKSUMS.md5".format(_meta_.lib_path, repo)
        f = open(lib, "r")
        CHECKSUMS_md5 = f.read()
        f.close()
    for line in CHECKSUMS_md5.splitlines():
        if line.endswith("/{0}".format(binary)):
            md5 = line.split()[0]
    return md5
Exemple #8
0
 def __init__(self, skip, flag):
     self.skip = skip
     self.flag = flag
     self.meta = _meta_
     self.msg = Msg()
     self.version = self.meta.slack_rel
     self.patch_path = self.meta.slpkg_tmp_patches
     self.pkg_for_upgrade = []
     self.dwn_links = []
     self.upgrade_all = []
     self.count_added = 0
     self.count_upg = 0
     self.upgraded = []
     self.installed = []
     self.comp_sum = []
     self.uncomp_sum = []
     self.utils = Utils()
     self.msg.checking()
     if self.version == "stable":
         self.PACKAGES_TXT = URL(mirrors("PACKAGES.TXT",
                                         "patches/")).reading()
     else:
         self.PACKAGES_TXT = URL(mirrors("PACKAGES.TXT", "")).reading()
Exemple #9
0
 def slackpkg_update(self):
     """This replace slackpkg ChangeLog.txt file with new
     from Slackware official mirrors after update distribution.
     """
     NEW_ChangeLog_txt = URL(mirrors("ChangeLog.txt", "")).reading()
     if os.path.isfile(self.meta.slackpkg_lib_path + "ChangeLog.txt.old"):
         os.remove(self.meta.slackpkg_lib_path + "ChangeLog.txt.old")
     if os.path.isfile(self.meta.slackpkg_lib_path + "ChangeLog.txt"):
         shutil.copy2(self.meta.slackpkg_lib_path + "ChangeLog.txt",
                      self.meta.slackpkg_lib_path + "ChangeLog.txt.old")
         os.remove(self.meta.slackpkg_lib_path + "ChangeLog.txt")
     with open(self.meta.slackpkg_lib_path + "ChangeLog.txt", "w") as log:
         log.write(NEW_ChangeLog_txt)
         log.close()
Exemple #10
0
def pkg_checksum(binary, repo):
    """Return checksum from CHECKSUMS.md5 file by repository
    """
    md5 = "None"
    if repo == "slack_patches" and _meta_.slack_rel == "stable":
        CHECKSUMS_md5 = URL(mirrors("CHECKSUMS.md5", "patches/")).reading()
    elif repo == "slack_patches" and _meta_.slack_rel == "current":
        CHECKSUMS_md5 = URL(mirrors("CHECKSUMS.md5", "")).reading()
    elif repo == "slpkg":
        CHECKSUMS_md5 = URL(_meta_.CHECKSUMS_link).reading()
    else:
        lib = "{0}{1}_repo/CHECKSUMS.md5".format(_meta_.lib_path, repo)
        f = open(lib, "r")
        CHECKSUMS_md5 = f.read()
        f.close()
    for line in CHECKSUMS_md5.splitlines():
        if line.endswith("/{0}".format(binary)):
            md5 = line.split()[0]
    return md5
Exemple #11
0
 def doinst(self, doinst_sh):
     """Read SlackBuild doinst.sh
     """
     return URL(self.sbo_url + doinst_sh).reading()
Exemple #12
0
 def slackbuild(self, name, sbo_file):
     """Read SlackBuild file
     """
     return URL(self.sbo_url + name + sbo_file).reading()
Exemple #13
0
 def info(self, name, sbo_file):
     """Read info file
     """
     return URL(self.sbo_url + name + sbo_file).reading()
Exemple #14
0
 def readme(self, sbo_readme):
     """Read SlackBuild README file
     """
     return URL(self.sbo_url + sbo_readme).reading()
Exemple #15
0
 def info(self, name, sbo_file):
     '''
     Read info file
     '''
     return URL(self.sbo_url + name + sbo_file).reading()
Exemple #16
0
 def readme(self, sbo_readme):
     '''
     Read SlackBuild README file
     '''
     return URL(self.sbo_url + sbo_readme).reading()