Posted by instaget on March Sat 24th 11:14 PM - Never Expires
download | new post
- #! /usr/bin/python
- import os
- import sys
- from getopt import getopt
- import zipfile
- from glob import glob
- def getPk3Hash(thezip):
- # This retrieves the md5 sum from the md5hash file in the zip file
- f = zipfile.ZipFile(thezip, "r")
- line = f.read(thezip[5:] + ".md5")
- return line[:32]
- def downloadHashes():
- # Will need to get all of the file.zip.md5 files
- os.system("wget -N http://instagib.jorgepena.be/downloads/packages/ -nd -r -l1 --no-parent -A md5")
- def downloadAllPk3s():
- os.system("wget -nd -r -l1 --no-parent -A pk3 http://instagib.jorgepena.be/downloads/packages/")
- try:
- mode = os.stat("base")[ST_MODE]
- if S_ISDIR(mode):
- os.system("mv -v *.pk3 base/")
- except OSError:
- os.system("mkdir base")
- os.system("mv -v *.pk3 base/")
- def downloadPk3(thefile):
- # This downloads the updated file
- url = "http://instagib.jorgepena.be/downloads/packages/" + thefile
- dest = "base/" + thefile
- print "Downloading " + thefile + " from " + url + " to " + dest
- os.system("wget -P base/ " + url + " -N")
- def Usage():
- print "Instaget: The Instagib Project Updater"
- print "Usage: instaget [SWITCH]"
- print "Switches:"
- print " -h, --help\t\tdisplays this help message"
- print " -i, --initial\t\tdownloads all of the pk3s"
- print " -c, --check\t\tchecks a specific package"
- print " -a, --all\t\tchecks all of the packages"
- print " -d, --download\tdownloads the specific pk3"
- print "Examples:"
- print " Downloading all of the pk3s for the first time:"
- print " python instaget.py -i"
- print " Check only one of the pk3s:"
- print " python instaget.py -c players.pk3"
- print " Check all of the pk3s:"
- print " python instaget.py -a"
- print " Download a specific pk3:"
- print " python instaget.py -d players.pk3"
- def onlyCheck(pk3):
- if os.path.exists(pk3):
- print "Checking " + pk3 + "..."
- f = open(pk3[5:] + ".md5", "r")
- rHash = f.readline()[:32]
- lHash = getPk3Hash(pk3)
- print "---------------------------------------------"
- print "File: " + pk3
- print "Remote Hash: " + rHash
- print "Local Hash: " + lHash
- if (lHash != rHash):
- print "MD5 Hash Mismatch..."
- failed = failed + 1
- downloadPk3(pk3[5:])
- else:
- print "Successful match"
- else:
- print "The file doesn't even exist. Try using the -d switch"
- def doAll():
- # We should first download the hashes
- downloadHashes()
- failed = 0 # This will check how many updates are needed
- pk3s = glob("base/*.pk3")
- for pk3 in pk3s:
- f = open(pk3[5:] + ".md5", "r")
- rHash = f.readline()[:32]
- lHash = getPk3Hash(pk3)
- print "---------------------------------------------"
- print "File: " + pk3
- print "Remote Hash: " + rHash
- print "Local Hash: " + lHash
- if (lHash != rHash):
- print "MD5 Hash Mismatch..."
- failed = failed + 1
- downloadPk3(pk3[5:])
- else:
- print "Successful match"
- print "---------------------------------------------"
- if failed == 0:
- print "No updates available"
- else:
- print "Downloaded %i updates" % failed
- # Remove the .md5 files
- print "Removing the MD5 Hash files..."
- os.system("rm -v *.md5")
- if __name__ == "__main__":
- try:
- opts, args = getopt(sys.argv[1:], ':hicad', ["help", "check"])
- except getopt.GetoptError:
- Usage()
- sys.exit(2)
- if not opts:
- Usage()
- sys.exit(2)
- package = "None"
- for o, a in opts:
- if o in ("-h", "--help"):
- Usage()
- if o in ("-i", "--initial"):
- downloadAllPk3s()
- if o in ("-c", "--check"):
- onlyCheck(a)
- if o in ("-a", "--all"):
- doAll()
- if o in ("-d", "--download"):
- downloadPk3(a)
- if not glob("base/*.pk3"):
- print "No media archives (pk3s) present, now dowloading them all..."
- downloadAllPk3s()
- else:
- doAll()
Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.