Пример #1
0
    def test_load(self):
        log = _log.Log("Tests/Temp")
        control = _control.Control("Tests/Temp")
        self.assertTrue(control.load(log))
        self.assertFalse(log.error_occurred)
        self.assertFalse(log.warning_occurred)
        self.assertFalse(log.sync_occurred)

        control = _control.Control("Tests/TempWRONG")
        self.assertFalse(control.load(log))
        self.assertTrue(log.error_occurred)
        self.assertFalse(log.warning_occurred)
        self.assertFalse(log.sync_occurred)
Пример #2
0
 def test_schedule(self):
     log = _log.Log("Tests/Temp")
     control = _control.Control("Tests/Temp")
     self.assertTrue(control.load(log))
     now = datetime.datetime.now()
     control.schedule("itstime.json", 1)
     self.assertEqual(
         control.properties["itstime.json"],
         (now +
          datetime.timedelta(seconds=1)).strftime("%Y-%m-%d %H-%M-%S"))
Пример #3
0
    def test_write(self):
        log = _log.Log("Tests/Temp")
        control = _control.Control("Tests/Temp")
        self.assertTrue(control.load(log))
        now = datetime.datetime.now()
        control.schedule("itstime.json", 1)
        self.assertTrue(control.write(log))
        self.assertFalse(log.error_occurred)
        self.assertFalse(log.warning_occurred)
        self.assertFalse(log.sync_occurred)
        self.assertTrue(os.path.isfile(control.path))

        log = _log.Log("Tests/Temp")
        log.path = "Tests/Temp/Logs/Error.txt"
        control = _control.Control("Tests/TempWRONG")
        self.assertFalse(control.load(log))
        self.assertFalse(control.write(log))
        self.assertTrue(log.error_occurred)
        self.assertFalse(log.warning_occurred)
        self.assertFalse(log.sync_occurred)
        # ensures that the log is written right away when needed (critical=True)
        self.assertTrue(os.path.isfile("Tests/Temp/Logs/Error.txt"))
Пример #4
0
 def entity_control_update_cb(self, op, entity, control):
     if (self.destroyed):
         return
     if (op == "added"):
         if (control.get_name() not in self.controls):
             e = _control.Control(self, control)
             pass
         pass
     elif (op == "deleted"):
         if (control.get_name() in self.controls):
             self.controls[control.get_name()].remove()
             pass
         pass
     return
Пример #5
0
import os
import logging


if __name__ == "__main__":
    logging.getLogger("eyed3").setLevel(logging.CRITICAL) # hides the eyed3 console output

    root = os.path.dirname(os.path.realpath(__file__)) # filesystem path to this python file

    first_run = True # helps with the startup delay

    while True:
        log = _log.Log(root) # logs all program operations
        config = _config.Config(root) # main configuration file
        control = _control.Control(root) # controls the sync schedule
        email = _email.Email()  # email sent to the user, if asked

        if not config.load(log): # loads the main config file
            raise SystemExit # force close if an error occurred

        if not control.load(log): # loads the schedule file
            raise SystemExit # force close if an error occurred

        if first_run: # will sleep the startup delay if this is the first program loop
            first_run = False
            config.run_startup_delay(log)

        log.report("") # indentation of the log file
        for (dirpath, dirnames, filenames) in os.walk(os.path.join(root, _paths.syncs_folder)): # runs every sync found
            for file in filenames:
Пример #6
0
 def test_its_time(self):
     log = _log.Log("Tests/Temp")
     control = _control.Control("Tests/Temp")
     self.assertTrue(control.load(log))
     self.assertTrue(control.its_time("itstime.json"))
     self.assertFalse(control.its_time("notyet.json"))
Пример #7
0
 def test_init(self):
     control = _control.Control("Tests/Temp")
     self.assertEqual(
         control.path,
         os.path.join("Tests/Temp", _paths.config_folder,
                      _paths.control_file))