def download_updates(updates_dictionary, flag): download_path = '/usr/local/python/wp_updates/wp_updates_dir/working/' downloads_dictionary = {} for key in updates_dictionary.copy(): # construct download URLs if flag == 'p': url = 'https://downloads.wordpress.org/plugin/' + key + '.' \ + updates_dictionary[key] + '.zip' elif flag == 't': url = 'https://downloads.wordpress.org/theme/' + key + '.' \ + updates_dictionary[key] + '.zip' else: raise custom_exceptions.FlagError('Error: Invalid flag. Updates' + ' not downloaded.') try: wget.download(url, download_path, bar=None) downloads_dictionary[key] = updates_dictionary[key] except HTTPError: print('Error: Could not access URL:', url) print('\tDownload removed from list: ', key, updates_dictionary[key]) del updates_dictionary[key] return downloads_dictionary
def create_installed_dictionary(directory_path, installs_list, flag): # create a dictionary to store plugin name and version installed_dictionary = {} # construct dictionary from list for install in installs_list: # deal with plugins if flag == 'p': filename = construct_plugin_filename(install) # deal with themes elif flag == 't': filename = 'style.css' else: raise custom_exceptions.FlagError( 'Error: Invalid flag. Installed' + ' name and version dictionary' + ' not constructed.') # construct full path to file install_path = directory_path / install / filename # create a dictionary of the name and version of the install try: version = get_installed_version(install_path) if (version != ''): installed_dictionary[install] = version except IOError: print('Error: Cannot open file:', install_path) return installed_dictionary
def construct_url(install, flag): if flag == 'p': url = 'https://wordpress.org/plugins/' + install elif flag == 't': url = 'https://wordpress.org/themes/' + install else: raise custom_exceptions.FlagError('Error: Invalid flag. URL to ' + ' get current version not' + ' constructed. \n\tInstall ' + 'failed on: ' + install) return url
def get_available_dictionary(installs_list, flag): #create empty dictionary available_dictionary = {} # construct dictionary of plugin and currently avaiable version for install in installs_list: version = '' # construct URLs url = construct_url(install, flag) try: # get content from URL html = urllib.request.urlopen(url) for line in html: string_line = line.decode().strip() if flag == 'p': if 'softwareVersion' in string_line: version = (string_line.split(':'))[1] version = version.strip('" ,') break elif flag == 't': if 'Version' in string_line: version = (string_line.split(':'))[1] version = find_theme_version(string_line) break else: raise custom_exceptions.FlagError('Error: Invalid flag.' + ' Current version' + ' dictionary not' + ' constructed.') if (version != ''): available_dictionary[install] = version except URLError: print('Error: Unable to access URL:', url) return available_dictionary
def cleanup_zip_files(updates_dictionary, flag): home_path = pathlib.Path('/usr/local/python/wp_updates/wp_updates_dir/') for key in updates_dictionary: filename = key + '.' + updates_dictionary[key] + '.zip' working_file = home_path / 'working' / filename if flag == 'p': working_file.replace(home_path / 'plugins' / filename) elif flag == 't': working_file.replace(home_path / 'themes' / filename) else: raise custom_exceptions.FlagError( 'Error: Invalid flag. Zip files' + ' not cleaned up.')