mirror of
https://github.com/blackjack4494/yt-dlc.git
synced 2024-12-25 09:19:48 +00:00
Make the self-updating function a bit more robust
This commit is contained in:
parent
0d8d9877ad
commit
0fe64c04f8
1 changed files with 15 additions and 9 deletions
24
youtube-dl
24
youtube-dl
|
@ -2296,20 +2296,26 @@ if __name__ == '__main__':
|
||||||
import getpass
|
import getpass
|
||||||
import optparse
|
import optparse
|
||||||
|
|
||||||
# Function to update the program file with the latest version from bitbucket.org
|
# Function to update the program file with the latest version from the repository.
|
||||||
def update_self(downloader, filename):
|
def update_self(downloader, filename):
|
||||||
# Note: downloader only used for options
|
# Note: downloader only used for options
|
||||||
if not os.access (filename, os.W_OK):
|
if not os.access(filename, os.W_OK):
|
||||||
sys.exit('ERROR: no write permissions on %s' % filename)
|
sys.exit('ERROR: no write permissions on %s' % filename)
|
||||||
|
|
||||||
downloader.to_screen('Updating to latest stable version...')
|
downloader.to_screen('Updating to latest stable version...')
|
||||||
latest_url = 'http://github.com/rg3/youtube-dl/raw/master/LATEST_VERSION'
|
try:
|
||||||
latest_version = urllib.urlopen(latest_url).read().strip()
|
latest_url = 'http://github.com/rg3/youtube-dl/raw/master/LATEST_VERSION'
|
||||||
prog_url = 'http://github.com/rg3/youtube-dl/raw/%s/youtube-dl' % latest_version
|
latest_version = urllib.urlopen(latest_url).read().strip()
|
||||||
newcontent = urllib.urlopen(prog_url).read()
|
prog_url = 'http://github.com/rg3/youtube-dl/raw/%s/youtube-dl' % latest_version
|
||||||
stream = open(filename, 'w')
|
newcontent = urllib.urlopen(prog_url).read()
|
||||||
stream.write(newcontent)
|
except (IOError, OSError), err:
|
||||||
stream.close()
|
sys.exit('ERROR: unable to download latest version')
|
||||||
|
try:
|
||||||
|
stream = open(filename, 'w')
|
||||||
|
stream.write(newcontent)
|
||||||
|
stream.close()
|
||||||
|
except (IOError, OSError), err:
|
||||||
|
sys.exit('ERROR: unable to overwrite current version')
|
||||||
downloader.to_screen('Updated to version %s' % latest_version)
|
downloader.to_screen('Updated to version %s' % latest_version)
|
||||||
|
|
||||||
# Parse command line
|
# Parse command line
|
||||||
|
|
Loading…
Reference in a new issue