Move update_self out of __main__ for clarity

pull/2/head
Georgi Valkov 13 years ago
parent 7a9054ec79
commit 5fb3df4aff

@ -2698,20 +2698,15 @@ class FFmpegExtractAudioPP(PostProcessor):
information['filepath'] = new_path information['filepath'] = new_path
return information return information
### MAIN PROGRAM ###
if __name__ == '__main__':
try:
# Modules needed only when running the main program
import getpass
import optparse
# Function to update the program file with the latest version from the repository. def updateSelf(downloader, filename):
def update_self(downloader, filename): ''' Update the program file with the latest version from the repository '''
# 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...')
try: try:
latest_url = 'http://github.com/rg3/youtube-dl/raw/master/LATEST_VERSION' latest_url = 'http://github.com/rg3/youtube-dl/raw/master/LATEST_VERSION'
latest_version = urllib.urlopen(latest_url).read().strip() latest_version = urllib.urlopen(latest_url).read().strip()
@ -2719,14 +2714,24 @@ if __name__ == '__main__':
newcontent = urllib.urlopen(prog_url).read() newcontent = urllib.urlopen(prog_url).read()
except (IOError, OSError), err: except (IOError, OSError), err:
sys.exit('ERROR: unable to download latest version') sys.exit('ERROR: unable to download latest version')
try: try:
stream = open(filename, 'w') stream = open(filename, 'w')
stream.write(newcontent) stream.write(newcontent)
stream.close() stream.close()
except (IOError, OSError), err: except (IOError, OSError), err:
sys.exit('ERROR: unable to overwrite current version') 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)
if __name__ == '__main__':
try:
# Modules needed only when running the main program
import getpass
import optparse
# Parse command line # Parse command line
parser = optparse.OptionParser( parser = optparse.OptionParser(
usage='Usage: %prog [options] url...', usage='Usage: %prog [options] url...',
@ -2981,7 +2986,7 @@ if __name__ == '__main__':
# Update version # Update version
if opts.update_self: if opts.update_self:
update_self(fd, sys.argv[0]) updateSelf(fd, sys.argv[0])
# Maybe do nothing # Maybe do nothing
if len(all_urls) < 1: if len(all_urls) < 1:

Loading…
Cancel
Save