def DownloadMethod(bookid=None, nzbprov=None, nzbtitle=None, nzburl=None): myDB = database.DBConnection() if lazylibrarian.SAB_HOST and not lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: download = sabnzbd.SABnzbd(nzbtitle, nzburl) elif lazylibrarian.NZBGET_HOST and not lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: headers = {'User-Agent': USER_AGENT} data = request.request_content(url=nzburl, headers=headers) nzb = classes.NZBDataSearchResult() nzb.extraInfo.append(data) nzb.name = nzbtitle nzb.url = nzburl download = nzbget.sendNZB(nzb) elif lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: try: req = urllib2.Request(nzburl) if lazylibrarian.PROXY_HOST: req.set_proxy(lazylibrarian.PROXY_HOST, lazylibrarian.PROXY_TYPE) req.add_header('User-Agent', USER_AGENT) nzbfile = urllib2.urlopen(req, timeout=90).read() except urllib2.URLError, e: logger.warn('Error fetching nzb from url: ' + nzburl + ' %s' % e) nzbfile = False if (nzbfile): nzbname = str(nzbtitle) + '.nzb' nzbpath = os.path.join(lazylibrarian.NZB_BLACKHOLEDIR, nzbname) try: f = open(nzbpath, 'w') f.write(nzbfile) f.close() logger.info('NZB file saved to: ' + nzbpath) download = True try: os.chmod(nzbpath, 0777) except Exception, e: logger.info("Could not chmod path: " + str(file2)) except Exception, e: logger.error('%s not writable, NZB not saved. Error: %s' % (nzbpath, e)) download = False
def DownloadMethod(bookid=None, nzbprov=None, nzbtitle=None, nzburl=None): myDB = database.DBConnection() if lazylibrarian.SAB_HOST and not lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: download = sabnzbd.SABnzbd(nzbtitle, nzburl) elif lazylibrarian.NZBGET_HOST and not lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: headers = {'User-Agent': USER_AGENT} data = request.request_content(url=nzburl, headers=headers) nzb = classes.NZBDataSearchResult() nzb.extraInfo.append(data) nzb.name = nzbtitle nzb.url = nzburl download = nzbget.sendNZB(nzb) elif lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: try: req = urllib2.Request(nzburl) if lazylibrarian.PROXY_HOST: req.set_proxy(lazylibrarian.PROXY_HOST, lazylibrarian.PROXY_TYPE) req.add_header('User-Agent', USER_AGENT) nzbfile = urllib2.urlopen(req, timeout=90).read() except urllib2.URLError, e: logger.warn('Error fetching nzb from url: ' + nzburl + ' %s' % e) nzbfile = False; if (nzbfile): nzbname = str(nzbtitle) + '.nzb'; nzbpath = os.path.join(lazylibrarian.NZB_BLACKHOLEDIR, nzbname); try: f = open(nzbpath, 'w'); f.write(nzbfile); f.close(); logger.info('NZB file saved to: ' + nzbpath); download = True; try: os.chmod(nzbpath, 0777); except Exception, e: logger.info("Could not chmod path: " + str(file2)); except Exception, e: logger.error('%s not writable, NZB not saved. Error: %s' % (nzbpath, e)); download = False;
def NZBDownloadMethod(bookid=None, nzbprov=None, nzbtitle=None, nzburl=None): myDB = database.DBConnection() if lazylibrarian.SAB_HOST and not lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: download = sabnzbd.SABnzbd(nzbtitle, nzburl) elif lazylibrarian.NZBGET_HOST and not lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: headers = {"User-Agent": USER_AGENT} data = request.request_content(url=nzburl, headers=headers) nzb = classes.NZBDataSearchResult() nzb.extraInfo.append(data) nzb.name = nzbtitle nzb.url = nzburl download = nzbget.sendNZB(nzb) elif lazylibrarian.NZB_DOWNLOADER_BLACKHOLE: try: req = urllib2.Request(nzburl) if lazylibrarian.PROXY_HOST: req.set_proxy(lazylibrarian.PROXY_HOST, lazylibrarian.PROXY_TYPE) req.add_header("User-Agent", USER_AGENT) nzbfile = urllib2.urlopen(req, timeout=90).read() except urllib2.URLError as e: logger.warn("Error fetching nzb from url: " + nzburl + " %s" % e.reason) nzbfile = False if nzbfile: nzbname = str(nzbtitle) + ".nzb" nzbpath = os.path.join(lazylibrarian.NZB_BLACKHOLEDIR, nzbname) try: f = open(nzbpath, "w") f.write(nzbfile) f.close() logger.info("NZB file saved to: " + nzbpath) download = True try: os.chmod(nzbpath, 0777) except Exception, e: logger.info("Could not chmod path: " + str(nzbpath)) except Exception, e: logger.error("%s not writable, NZB not saved. Error: %s" % (nzbpath, e)) download = False
def update(): if plexpy.INSTALL_TYPE == 'win': logger.info('Windows .exe updating not supported yet.') elif plexpy.INSTALL_TYPE == 'git': output, err = runGit('pull ' + plexpy.CONFIG.GIT_REMOTE + ' ' + plexpy.CONFIG.GIT_BRANCH) if not output: logger.error('Unable to download latest version') return for line in output.split('\n'): if 'Already up-to-date.' in line: logger.info('No update available, not updating') logger.info('Output: ' + str(output)) elif line.endswith(('Aborting', 'Aborting.')): logger.error('Unable to update from git: ' + line) logger.info('Output: ' + str(output)) else: tar_download_url = 'https://github.com/{}/{}/tarball/{}'.format( plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO, plexpy.CONFIG.GIT_BRANCH) update_dir = os.path.join(plexpy.PROG_DIR, 'update') version_path = os.path.join(plexpy.PROG_DIR, 'version.txt') logger.info('Downloading update from: ' + tar_download_url) data = request.request_content(tar_download_url) if not data: logger.error( "Unable to retrieve new version from '%s', can't update", tar_download_url) return download_name = plexpy.CONFIG.GIT_BRANCH + '-github' tar_download_path = os.path.join(plexpy.PROG_DIR, download_name) # Save tar to disk with open(tar_download_path, 'wb') as f: f.write(data) # Extract the tar to update folder logger.info('Extracting file: ' + tar_download_path) tar = tarfile.open(tar_download_path) tar.extractall(update_dir) tar.close() # Delete the tar.gz logger.info('Deleting file: ' + tar_download_path) os.remove(tar_download_path) # Find update dir name update_dir_contents = [ x for x in os.listdir(update_dir) if os.path.isdir(os.path.join(update_dir, x)) ] if len(update_dir_contents) != 1: logger.error("Invalid update data, update failed: " + str(update_dir_contents)) return content_dir = os.path.join(update_dir, update_dir_contents[0]) # walk temp folder and move files to main folder for dirname, dirnames, filenames in os.walk(content_dir): dirname = dirname[len(content_dir) + 1:] for curfile in filenames: old_path = os.path.join(content_dir, dirname, curfile) new_path = os.path.join(plexpy.PROG_DIR, dirname, curfile) if os.path.isfile(new_path): os.remove(new_path) os.renames(old_path, new_path) # Update version.txt try: with open(version_path, 'w') as f: f.write(str(plexpy.LATEST_VERSION)) except IOError as e: logger.error( "Unable to write current version to version.txt, update not complete: %s", e) return
def update(): if pacvert.INSTALL_TYPE == 'win': logger.info('Windows .exe updating not supported yet.') elif pacvert.INSTALL_TYPE == 'git': output, err = runGit('pull origin ' + pacvert.CONFIG.GIT_BRANCH) if not output: logger.error('Couldn\'t download latest version') for line in output.split('\n'): if 'Already up-to-date.' in line: logger.info('No update available, not updating') logger.info('Output: ' + str(output)) elif line.endswith('Aborting.'): logger.error('Unable to update from git: ' + line) logger.info('Output: ' + str(output)) else: tar_download_url = 'https://github.com/%s/pacvert/tarball/%s' % (pacvert.CONFIG.GIT_USER, pacvert.CONFIG.GIT_BRANCH) update_dir = os.path.join(pacvert.PROG_DIR, 'update') version_path = os.path.join(pacvert.PROG_DIR, 'version.txt') logger.info('Downloading update from: ' + tar_download_url) data = request.request_content(tar_download_url) if not data: logger.error("Unable to retrieve new version from '%s', can't update", tar_download_url) return download_name = pacvert.CONFIG.GIT_BRANCH + '-github' tar_download_path = os.path.join(pacvert.PROG_DIR, download_name) # Save tar to disk with open(tar_download_path, 'wb') as f: f.write(data) # Extract the tar to update folder logger.info('Extracting file: ' + tar_download_path) tar = tarfile.open(tar_download_path) tar.extractall(update_dir) tar.close() # Delete the tar.gz logger.info('Deleting file: ' + tar_download_path) os.remove(tar_download_path) # Find update dir name update_dir_contents = [x for x in os.listdir(update_dir) if os.path.isdir(os.path.join(update_dir, x))] if len(update_dir_contents) != 1: logger.error("Invalid update data, update failed: " + str(update_dir_contents)) return content_dir = os.path.join(update_dir, update_dir_contents[0]) # walk temp folder and move files to main folder for dirname, dirnames, filenames in os.walk(content_dir): dirname = dirname[len(content_dir) + 1:] for curfile in filenames: old_path = os.path.join(content_dir, dirname, curfile) new_path = os.path.join(pacvert.PROG_DIR, dirname, curfile) if os.path.isfile(new_path): os.remove(new_path) os.renames(old_path, new_path) # Update version.txt try: with open(version_path, 'w') as f: f.write(str(pacvert.LATEST_VERSION)) except IOError as e: logger.error( "Unable to write current version to version.txt, update not complete: %s", e ) return
def update(): if plexpy.PYTHON2: logger.warn('Tautulli is running using Python 2. Unable to update.') return if not plexpy.UPDATE_AVAILABLE: return if plexpy.INSTALL_TYPE in ('docker', 'snap', 'macos'): return elif plexpy.INSTALL_TYPE == 'windows': logger.info('Calling Windows scheduled task to update Tautulli') CREATE_NO_WINDOW = 0x08000000 subprocess.Popen(['SCHTASKS', '/Run', '/TN', 'TautulliUpdateTask'], creationflags=CREATE_NO_WINDOW) elif plexpy.INSTALL_TYPE == 'git': output, err = runGit('pull --ff-only {} {}'.format( plexpy.CONFIG.GIT_REMOTE, plexpy.CONFIG.GIT_BRANCH)) if not output: logger.error('Unable to download latest version') return for line in output.split('\n'): if 'Already up-to-date.' in line or 'Already up to date.' in line: logger.info('No update available, not updating') elif line.endswith(('Aborting', 'Aborting.')): logger.error('Unable to update from git: ' + line) elif plexpy.INSTALL_TYPE == 'source': tar_download_url = 'https://github.com/{}/{}/tarball/{}'.format( plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO, plexpy.CONFIG.GIT_BRANCH) update_dir = os.path.join(plexpy.DATA_DIR, 'update') version_path = os.path.join(plexpy.PROG_DIR, 'version.txt') logger.info('Downloading update from: ' + tar_download_url) data = request.request_content(tar_download_url) if not data: logger.error( "Unable to retrieve new version from '%s', can't update", tar_download_url) return download_name = plexpy.CONFIG.GIT_BRANCH + '-github' tar_download_path = os.path.join(plexpy.DATA_DIR, download_name) # Save tar to disk with open(tar_download_path, 'wb') as f: f.write(data) # Extract the tar to update folder logger.info('Extracting file: ' + tar_download_path) tar = tarfile.open(tar_download_path) tar.extractall(update_dir) tar.close() # Delete the tar.gz logger.info('Deleting file: ' + tar_download_path) os.remove(tar_download_path) # Find update dir name update_dir_contents = [ x for x in os.listdir(update_dir) if os.path.isdir(os.path.join(update_dir, x)) ] if len(update_dir_contents) != 1: logger.error("Invalid update data, update failed: " + str(update_dir_contents)) return content_dir = os.path.join(update_dir, update_dir_contents[0]) # walk temp folder and move files to main folder for dirname, dirnames, filenames in os.walk(content_dir): dirname = dirname[len(content_dir) + 1:] for curfile in filenames: old_path = os.path.join(content_dir, dirname, curfile) new_path = os.path.join(plexpy.PROG_DIR, dirname, curfile) if os.path.isfile(new_path): os.remove(new_path) os.renames(old_path, new_path) # Update version.txt try: with open(version_path, 'w') as f: f.write(str(plexpy.LATEST_VERSION)) except IOError as e: logger.error( "Unable to write current version to version.txt, update not complete: %s", e) return