def doUpdateCheck(self): """ Will run the whole flow for update, Return None. """ updater = getUpdater() if updater and updater.ShouldCheckUpdates(): (_is_latest, _latest_ver, _latest_url) = updater.IsLatestVersion() if not _is_latest: if updater.ShouldAutoUpdate() and _latest_url: if updater.DownloadUpdate(_latest_url, _latest_ver): WriteDebug('Update zip downloaded, restarting!') restart() elif not updater.ShouldAutoUpdate() and _latest_url: getInteractor().notifyNewVersion\ (updater.CurrentVersion(), _latest_ver, _latest_url)
def _put_user_single_input_in_queue(self): query = getInteractor().getSearchInput\ (DIRC_LOGS.INSERT_MOVIE_NAME_FOR_QUERY) self.interactive = True WriteDebug('The query from the user is: %s' % query) new_single_input = getSingleInputFromQuery(query) WriteDebug('Created SingleInput from the query, adding it to the queue') self.single_input_queue.putSingleInput(new_single_input)
def startWorking(queries = [], files = [], directories = []): """ The entry point for the real work of SubiT. The parameters are those that parsed successfully from the command line. """ WriteDebug('Starting SubiT\'s real work.') WriteDebug('Running from: %s' % GetProgramDir()) WriteDebug('Creating SUBIT_WORKER_THREAD daemon thread.') SUBIT_WORKER_THREAD = SubiTWorkerThread(queries, files, directories) SUBIT_WORKER_THREAD.setDaemon(True) SUBIT_WORKER_THREAD.start() WriteDebug('SUBIT_WORKER_THREAD created and started.') # In Gui mode, after calling load(), the thread enters the event loop so # we don't need to take to much care about the rest of the code. getInteractor().load() # In Console modes however, we wait for the worker thread to finish # (otherwise, we are ending the run in here beacuse there is no event loop # for the console). if (getInteractor().InteractionType in \ [InteractionTypes.Console, InteractionTypes.ConsoleSilent]): while SUBIT_WORKER_THREAD.isAlive(): sleep(0.05)
from SubStages.ISubStage import ISubStage from SubStages.ISubStage import getSubProviderByName from Utils import WriteDebug, getlist from Logs import INFO as INFO_LOGS from Logs import WARN as WARN_LOGS from Logs import DIRECTION as DIRC_LOGS from Logs import BuildLog from Interaction import getInteractor writeLog = getInteractor().writeLog class MovieSubStage(ISubStage): """ The stage that comes right after we get results from querying the site. In case of querying for a movie, this stage realy stand for a single movie, but in case that we are querying for an episode in a series, this stage will represent a single episode, and not the whole series. What it means is that if the site under a certain provider provides a whole series in a query, the SubPorvider will need to enter the series and extract all the episode under it. """ def __init__(self, provider_name, movie_name, movie_code, versions_sum, extra = {}): """ Simple constructor. movie_name is the display name of the results, movie_code is the code representing the movie_name in the site, versions_sum is a string representing the versions that this movie stores under it. """ self.provider_name = provider_name self.movie_name = movie_name
def run(self): """ Execute the procedure. """ # Wait until the interactor finishes the loading procedure while not getInteractor() or not getInteractor().IsLoaded(): sleep(0.05) # We can set the writeLog variable only after the interactor was # loaded, because before that, we don't have the right underlying # function for the writeLog. writeLog = getInteractor().writeLog if getInteractor().InteractionType == InteractionTypes.Gui: from SubProviders import getSelectedLanguages # We need to ask the user to select his languages. if not getSelectedLanguages(): getInteractor().showLanguageSelection() # We are checking for update in each program's load. self.doUpdateCheck() # Now we are ready for the real work. from SubFlow import SubFlow close_on_finish = SubiTConfig.Singleton().getBoolean\ ('Global', 'close_on_finish', False) interactive_by_interactor = getInteractor().InteractionType in [ InteractionTypes.Console, InteractionTypes.Gui] self.interactive = \ interactive_by_interactor and self.interactive_by_input writeLog(INFO_LOGS.STARTING) if self.single_input_queue.empty() and interactive_by_interactor: WriteDebug('The queue is empty from the start, adding user query.') self._put_user_single_input_in_queue() while not self.single_input_queue.empty(): WriteDebug('Getting next_single_input form the queue.') next_single_input = self.single_input_queue.getSingleInput() WriteDebug('Got next_single_input: %s' % next_single_input.printableInfo()) writeLog(INFO_LOGS.STARTING_PROCESSING_OF_SINGLE_INPUT % next_single_input.printableInfo()) writeLog(GUI_SPECIAL_LOGS.SEARCH_LINE_UPDATE % next_single_input.query) try: SubFlow(next_single_input).process(self.interactive) except Exception as eX: WriteDebug('Failed processing the next_single_input: %s' % eX) writeLog(BuildLog(WARN_LOGS._TYPE_, 'SingleInput failure: %s' % str(eX))) else: writeLog(FINISH_LOGS.FINISHED_PROCESSING_SINGLE_INPUT % next_single_input.printableInfo()) # Update the stats after processing the SingleInput self._update_working_stats(next_single_input) if self.single_input_queue.empty() and not close_on_finish: WriteDebug('Queue is empty, getting query from the user.') self._put_user_single_input_in_queue() WriteDebug('Successful downloads: %s' % self.number_of_success) WriteDebug('Failed downloads: %s' % self.number_of_failures) # Finish up. writeLog(FINISH_LOGS.FINISHED) writeLog(FINISH_LOGS.APPLICATION_WILL_NOW_EXIT) # Close program in this stage. exit(2, self._get_exit_code())