示例#1
0
    def __init__(self,
                 configs,
                 cli_options=None,
                 cfg_patches=None,
                 cli_args=None,
                 no_local=False,
                 log_handlers=None,
                 wait_lock=False,
                 files=None,
                 ammo_file=None,
                 api_start=False,
                 manager=None,
                 debug=False):
        self.api_start = api_start
        self.wait_lock = wait_lock
        self.log_handlers = log_handlers if log_handlers is not None else []
        self.files = [] if files is None else files
        self.ammo_file = ammo_file
        self.config_paths = configs
        self.interrupted = ProcessEvent() if api_start else ThreadEvent()
        self.info = TankInfo(manager.dict()) if api_start else TankInfo(dict())
        self.config_list = self._combine_configs(configs, cli_options,
                                                 cfg_patches, cli_args,
                                                 no_local)
        self.core = TankCore(self.config_list, self.interrupted, self.info)
        self.folder = self.init_folder()
        self.init_logging(debug
                          or self.core.get_option(self.core.SECTION, 'debug'))

        is_locked = Lock.is_locked(self.core.lock_dir)
        if is_locked and not self.core.config.get_option(
                self.SECTION, 'ignore_lock'):
            raise LockError(is_locked)
示例#2
0
 def get_lock(self):
     while not self.interrupted.is_set():
         try:
             lock = Lock(self.test_id, self.folder).acquire(
                 self.core.lock_dir,
                 self.core.config.get_option(self.SECTION, 'ignore_lock'))
             break
         except LockError as e:
             self.upd_msg(e.message)
             if not self.wait_lock:
                 raise RuntimeError("Lock file present, cannot continue")
             logger.warning("Couldn't get lock. Will retry in 5 seconds...")
             time.sleep(5)
     else:
         raise KeyboardInterrupt
     return lock
示例#3
0
def test_running_ids():
    Lock('123', 'tests/123').acquire(TEST_DIR)
    Lock('124', 'tests/124').acquire(TEST_DIR, ignore=True)
    assert set(Lock.running_ids(TEST_DIR)) == {'123', '124'}
示例#4
0
def test_release():
    lock = Lock('123', 'tests/123').acquire(TEST_DIR)
    assert len(glob.glob(os.path.join(TEST_DIR, Lock.LOCK_FILE_WILDCARD))) == 1
    lock.release()
    assert len(glob.glob(os.path.join(TEST_DIR, Lock.LOCK_FILE_WILDCARD))) == 0
示例#5
0
def test_ignore():
    Lock('123', 'tests/123').acquire(TEST_DIR)
    Lock('124', 'tests/124').acquire(TEST_DIR, ignore=True)
    assert len(glob.glob(os.path.join(TEST_DIR, Lock.LOCK_FILE_WILDCARD))) == 2
示例#6
0
def test_load():
    lock = Lock('123', 'tests/123').acquire(TEST_DIR)
    lock_loaded = Lock.load(lock.lock_file)
    assert lock_loaded.info == lock.info
示例#7
0
def test_acquire():
    Lock('123', 'tests/123').acquire(TEST_DIR)
    with pytest.raises(LockError):
        Lock('124', 'test/124').acquire(TEST_DIR)