コード例 #1
0
ファイル: compile.py プロジェクト: necrophcodr/PyUpdater
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
ファイル: compile.py プロジェクト: necrophcodr/PyUpdater
def compile(PAK, CXX, WORKDIR):
    """
    'CXX' is the full path to the executable compiler.
    """
    if( PAK.endswith(".json") == False):
        PAK = PAK+".json"
    INSTDIR = packages.getInstdir(PAK)
    HOMEROOT=os.path.abspath(os.curdir)
    if( CXX != None ):
        HOMEROOT=os.path.abspath(os.curdir)
        print( bcolors.YELLOW+"cd: "+bcolors.ENDC+" Entering '"+WORKDIR+INSTDIR+"'")
        os.chdir(WORKDIR+INSTDIR)
        RETCODE = subprocess.call(CXX, shell=True)
        print( bcolors.YELLOW+"cd: "+bcolors.ENDC+" Leaving '"+WORKDIR+INSTDIR+"'")
        os.chdir(HOMEROOT)
        return RETCODE
コード例 #3
0
ファイル: backup.py プロジェクト: necrophcodr/PyUpdater
def backup(OBJ, WORKDIR, BACKUPDIR):
    """
    Backup OBJ from WORKDIR, to BACKUPDIR.
    The installation directory of OBJ will be read from OBJ+'.json'
    OBJ will be packaged in BACKUPDIR as NAME+'.tar.bz2'
    """
    if(os.access("packages.rules"+os.sep+OBJ+".json", os.R_OK) == True):
            INSTDIR = packages.getInstdir(OBJ+".json")
            BACKUPTAR = packages.getTarfile(OBJ+".json")
            if(BACKUPTAR.startswith("http://") == True):
                BACKUPTAR="%s" % (
                    BACKUPTAR.split("/")[-1]
                )
            if (INSTDIR == None):
                INSTDIR=WORKDIR+BACKUPTAR[:-8]
            else:
                INSTDIR=WORKDIR+INSTDIR
            INSTDIR=varCheck.do(INSTDIR)
            if (INSTDIR.endswith(os.sep) == False):
                INSTDIR=INSTDIR+os.sep
            if(os.access(BACKUPDIR, os.F_OK) == False):
                os.makedirs(BACKUPDIR)
            if(os.access(WORKDIR, os.F_OK) == False):
                print( bcolors.RED+"Workdir '"+WORKDIR+"' does NOT exist!"+bcolors.ENDC)
                sys.exit(1)
            if(os.access(INSTDIR, os.F_OK) == False):
                print( bcolors.RED+"Package '"+OBJ+"' is NOT installed."+bcolors.ENDC)
                return
            TARFILE=tarfile.open(BACKUPDIR+BACKUPTAR, "w:bz2")
            if(args.QUIET==False or None):
                print( bcolors.GREEN+"+"+bcolors.ENDC+"--"+OBJ+".json" )
            if( INSTDIR==(WORKDIR+"."+os.sep) ):
                print( "(WIP)")
                return
            else:
                HOME=os.path.abspath(os.curdir)
                os.chdir(INSTDIR)
                for FILES in os.listdir(os.curdir):
                    if((FILES+os.sep)==BACKUPDIR):
                        continue
                    elif((FILES+os.sep)==WORKDIR):
                        continue
                    if(args.QUIET==False or None):
                        print( bcolors.YELLOW+"|"+bcolors.ENDC+"-"+FILES)
                    TARFILE.add(FILES)
                os.chdir(HOME)
            TARFILE.close()
            del TARFILE
            m = hashlib.sha1(open(BACKUPDIR+BACKUPTAR, "rb").read()).hexdigest()
            if(args.NEW == True):
                if(os.access("packages.checksum"+os.sep+BACKUPTAR+".checksum", os.W_OK) == False):
                    print( "Please re-run this script with write-access to 'packages.checksum"+os.sep+"'.")
                    return
                mOut = open("packages.checksum"+os.sep+BACKUPTAR+".checksum", "w")
                mOut.write(m)
                mOut.close()
            mOut = open(BACKUPDIR+BACKUPTAR+".checksum", "w")
            mOut.write(m)
            mOut.close()
            del m
            del mOut
コード例 #4
0
ファイル: update.py プロジェクト: necrophcodr/PyUpdater
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
コード例 #5
0
ファイル: clean.py プロジェクト: necrophcodr/PyUpdater
        print("REM [R]'"+OBJ+"'")
        shutil.rmtree(OBJ)
        return
    else:
        print("REM '"+OBJ+"'")
        os.remove(OBJ)
        return

if __name__ == "__main__":
    WORKDIR = settings.getWorkdir()
    BACKUPDIR = settings.getBackupdir()
    for ARGS in sys.argv:
        if(ARGS == sys.argv[0]):
            continue
        if(os.access("packages.rules"+os.sep+ARGS+".json", os.R_OK) == True):
            INSTDIR=packages.getInstdir(ARGS+".json")
            TARFILE=packages.getTarfile(ARGS+".json")
            if(INSTDIR==None):
                INSTDIR=TARFILE[:-8]
            rm(WORKDIR+INSTDIR)
            rm("packages.checksum"+os.sep+TARFILE+".checksum")
            if( os.path.isfile("packages.installed") == True):
                PACK = open("packages.installed","r").read().split("\n")
                PACK.remove(ARGS)
                PACKOUT = open("packages.installed", "w")
                for LINES in PACK:
                    PACKOUT.write(LINES+"\n")
                PACKOUT.close()
                del PACK
                del PACKOUT
            continue
コード例 #6
0
ファイル: compile.py プロジェクト: necrophcodr/PyUpdater
    if( CXX != None ):
        HOMEROOT=os.path.abspath(os.curdir)
        print( bcolors.YELLOW+"cd: "+bcolors.ENDC+" Entering '"+WORKDIR+INSTDIR+"'")
        os.chdir(WORKDIR+INSTDIR)
        RETCODE = subprocess.call(CXX, shell=True)
        print( bcolors.YELLOW+"cd: "+bcolors.ENDC+" Leaving '"+WORKDIR+INSTDIR+"'")
        os.chdir(HOMEROOT)
        return RETCODE
if __name__ == "__main__":
    if(len(sys.argv)==1):
        # Display help
        sys.exit(1)
    WORKDIR = settings.getWorkdir()
    for ARGS in sys.argv[1:]:
        if(os.access("packages.rules"+os.sep+ARGS+".json", os.R_OK) == True):
            INSTDIR = packages.getInstdir(ARGS)
            if( os.access(WORKDIR+INSTDIR, os.W_OK) == False):
                    if( os.access(WORKDIR+INSTDIR, os.F_OK) == False):
                        print( "Trying to update...")
                        MIRROR = settings.getMirror()
                        if( MIRROR == None):
                            sys.exit(1)
                        MIRROR=MIRROR[0]
                        from update import *
                        if ( os.access("packages.rules"+os.sep+ARGS+".json", os.R_OK) == True):
                            update(ARGS, MIRROR, WORKDIR)
                        elif( os.path.isdir("packages.rules"+os.sep+ARGS) == True):
                            LIST = os.listdir("packages.rules"+os.sep+ARGS)
                            for FILES in LIST:
                                update(FILES, MIRROR, WORKDIR)
                        elif( ARGS != sys.argv[0]):