pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Python PasteBin - Home - Help - Archive

Posted by instaget on March Wed 21st 6:55 PM - Never Expires
download | new post

  1. #! /usr/bin/python
  2.  
  3. import os
  4. import zipfile
  5. from glob import glob
  6.  
  7. def getZipHash(thezip):
  8.    # This retrieves the md5 sum from the md5hash file in the zip file
  9.    f = zipfile.ZipFile(thezip, "r")
  10.    line = f.read(thezip[5:] + ".md5")
  11.    return line[:32]
  12.  
  13. def downloadHashes():
  14.    # Will need to get all of the file.zip.md5 files
  15.    os.system("wget -N http://instagib.jorgepena.be/downloads/packages/bots.pk3.md5")
  16.    os.system("wget -N http://instagib.jorgepena.be/downloads/packages/maps.pk3.md5")
  17.    os.system("wget -N http://instagib.jorgepena.be/downloads/packages/media.pk3.md5")
  18.    os.system("wget -N http://instagib.jorgepena.be/downloads/packages/players.pk3.md5")
  19.    os.system("wget -N http://instagib.jorgepena.be/downloads/packages/scripts.pk3.md5")
  20.    os.system("wget -N http://instagib.jorgepena.be/downloads/packages/sound.pk3.md5")
  21.    os.system("wget -N http://instagib.jorgepena.be/downloads/packages/textures.pk3.md5")
  22.    os.system("wget -N http://instagib.jorgepena.be/downloads/packages/ui.pk3.md5")
  23.  
  24. def downloadFile(thefile):
  25.    # This downloads the updated file
  26.    url = "http://instagib.jorgepena.be/downloads/packages/" + thefile
  27.    dest = "base/" + thefile
  28.    print "Downloading " + thefile + " from " + url + " to " + dest
  29.    os.system("wget -P base/ " + url + " -N")
  30.  
  31. # We should first download the hashes
  32. downloadHashes()
  33. failed = 0 # This will check how many updates are needed
  34.  
  35. for pk3 in glob("base/*.pk3"):
  36.    f = open(pk3[5:] + ".md5", "r")
  37.    rHash = f.readline()[:32]
  38.    lHash = getZipHash(pk3)
  39.    print "---------------------------------------------"
  40.    print "File: " + pk3
  41.    print "Remote Hash: " + rHash
  42.    print "Local Hash:  " + lHash
  43.  
  44.    if (lHash != rHash):
  45.       print "MD5 Hash Mismatch..."
  46.       failed = failed + 1
  47.       downloadFile(pk3[5:])
  48.    else:
  49.       print "Successful match"
  50.  
  51. print "---------------------------------------------"
  52. if failed == 0:
  53.    print "No updates available"
  54. else:
  55.    print "Downloaded " + string(failed) + " updates"
  56.  
  57. # Remove the .md5 files
  58. print "Removing the MD5 Hash files..."
  59. os.system("rm *.md5")

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.
Syntax Highlighting:
To highlight particular lines, prefix each line with @@
Pressing TAB inserts 3 spaces