def delete_watch_folders_and_files(self, repos_list, sobject_item):
        def onerror(func, path, exc_info):
            """
            Error handler for ``shutil.rmtree``.

            If the error is due to an access error (read only file)
            it attempts to add write permission and then retries.

            If the error is for another reason it re-raises the error.

            Usage : ``shutil.rmtree(path, onerror=onerror)``
            """
            import stat
            if not os.access(path, os.W_OK):
                # Is the error an access error ?
                os.chmod(path, stat.S_IWUSR)
                func(path)
            # else:
            # raise

        for repo in repos_list:
            abs_path = env_tactic.get_base_dir(
                repo)['value'][0] + '/' + sobject_item.get_watch_folder_path()

            if os.path.exists(gf.form_path(abs_path)):
                shutil.rmtree(gf.form_path(abs_path),
                              ignore_errors=True,
                              onerror=onerror)
    def add_item_to_fs_watch(self, skey, path=None, recursive=True):

        watch_dict = self.get_watch_dict_by_skey(skey)

        if not path:
            path = watch_dict['path']

        paths = []
        for repo in watch_dict['rep']:
            abs_path = env_tactic.get_base_dir(repo)['value'][0] + '/' + path
            paths.append(gf.form_path(abs_path))

        self.fs_watcher.append_watch(watch_name=skey, paths=paths, repos=watch_dict['rep'], pipeline=watch_dict['asset_pipeline'], recursive=recursive)
    def create_watch_folders(self, repos_list, sobject_item):

        # creating base folders with paths
        for repo in repos_list:
            abs_path = env_tactic.get_base_dir(
                repo)['value'][0] + '/' + sobject_item.get_watch_folder_path()

            # creating folders by processes
            for process in sobject_item.get_process_list(
                    include_hierarchy=True):
                process_abs_path = abs_path + '/' + process

                if not os.path.exists(gf.form_path(process_abs_path)):
                    os.makedirs(gf.form_path(process_abs_path))
    def fill_watch_folders_tree_widget(self):
        self.watchFoldersTreeWidget.clear()

        if self.watch_folders_dict:

            for i, asset_skey in enumerate(
                    self.watch_folders_dict.get('assets_skeys')):
                root_item = QtGui.QTreeWidgetItem()
                root_item.setData(0, QtCore.Qt.UserRole, asset_skey)

                root_item.setText(1,
                                  self.watch_folders_dict['assets_stypes'][i])
                root_item.setText(2,
                                  self.watch_folders_dict['assets_names'][i])
                repos_names = []

                for repo in self.watch_folders_dict['repos'][i]:
                    repos_names.append(
                        env_tactic.get_base_dir(repo)['value'][1])

                root_item.setText(3, ', '.join(repos_names))

                # setting actual watch status
                if self.watch_folders_dict['statuses'][i]:
                    if self.check_for_item_in_watch(asset_skey):
                        root_item.setText(0, 'Watching')
                        self.start_watch_by_skey(asset_skey)
                    else:
                        root_item.setText(0, 'Waiting')
                else:
                    root_item.setText(0, 'Stopped')
                    self.stop_watch_by_skey(asset_skey)

                self.watchFoldersTreeWidget.addTopLevelItem(root_item)

            self.watchFoldersTreeWidget.resizeColumnToContents(0)
            self.watchFoldersTreeWidget.resizeColumnToContents(1)
            self.watchFoldersTreeWidget.resizeColumnToContents(2)
            self.watchFoldersTreeWidget.resizeColumnToContents(3)

        if self.watched_items:
            self.start_watching()
        else:
            self.stop_watching()