Beispiel #1
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 == "y":
            answer = _meta_.default_answer
        else:
            print("\nNew version '{0}-{1}' is available !\n".format(
                _meta_.__all__, __new_version__))
            answer = raw_input("Would you like to upgrade [y/N]? ")
        if answer in ["y", "Y"]:
            print("")   # new line after answer
        else:
            sys.exit(0)
        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__))
    sys.exit(0)
Beispiel #2
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
Beispiel #3
0
def initialization():
    '''
    Slpkg initialization, creating directories and SLACKBUILDS.TXT in
    /var/lib/slpkg/sbo_repo/ and ChangeLog.txt in /var/log/slpkg/ from
    slackbuilds.org.
    '''
    sbo_log = log_path + "sbo/"
    sbo_lib = lib_path + "sbo_repo/"
    pkg_que = lib_path + "queue"
    if not os.path.exists(log_path):
        os.mkdir(log_path)
    if not os.path.exists(lib_path):
        os.mkdir(lib_path)
    if not os.path.exists(sbo_log):
        os.mkdir(sbo_log)
    if not os.path.exists(sbo_lib):
        os.mkdir(sbo_lib)
    if not os.path.exists(pkg_que):
        os.mkdir(pkg_que)
    sbo_url = ("http://slackbuilds.org/slackbuilds/{0}/".format(slack_ver()))
    # Read SLACKBUILDS.TXT from slackbuilds.org and write in
    # /var/lib/slpkg/sbo_repo directory if not exist
    if not os.path.isfile(sbo_lib + "SLACKBUILDS.TXT"):
        print("\nslpkg ...initialization")
        sys.stdout.write("SLACKBUILDS.TXT read ...")
        sys.stdout.flush()
        SLACKBUILDS_TXT = URL((
            "http://slackbuilds.org/slackbuilds/{0}/SLACKBUILDS.TXT".format(
                slack_ver()))).reading()
        sys.stdout.write("Done\n")
        with open("{0}SLACKBUILDS.TXT".format(sbo_lib), "w") as sbo:
            sbo.write(SLACKBUILDS_TXT)
            sbo.close()
            print("File SLACKBUILDS.TXT created in {0}".format(sbo_lib))
    # Read ChangeLog.txt from slackbuilds.org and write in /var/log/slpkg/sbo/
    # directory if not exist
    if not os.path.isfile(sbo_log + "ChangeLog.txt"):
        print("\nslpkg initialization")
        sys.stdout.write("ChangeLog.txt read ...")
        sys.stdout.flush()
        ChangeLog_txt = URL((
            "http://slackbuilds.org/slackbuilds/{0}/ChangeLog.txt".format(
                slack_ver()))).reading()
        sys.stdout.write("Done\n")
        with open("{0}ChangeLog.txt".format(sbo_log), "w") as log:
            log.write(ChangeLog_txt)
            log.close()
            print("File ChangeLog.txt created in {0}".format(sbo_log))
    # We take the size of ChangeLog.txt from the server and locally
    server = FileSize(sbo_url + "ChangeLog.txt").server()
    local = FileSize(sbo_log + "ChangeLog.txt").local()
    # If the two files differ in size delete and replaced with new
    if server != local:
        os.remove("{0}{1}".format(sbo_lib, "SLACKBUILDS.TXT"))
        os.remove("{0}{1}".format(sbo_log, "ChangeLog.txt"))
        print("\nNEWS in ChangeLog.txt")
        print("slpkg ...initialization")
        sys.stdout.write("Files re-created ...")
        sys.stdout.flush()
        SLACKBUILDS_TXT = URL((
            "http://slackbuilds.org/slackbuilds/{0}/SLACKBUILDS.TXT".format(
                slack_ver()))).reading()
        ChangeLog_txt = URL((
            "http://slackbuilds.org/slackbuilds/{0}/ChangeLog.txt".format(
                slack_ver()))).reading()
        with open("{0}SLACKBUILDS.TXT".format(sbo_lib), "w") as sbo:
            sbo.write(SLACKBUILDS_TXT)
            sbo.close()
        with open("{0}ChangeLog.txt".format(sbo_log), "w") as log:
            log.write(ChangeLog_txt)
            log.close()
        sys.stdout.write("Done\n")