# This script downloads Mechanic and Ghostlines as .zip files into tmp, and then installs them into RoboFont.

from urllib2 import urlopen
import zipfile as zf
from mojo.extensions import *
from vanilla import dialogs
import os

temp = '/tmp/'

def unzip(zipFilePath, destDir):
    zipped_dir = zf.ZipFile(zipFilePath)
    for name in zipped_dir.namelist():
        (dirName, fileName) = os.path.split(name)
        if fileName == '':
            # so this file is a directory
            newDir = destDir + '/' + dirName
            if not os.path.exists(newDir):
                os.mkdir(newDir)
        else:
            # so this is a file with an extension
            fd = open(destDir + '/' + name, 'wb')
            fd.write(zipped_dir.read(name))
            fd.close()
    zipped_dir.close()

def download(url, destDir):
    zip_path = temp + destDir + '.zip'
    response = urlopen(url)
    CHUNK = 16 * 1024
    with open(zip_path, 'wb') as f:
        while True:
            chunk = response.read(CHUNK)
            if not chunk:
                break
            f.write(chunk)

    unzip(zip_path, temp) # Unzip it into temp

def install_extension(url, destDir, extName):
    """Download extension, unzip it, and install in RoboFont."""

    download(url,destDir)
    extension_path = temp + destDir + '/' + extName
    extension = ExtensionBundle(extension_path)
    extension.install()

########## end functions, now the script ##########

install_extension('https://github.com/jackjennings/Mechanic/archive/master.zip', 'Mechanic-master', 'Mechanic.roboFontExt')
install_extension('https://github.com/ghostlines/ghostlines-robofont/archive/v1.zip', 'ghostlines-robofont-master', 'Ghostlines.roboFontExt')

try:
    import mechanic
except:
    dialogs.message("Error installing Mechanic.")

try:
    import ghostlines
except:
    dialogs.message("Error installing Ghostlines.")

from ghostlines.windows.account_window import AccountWindow
AccountWindow.open()

@@ -104,16 +104,26 @@
 oFont.%0A%0A
+import os%0A
 from url
@@ -163,16 +163,45 @@
 e as zf%0A
+from vanilla import dialogs%0A%0A
 from moj
@@ -225,46 +225,8 @@
 rt *
-%0Afrom vanilla import dialogs%0Aimport os
 %0A%0Ate
@@ -252,21 +252,23 @@
 nzip(zip
-FileP
+_file_p
 ath, des
@@ -264,25 +264,26 @@
 e_path, dest
-D
+_d
 ir):%0A    zip
@@ -310,13 +310,15 @@
 (zip
-FileP
+_file_p
 ath)
@@ -369,17 +369,18 @@
     (dir
-N
+_n
 ame, fil
@@ -380,17 +380,18 @@
 me, file
-N
+_n
 ame) = o
@@ -409,16 +409,25 @@
 t(name)%0A
+        %0A
         
@@ -433,17 +433,18 @@
  if file
-N
+_n
 ame == '
@@ -503,17 +503,18 @@
      new
-D
+_d
 ir = des
@@ -510,25 +510,26 @@
 w_dir = dest
-D
+_d
 ir + '/' + d
@@ -530,17 +530,18 @@
 /' + dir
-N
+_n
 ame%0A    
@@ -573,17 +573,18 @@
 ists(new
-D
+_d
 ir):%0A   
@@ -608,17 +608,18 @@
 kdir(new
-D
+_d
 ir)%0A    
@@ -700,25 +700,26 @@
  = open(dest
-D
+_d
 ir + '/' + n
@@ -796,16 +796,17 @@
 close()%0A
+%0A
     zipp
@@ -843,17 +843,18 @@
 rl, dest
-D
+_d
 ir):%0A   
@@ -872,25 +872,26 @@
  temp + dest
-D
+_d
 ir + '.zip'%0A
@@ -1196,17 +1196,19 @@
 dest
-D
+_d
 ir, ext
-N
+_n
 ame)
@@ -1292,21 +1292,23 @@
 oad(url,
+ 
 dest
-D
+_d
 ir)%0A    
@@ -1335,17 +1335,18 @@
 p + dest
-D
+_d
 ir + '/'
@@ -1351,17 +1351,18 @@
 /' + ext
-N
+_n
 ame%0A    
@@ -1995,16 +1995,18 @@
 ntWindow
+()
 .open()%0A

Fix AccountWindow initialization and general syntax