Skip to content

Instantly share code, notes, and snippets.

@L422Y
Created February 14, 2014 05:44
Show Gist options
  • Save L422Y/8996376 to your computer and use it in GitHub Desktop.
Save L422Y/8996376 to your computer and use it in GitHub Desktop.
AirMail Beta Automatic Updater Script
#!/usr/bin/python
import re,urllib2,urllib
import subprocess, shutil
try:
f = open('/Applications/AirMail Beta.app/Contents/Info.plist','r')
plist = f.read();
# <key>CFBundleVersion</key\>.*
my_bundlever = re.findall('CFBundleVersion.*\n.*\<string\>(\d*)\</string\>',plist)[0]
except IOError:
my_bundlever = 0
htmlpage = urllib2.urlopen("https://rink.hockeyapp.net/apps/84be85c3331ee1d222fd7f0b59e41b04").read()
matches = re.findall("button' href='([^\']*)'.*?Version (.*?) \(([0-9]*)\)",htmlpage.replace("\n",""))
url = matches[0][0]
latest_version = matches[0][1]
latest_bundlever = matches[0][2]
print "My AirMail bundle version is %s, latest is %s (%s)..." % (my_bundlever,latest_bundlever,latest_version)
if latest_bundlever > my_bundlever:
print "Outdated... downloading..."
file_name = "AirMailBeta_%s.zip" % latest_bundlever
u = urllib2.urlopen(url)
f = open("/tmp/%s" % file_name, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
status = status + chr(8)*(len(status)+1)
print status,
f.close()
shutil.rmtree("/tmp/AirMail Beta.app", True)
subprocess.call(['unzip', "/tmp/%s" % file_name, "-d", "/tmp/"])
subprocess.call(['killall', "-9", "AirMail Beta"])
shutil.rmtree("/Applications/AirMail Beta.app", True)
shutil.move("/tmp/AirMail Beta.app", "/Applications/AirMail Beta.app")
subprocess.call(['open', '/Applications/AirMail Beta.app'])
print "Done!"
else:
print "Up to date."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment