예제 #1
0
def check( PAK, WORKDIR):
    if( PAK.endswith(".json") == False):
        PAK = PAK+".json"
    INSTDIR = packages.getInstdir(PAK)
    INSTALLSCRIPT = packages.getInstallScript(PAK)
    HOMEROOT=os.path.abspath(os.curdir)
    os.chdir(WORKDIR+INSTDIR)
    if( INSTALLSCRIPT != None):
        os.chdir(HOMEROOT)
        return os.path.abspath(WORKDIR+INSTDIR+INSTALLSCRIPT)
    if(os.access("Makefile", os.R_OK) == True):
        CXX="make"
        os.chdir(HOMEROOT)
        return CXX
    elif( os.access("CMakeLists.txt", os.R_OK) == True):
        CXX="cmake && make"
        GEN="\"Unix Makefiles\""
        if( os.name.lower() == "msys" ):
            GEN="\"MSYS Makefiles\""
        os.chdir(HOMEROOT)
        return CXX+" -G "+GEN
    elif( os.access("configure", os.X_OK) == True):
        CXX="configure && make"
        os.chdir(HOMEROOT)
        return CXX+" --prefix=/usr/bin"
    else:
        os.chdir(HOMEROOT)
        return None
예제 #2
0
def update(PAK, MIRROR, WORKDIR):
    """
    Update package 'PAK' in packages.rules.
    MIRROR is either a http or a ftp URL
    WORKDIR is the root directory to install everything to.
    """
    if( MIRROR.endswith("/PAK/") == False ):
        MIRROR = MIRROR+"/PAK/"
    elif( MIRROR.endswith("PAK/") == False):
        MIRROR = MIRROR+"PAK/"
    # --- Below this line: SETUP VARIABLES ---
    if(PAK.endswith(".json")==False):
        if(os.path.isdir("packages.rules"+os.sep+PAK)):
            return
        PAK=PAK+".json"  # Easier JSON reading in the future.
                            # Works better than constantly appending '.json' to PAK.
    TARFILE=packages.getTarfile(PAK)
    if (TARFILE == None):
        print( PAK+" doesn't point to a file. What do?")
        sys.exit(1)
    if (TARFILE.startswith("http://") == True or TARFILE.startswith("ftp://") == True or TARFILE.startswith("https://") == True):
        FILE = TARFILE.split("/")[-1]
        MIRROR=TARFILE[0:-len(FILE)]
        TARFILE=TARFILE[-len(FILE):]
    if( TARFILE.endswith("bz2") == True):
        TARTYPE = "bz2"
    elif( TARFILE.endswith( "gz") == True):
        TARTYPE = "gz"
    else:
        print( bcolors.RED+"* WARNING"+bcolors.ENDC+": Tar file isn't bz2 or gzip")
    NAME = json.loads( open( "packages.rules"+os.sep+PAK).read() ).get("name")
    if (NAME == None):
        NAME=TARFILE[:-8]
    INSTDIR=packages.getInstdir(PAK)
    if( os.path.exists(WORKDIR) == False):
        os.mkdir(WORKDIR)
    DEPENDS = []
    DEPENDS=packages.getDepend(PAK)
    bcolors.YES = bcolors.GREEN+"Y"+bcolors.ENDC
    bcolors.NO = bcolors.RED+"n"+bcolors.ENDC
    if( DEPENDS != None):
        for DEPEND in DEPENDS:
            DEPENDTAR = packages.getTarfile(DEPEND+".json")
            if( os.path.exists( "packages.checksum"+os.sep+DEPENDTAR+".checksum" ) == True):
                DEPENDS.remove(DEPEND)
                continue
        if( DEPENDS != [] ):
            print( PAK+" depends on" )
            print( DEPENDS )
            print( "Install above dependencies?"+" ["+bcolors.YES+"/"+bcolors.NO+"]")
            IN = input()
            if( IN.endswith("\r")==True ):
                IN = IN[:-1]
            while( IN.lower() != "y" or IN.lower() != "yes"):
                if( IN.lower() == "n" or IN.lower() == "no"):
                    return
                if( IN.lower() == "y" or IN.lower() == "yes"):
                    break
                if( IN.lower() == "" ):
                    break
                print( "Sorry, answer not recognized '"+IN+"'" )
                IN = input()
                if( IN.endswith("\r")==True ):
                    IN = IN[:-1]
            for DEPEND in DEPENDS:
                RETCODE = update(DEPEND, MIRROR, WORKDIR)
                if( RETCODE == 1):
                    sys.exit(1)
                DEPENDS.remove(DEPEND)
    INSTALLSCRIPT = packages.getInstallScript(PAK) # If this isn't needed, we won't use it.

    # --- Below this line: PRINT PACKAGE CRITICAL INFO ---
    print( bcolors.GREEN+"*"+bcolors.ENDC+" "+"Name"+": "+NAME)
    print( bcolors.GREEN+"*"+bcolors.ENDC+" "+"Package JSON"+": "+PAK)
    print( bcolors.GREEN+"*"+bcolors.ENDC+" "+"Package file"+": "+TARFILE)

    # --- Below this line: ACTUALLY UPDATE PACKAGE 'PAK' ---
    print(">>> Fetching checksum"+" '"+TARFILE+".checksum'")
    get.download(args.VERBOSE,MIRROR+TARFILE+".checksum", WORKDIR+TARFILE+".checksum")
    m = open(WORKDIR+TARFILE+".checksum", 'r').read()
    print( bcolors.GREEN+"*"+bcolors.ENDC+" SHA-1: "+m.split("\n")[0] )
    if ( os.path.exists("packages.checksum"+os.sep+TARFILE+".checksum") == False ):
        if ( os.access("packages.checksum"+os.sep, os.F_OK) == False):
            os.mkdir("packages.checksum")
        print( ">>> Downloading"+" '"+TARFILE+"' -> '"+WORKDIR+TARFILE+"'")
        get.download( True, MIRROR+TARFILE, WORKDIR+TARFILE )
        m = hashlib.sha1(open(WORKDIR+TARFILE, "rb").read()).hexdigest()
    else:
        mm = open("packages.checksum"+os.sep+TARFILE+".checksum", "r").read()
        if ( m == mm ):
            print( "Project is up-to-date!")
            clean.rm(WORKDIR+TARFILE+".checksum")
            return
        else:
            print( ">>> Downloading"+" '"+TARFILE+"' -> '"+WORKDIR+TARFILE+"'")
            get.download( True, MIRROR+TARFILE, WORKDIR+TARFILE )
            m = hashlib.sha1(open(WORKDIR+TARFILE, "rb").read()).hexdigest()
            
    # --- Below this line: EXTRACT UPDATE PACKAGE 'PAK' ---
    FILE = tarfile.open(WORKDIR+TARFILE, 'r')
    if( args.VERBOSE == False ):
        print( ">>> Extracting '"+TARFILE+"' -> '"+WORKDIR+INSTDIR+"'")
        FILE.extractall(WORKDIR+INSTDIR)
    else:
        print( ">>> Extracting '"+FILE.name.split(os.sep)[-1]+"'" )
        MEMBERS=FILE.getmembers()
        for MEMBS in MEMBERS:
            print( ">>> '"+WORKDIR+INSTDIR+MEMBS.name+"'")
            FILE.extract(MEMBS.name, WORKDIR+INSTDIR)
    FILE.close()
    del FILE
    clean.rm(WORKDIR+TARFILE)
    
    # --- Below this line: INSTALLSCRIPT ---
    CXX = compile.check(PAK, WORKDIR=WORKDIR)
    if( CXX != None):
        print( bcolors.GREEN+"*"+bcolors.ENDC+" CXX: "+CXX)
        CXX = compile.compile(PAK, CXX, WORKDIR)
    if( CXX != None and CXX != 0 ):
        print( bcolors.RED+"[ERROR]: Couldn't compile!" )
        print( ">>> Cleaning up and returning 1!"+bcolors.ENDC )
        # clean.rm( WORKDIR+INSTDIR ) -- NO U
        clean.rm( WORKDIR+TARFILE )
        clean.rm( WORKDIR+TARFILE+".checksum" )
        return 1
    del CXX

    # --- Below this line: sha1 hash generation ---
    mOut = open("packages.checksum"+os.sep+TARFILE+".checksum", "w")
    mOut.write(m)
    mOut.close()
    del m
    os.remove(WORKDIR+TARFILE+".checksum")

    # --- Below this line: Project is now installed, write to "packages.installed" ---
    if( os.path.isfile( "packages.installed" ) == False):
        PACKINST = []
    else:
        PACKINST = open( "packages.installed", "r" ).read().split("\n")
    while( PACKINST.count(PAK[:-5]) > 0 ):
        PACKINST.remove(PAK[:-5])
    while( PACKINST.count("\n") > 0 ):
        PACKINST.remove("\n")
    while( PACKINST.count("") > 0 ):
        PACKINST.remove("")
    PACKOUT = open( "packages.installed", "w" )
    for LINES in PACKINST:
        PACKOUT.write(LINES+"\n")
    PACKOUT.write(PAK[:-5]+"\n")
    PACKOUT.close()
    del PACKOUT

    # --- Below this line: REMOVE UNNEEDED FILES (IF THEY EXIST) ---
    CLEANUP = [WORKDIR+TARFILE, WORKDIR+TARFILE+".checksum"]
    for FILES in CLEANUP:
        if( os.path.exists(FILES) == False):
            continue
        clean.rm( FILES )
    del CLEANUP