def getDepend(PAK): """ Parses "packages.rules"+os.sep+PAK, must be a JSON file. Returns the 'depend' tag, with all dependencies """ if( PAK.endswith(".json") == False): PAK=PAK+".json" JSON = json.loads( open("packages.rules"+os.sep+PAK).read() ) DEPENDS = JSON.get("depend") if( DEPENDS != None): for DEPEND in DEPENDS: DEPENDS.remove(DEPEND) DEPEND = varCheck.do(DEPEND) DEPENDS.append(DEPEND) return DEPENDS
def getInstdir(PAK): """ Parses "packages.rules"+os.sep+PAK, must be a JSON file. Returns the 'instdir' tag text. """ if( PAK.endswith(".json") == False): PAK = PAK+".json" JSON = json.loads( open("packages.rules"+os.sep+PAK).read() ) INSTDIR = JSON.get("instdir") if ( INSTDIR == None ): INSTDIR = getTarfile(PAK)[:-8] if( INSTDIR.endswith(os.sep) == False): INSTDIR=INSTDIR+os.sep INSTDIR=varCheck.do(INSTDIR) return INSTDIR
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