fixed a couple of Windows exe update bugs
authorFilippo Valsorda <filippo.valsorda@gmail.com>
Sun, 27 May 2012 21:03:45 +0000 (23:03 +0200)
committerFilippo Valsorda <filippo.valsorda@gmail.com>
Sun, 27 May 2012 21:03:45 +0000 (23:03 +0200)
youtube-dl
youtube-dl.exe
youtube_dl/__init__.py

index 3fc77f206861fcf4523be9d3e7c3d0ec69107b49..80175ed6eb869f022cf9e2981db0ff04d06c215e 100755 (executable)
Binary files a/youtube-dl and b/youtube-dl differ
index 287b78af52b7dafff7355e890f5d019d1e2d688d..6d19ef5eacdf67d3618ce9e7b623481712abbe2e 100755 (executable)
Binary files a/youtube-dl.exe and b/youtube-dl.exe differ
index 5e500d5e0243052eeb762f9cdf15de3c3782ddae..73590ecd6f0863c4787f62880df5203e8caf17d0 100644 (file)
@@ -60,13 +60,17 @@ def updateSelf(downloader, filename):
        urlv.close()
 
        if hasattr(sys, "frozen"): #py2exe
-               directory = os.path.dirname(filename)
                exe = os.path.abspath(filename)
+               directory = os.path.dirname(exe)
                if not os.access(directory, os.W_OK):
                        sys.exit('ERROR: no write permissions on %s' % directory)
                        
                try:
-                       urllib.urlretrieve(UPDATE_URL_EXE, exe + '.new')
+                       urlh = urllib2.urlopen(UPDATE_URL_EXE)
+                       newcontent = urlh.read()
+                       urlh.close()
+                       with open(exe + '.new', 'wb') as outf:
+                               outf.write(newcontent)
                except (IOError, OSError), err:
                        sys.exit('ERROR: unable to download latest version')
                        
@@ -75,6 +79,7 @@ def updateSelf(downloader, filename):
                        b = open(bat, 'w')
                        
                        print >> b, """
+echo Updating youtube-dl...
 ping 127.0.0.1 -n 5 -w 1000 > NUL
 move /Y "%s.new" "%s"
 del "%s"
@@ -95,11 +100,8 @@ del "%s"
                        sys.exit('ERROR: unable to download latest version')
 
                try:
-                       outf = open(filename, 'wb')
-                       try:
+                       with open(filename, 'wb') as outf:
                                outf.write(newcontent)
-                       finally:
-                               outf.close()
                except (IOError, OSError), err:
                        sys.exit('ERROR: unable to overwrite current version')