Beispiel #1
0
 def __init__(self, browser: str, sid: str, token: str, to: str, from_: str,
              output_dir: str):
     self.__browser = browser
     self.__load_cookie_jar()
     self.__output_dir = output_dir
     self.__notifier = Notifier(sid, token, to, from_)
     self.__lock = Lock()
Beispiel #2
0
 def __init__(self):
     # Notifier #
     self.notifier = Notifier(self.NOTIFIER_KEYS)
     self.notify = self.notifier.notify
     self.connect = self.notifier.connect
     self.disconnect = self.notifier.disconnect
     #
     if HAS_GCONF:
         self.gconf_client = gconf.client_get_default()
         self.quiz_file_path = \
                 self.gconf_client.get_string(self.DEFAULT_QUIZ_KEY)
         self.use_timer = self.gconf_client.get_bool(self.USE_TIMER_KEY)
         self.exam_length = self.gconf_client.get_int(self.EXAM_LENGTH_KEY)
         self.break_length = \
                 self.gconf_client.get_int(self.BREAK_LENGTH_KEY)
         self.snooze_length = \
                 self.gconf_client.get_int(self.SNOOZE_LENGTH_KEY)
         self.gconf_client.add_dir(self.DIR_KEY, gconf.CLIENT_PRELOAD_NONE)
         for gconf_key, notifier_key in zip(self.GCONF_KEYS,
                                            self.NOTIFIER_KEYS):
             self._add_listener(gconf_key, notifier_key,
                                self.value_is_in_range)
         for notifier_key in self.NOTIFIER_KEYS:
             self.connect(notifier_key, self.on_key_changed)
     else:
         self.edit_menuitem.set_visibility(False)
         # Default values #
         self.use_timer = True
         self.exam_length = 20
         self.break_length = 15
         self.snooze_length = 5
         self.quiz_file_path = resource_filename(
             __name__, '../quizzes/deu-fra.drill')
     if not os.path.exists(self.quiz_file_path):
         self.quiz_file_path = None
Beispiel #3
0
    def set_notifier(self, pb_token, name=None):
        """
        Add a pushbullet notifier to the job.
        There can only be one notifier.

        """
        self.remove_notifier()
        if name is None:
            name = "%s - %s" % (self.jobname, self.jobid)
        self.notifier = Notifier(name, pb_token)
Beispiel #4
0
    def __init__(self, id):
        alpr = Alpr("eu", "/etc/openalpr/openalpr.conf", "../runtime_data")
        if not alpr.is_loaded():
            print("Error loading OpenALPR")
            exit()
        alpr.set_top_n(20)

        self.alpr = alpr
        self.notifier = Notifier()
        self.id = id
        self.source = DataSource(self)
Beispiel #5
0
 def __init__(self):
     self.quiz_filer_list = []
     self.notifier = Notifier([
         "break_time", "question_changed", "direction_changed",
         "quiz_changed", "quiz_added", "quiz_removed", "quiz_list_emtpied",
         "quiz_list_non_emtpy"
     ])
     self.notify = self.notifier.notify
     self.connect = self.notifier.connect
     self.disconnect = self.notifier.disconnect
     self.current_quiz = None
     self.current_filer = None
Beispiel #6
0
 def __init__(self, quiz_pool, ask_from=0, exam_length=15):
     self.notifier = Notifier(
         ["break_time", "question_changed", "direction_changed"])
     self.notify = self.notifier.notify
     self.connect = self.notifier.connect
     self.disconnect = self.notifier.disconnect
     #
     self.previous_question = None
     self.quiz_pool = []
     self.answered = 0
     self.correct_answered = 0
     self.exam_length = exam_length
     self.session_length = exam_length
     self.ask_from = ask_from
     self.answer_to = 1 - ask_from
     self.add_quizzes(quiz_pool)
Beispiel #7
0
def main():
    config, backup_paths, key_paths = parse_config()

    try:
        check_should_backup(config)
    except BackupPrerequisiteFailed as e:
        print('Not backing up, for reason:')
        print(e.args[0])
        sys.exit(1)

    notifier = Notifier()
    notifier.notify('Starting backup')

    for bp in backup_paths.values():
        if bp.automount:
            mount_path_if_necessary(bp.mount_path)

        try:
            for name, snapshot in search_snapshots(bp.path).items():
                if snapshot.newest == snapshot.base:
                    message = "Most recent snapshot for '{}' ({}) already on remote system".format(
                        name,
                        snapshot.newest,
                    )
                    print(message)
                else:
                    message = (
                        "Need to backup subvolume {} (base snapshot: {}, most recent: {})"
                    ).format(
                        name,
                        snapshot.base,
                        snapshot.newest,
                    )
                    print(message)
                    backup_snapshot(snapshot, config['server']['host'],
                                    key_paths)

        finally:
            if bp.automount:
                umount_path(bp.mount_path)

    notifier.notify('Backup complete')
Beispiel #8
0
def restore_db():
    settings = get_settings()
    service = MontaguService(settings)
    notifier = Notifier(settings['notify_channel'])
    try:
        ok = service.status == 'running' and service.db_volume_present
        if not ok:
            raise Exception('montagu not in a state we can restore')
        bb8_backup.restore(service)
        database.setup(service)
        if settings["add_test_user"] is True:
            add_test_users()
        notifier.post("*Restored* data from backup on `{}` :recycle:".format(
            settings['instance_name']))
    except Exception as e:
        print(e)
        try:
            notifier.post("*Failed* to restore data on `{}` :bomb:",
                          settings['instance_name'])
        except:
            raise
Beispiel #9
0
def _deploy():
    print_ascii_art()
    print("Beginning Montagu deploy")

    settings = get_settings()
    service = MontaguService(settings)
    status = service.status
    volume_present = service.db_volume_present
    is_first_time = (status is None) and (not volume_present)
    if is_first_time:
        print("Montagu not detected: Beginning new deployment")
    else:
        print("Montagu status: {}. "
              "Data volume present: {}".format(status, volume_present))

    notifier = Notifier(settings['notify_channel'])

    # Check that the deployment environment is clean enough
    version = git_check(settings)

    deploy_str = "montagu {} (`{}`) on `{}`".format(
        version['tag'] or "(untagged)", version['sha'][:7],
        settings['instance_name'])

    notifier.post("*Starting* deploy of " + deploy_str)

    # Pull images
    service.pull()

    # If Montagu is running, back it up before tampering with it
    if status == "running":
        if settings["bb8_backup"]:
            bb8_backup.backup()

    # Stop Montagu if it is running
    # (and delete data volume if persist_data is False)
    if not is_first_time:
        notifier.post("*Stopping* previous montagu "
                      "on `{}` :hand:".format(settings['instance_name']))
        service.stop()

    # Schedule backups
    if settings["bb8_backup"]:
        bb8_backup.schedule()

    # BB8 restore
    data_exists = (not is_first_time) and service.settings["persist_data"]
    if settings["initial_data_source"] == "bb8_restore":
        data_update = service.settings["update_on_deploy"] and \
                      not service.settings["bb8_backup"]
        if data_exists and not data_update:
            print("Skipping bb8 restore: 'persist_data' is set, "
                  "and this is not a first-time deployment")
        else:
            print("Running bb8 restore (while service is stopped)")
            bb8_backup.restore()

    # Start Montagu again
    service.start()
    try:
        print("Configuring Montagu")
        configure_montagu(service, data_exists)

        print("Starting Montagu metrics")
        service.start_metrics()

        print("Montagu metrics started")
    except Exception as e:
        print("An error occurred before deployment could be completed:")
        print(e)
        print("\nYou may need to call ./stop.py before redeploying.")
        try:
            notifier.post("*Failed* deploy of " + deploy_str + " :bomb:")
        except:
            pass
        raise

    if settings["add_test_user"] is True:
        print("Adding tests users")
        add_test_users()

    last_deploy_update(version)
    notifier.post("*Completed* deploy of " + deploy_str + " :shipit:")

    print("Finished deploying Montagu")
    if settings["open_browser"]:
        sleep(1)
        webbrowser.open("https://localhost:{}/".format(settings["port"]))