Esempio n. 1
0
    def __init__(self, manager, cfg):
        self.manager = manager
        self.cfg = cfg
        QtGui.QMainWindow.__init__(self)
        self.ui = Ui_AniChou()
        self.ui.setupUi(self)

        # Sync on start
        if self.cfg.startup.get('sync'):
            QtCore.QTimer.singleShot(100, self, QtCore.SLOT('sync()'))

        # Register signals
        signals.Slot('notify', self.notify)
        signals.Slot('set_track_message', self.setTrackMessage)

        # Setup tracker
        self.tracker = signals.Signal()
        self.tracker.connect('start_tracker')
        self.tracker.connect('stop_tracker')
        self.toggleTracker(cfg.startup.get('tracker'))

        # GUI backend must process application-level signals if it has
        # its own main loop
        self.supportTimer = QtCore.QTimer(self)
        self.connect(self.supportTimer, QtCore.SIGNAL('timeout()'),
                     self.supportThread)
        self.supportTimer.start(0.01)

        # TODO: it must be called from service manager or like
        signals.emit(signals.Signal('gui_tables_update'))
Esempio n. 2
0
class Manager(object):
    ERROR_MESSAGES = {
        'bad_service': 'Service {0} not found in loaded services. Skipped.',
        'bad_file': 'Path {0} is not a file. Skipped.',
    }

    services = []

    def __init__(self):
        self.main = None
        self.update_slot = signals.Slot('manager_sync', self.sync)
        self.update_slot = signals.Slot('manager_update_config',
                                        self.updateConfig)

    def __enter__(self):
        self.loadServices()
        return self

    def __exit__(self, type, value, traceback):
        Anime.objects.save()

    def _setLastSync(self, date):
        Anime.objects.db.setdefault('sync', {})['manager'] = date

    def _getLastSync(self):
        try:
            sync = Anime.objects.db['sync']['manager']
        except KeyError:
            self.last_sync = sync = datetime.now()
        return sync

    last_sync = property(_getLastSync, _setLastSync)

    def setConfig(self, config):
        self.config = config
        self.updateConfig()
        if hasattr(config, 'files'):
            self.syncFiles()
            del config['files']

    def syncFiles(self):
        files = {}
        for s, fn in self.config.files.items():
            try:
                service = filter(lambda x: x.internalname == s,
                                 self.services)[0]
                if not os.path.isfile(fn):
                    raise OSError(self.ERROR_MESSAGES['bad_file'].format(fn))
            except IndexError:
                logging.warning(
                    self.ERROR_MESSAGES['bad_service'].format(service))
                continue
            except OSError, e:
                logging.warning(e)
                continue
            files[service] = fn
        # Sync with files after app is ready.
        if files:
            signals.emit(signals.Signal('manager_sync'), None, files)
Esempio n. 3
0
 def sync(self, files={}):
     for service in self.services:
         notify('Syncing with {0}..'.format(service.name))
         if not service.sync(filename=files.get(service)):
             notify('Syncing failed..')
     notify('Syncing Done.')
     self.last_sync = datetime.now()
     Anime.objects.save()
     signals.emit(signals.Signal('gui_tables_update'))
Esempio n. 4
0
 def saveConfig(self):
     self.cfg.startup['sync'] = bool(self.ui.sync.isChecked())
     self.cfg.startup['tracker'] = bool(self.ui.tracker.isChecked())
     self.cfg.search_dirs = self.ui.searchDirs.getValue()
     self.cfg.services['default'] = self.ui.Default_service.getValue()
     for i in range(0, self.ui.services.count()):
         tab = self.ui.services.widget(i)
         self.cfg.services[tab.serviceName] = tab.getValue()
     self.cfg.save()
     signals.emit(signals.Signal('manager_update_config'))
Esempio n. 5
0
 def search(self, string):
     result = set()
     for service in self.services:
         result |= service.search(string)
     signals.emit(signals.Signal('gui_search_create'), None, result)
Esempio n. 6
0
def notify(message):
    logging.info(message)
    signals.emit(signals.Signal('notify'), None, message)
Esempio n. 7
0
 def __init__(self, cfg):
     self.cfg = cfg
     self.trackmessage = signals.Signal()
     self.trackmessage.connect('set_track_message')
     super(Watcher, self).__init__()