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 updatereal on March Mon 19th 7:29 PM - Never Expires
download | new post

  1. #! /usr/bin/python
  2.  
  3. from md5 import md5
  4. import os
  5.  
  6. def hashLocal(thefile):
  7.    f = file("base/" + thefile, 'rb')
  8.    hsh = md5()
  9.    while 1:
  10.       data = f.read(2048)
  11.       if not data: break
  12.       hsh.update(data)
  13.    f.close()
  14.    return hsh.hexdigest()
  15.  
  16. def downloadHash():
  17.    os.system("wget -N http://instagib.jorgepena.be/downloads/packages/md5hash")
  18.  
  19. def downloadFile(thefile):
  20.    url = "http://instagib.jorgepena.be/downloads/packages/" + thefile
  21.    dest = "base/" + thefile
  22.    print "Downloading " + thefile + " from " + url + " to " + dest
  23.    os.system("wget -P base/ " + url + " -N")
  24.  
  25. # Begin
  26.  
  27. print "Downloading the hash file..."
  28. downloadHash()
  29.  
  30. failed = 0
  31.  
  32. for line in open('md5hash', 'r'):
  33.    print "---------------------------------------------"
  34.    filename = line[34:].rstrip() # Get the file name
  35.    print "File: " + filename
  36.    rHash = line[:32]
  37.    print "Remote Hash: " + rHash
  38.    lHash = hashLocal(filename)
  39.    print "Local Hash:  " + lHash
  40.    if rHash != lHash:
  41.       print "MD5 Hash Mismatch..."
  42.       failed = failed + 1
  43.       downloadFile(filename)
  44.    else:
  45.       print "Successful Hash Comparison"
  46.  
  47. if failed == 0:
  48.    print "No updates available"
  49. else:
  50.    print "Downloaded " + string(failed) + " updates"

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