def lock(self): self._homedir = get_user_dir( ) + utils.path_sep + u"." + self._name.lower() if not utils.path_exists(self._homedir): utils.path_makedirs(self._homedir) self._lockfilename = self._homedir + utils.path_sep + "monitor.lock" try: if is_linux(): import fcntl self._lockfile = utils.file_open(self._lockfilename, "w") fcntl.lockf(self._lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB) else: if utils.path_exists(self._lockfilename): utils.path_remove(self._lockfilename) self._lockfile = utils.file_open(self._lockfilename, "w") self._lockfile.write("\x00") except: try: self._lockfile.close() except: None if self._mode == "systray": print("An Instance is already running.") else: self.add_show_file() return False #self.remove_show_file() return True
def _cpmv(self, tp, fs, fd, replace): bok = True if utils.path_isdir(fs): if not utils.path_exists(fd): utils.path_makedirs(fd) if tp=="copy": self._agent_main.get_osmodule().fix_file_permissions("COPY_DIRECTORY",fd, fs) elif tp=="move": self._agent_main.get_osmodule().fix_file_permissions("MOVE_DIRECTORY",fd, fs) lst=None try: lst=utils.path_list(fs) for fname in lst: b = self._cpmv(tp, fs + utils.path_sep + fname, fd + utils.path_sep + fname, replace) if bok is True: bok = b except Exception: bok=False if tp=="move": try: utils.path_remove(fs) except Exception: bok=False else: b=True if utils.path_exists(fd): if replace is True: try: utils.path_remove(fd) except Exception: bok = False b = False else: b = False if b is True: try: if tp=="copy": utils.path_copy(fs, fd) self._agent_main.get_osmodule().fix_file_permissions("COPY_FILE",fd, fs) elif tp=="move": utils.path_move(fs, fd) self._agent_main.get_osmodule().fix_file_permissions("MOVE_FILE",fd) except Exception: bok=False return bok