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 build_directory_structure(self, sobject=None):
        import os
        repo = self.repositoryComboBox.itemData(
            self.repositoryComboBox.currentIndex())
        if sobject:
            sobject_class = tc.SObject(sobject, project=self.stype.project)
            self.sobject = sobject_class

        if self.stype.pipeline:

            paths = tc.get_dirs_with_naming(self.sobject.get_search_key(),
                                            None)

            all_paths = []

            if paths:
                if paths['versionless']:
                    all_paths.extend(paths['versionless'])
                if paths['versions']:
                    all_paths.extend(paths['versions'])

            if not repo:
                base_dirs = env_tactic.get_all_base_dirs()
                for key, val in base_dirs:
                    if val['value'][4]:
                        for path in all_paths:
                            abs_path = val['value'][0] + '/' + path
                            if not os.path.exists(gf.form_path(abs_path)):
                                os.makedirs(gf.form_path(abs_path))
            else:
                for path in all_paths:
                    abs_path = repo['value'][0] + '/' + path
                    if not os.path.exists(gf.form_path(abs_path)):
                        os.makedirs(gf.form_path(abs_path))
Пример #3
0
    def build_directory_structure(self, sobject=None):
        import os
        repo = self.repositoryComboBox.itemData(
            self.repositoryComboBox.currentIndex())
        if sobject:
            sobject_class = tc.SObject(sobject, project=self.stype.project)
            self.sobject = sobject_class

        if self.stype.pipeline:
            current_pipeline = self.stype.pipeline.get(
                self.sobject.get_pipeline_code())
            workflow = self.stype.get_workflow()
            processes_list = current_pipeline.get_all_processes_names()
            sub_processes_list = []

            # getting sub-processes from workflow
            for process, process_info in current_pipeline.process.items():
                if process_info.get('type') == 'hierarchy':
                    child_pipeline = workflow.get_child_pipeline_by_process_code(
                        current_pipeline, process)
                    if child_pipeline:
                        sub_processes_list.extend(
                            child_pipeline.get_all_processes_names())

            if sub_processes_list:
                processes_list.extend(sub_processes_list)

            paths = tc.get_dirs_with_naming(self.sobject.get_search_key(),
                                            processes_list)

            all_paths = []

            if paths:
                if paths['versionless']:
                    all_paths.extend(paths['versionless'])
                if paths['versions']:
                    all_paths.extend(paths['versions'])

            if not repo:
                base_dirs = env_tactic.get_all_base_dirs()
                for key, val in base_dirs:
                    if val['value'][4]:
                        for path in all_paths:
                            abs_path = val['value'][0] + '/' + path
                            if not os.path.exists(gf.form_path(abs_path)):
                                os.makedirs(gf.form_path(abs_path))
            else:
                for path in all_paths:
                    abs_path = repo['value'][0] + '/' + path
                    if not os.path.exists(gf.form_path(abs_path)):
                        os.makedirs(gf.form_path(abs_path))
    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))
Пример #5
0
 def fill_versionless_widget(self, paths):
     self.treeWidget_vls.clear()
     for keys, values in paths:
         for i, fl in enumerate(values['versionless']['names']):
             full_path = gf.form_path(self.repo['value'][0] + '/' + values['versionless']['paths'][i])
             item = QtGui.QTreeWidgetItem()
             item.setText(0, u''.join(fl))
             item.setText(1, full_path)
             self.treeWidget_vls.addTopLevelItem(item)
     self.treeWidget_vls.resizeColumnToContents(0)
    def prnt(self, event, watch):

        self.show()

        self.setWindowState(self.windowState() & ~QtCore.Qt.WindowMinimized
                            | QtCore.Qt.WindowActive)
        QtGui.QDialog.activateWindow(self)
        self.show()
        self.hide()

        search_key = watch.watch_name

        commit_path = gf.extract_dirname(event.src_path)

        if watch.path == commit_path:
            context = 'publish'
        else:
            context = gf.form_path(commit_path, 'linux').split('/')[-1]

        description = 'From watch folder'

        skey_dict = tc.split_search_key(search_key)

        checkin_widget = env_inst.get_check_tree(
            project_code=skey_dict['project_code'],
            tab_code='checkin_out',
            wdg_code=skey_dict['pipeline_code'],
        )

        checkin_widget.do_creating_ui()

        match_template = gf.MatchTemplate(['$FILENAME.$EXT'])
        files_objects_dict = match_template.get_files_objects([event.src_path])

        stypes = self.project.get_stypes()
        current_stype = stypes.get(skey_dict['pipeline_code'])
        pipelines = current_stype.get_pipeline()
        print(skey_dict['pipeline_code'])
        current_pipeline = pipelines.get(skey_dict['pipeline_code'])
        print(current_pipeline)
        current_process = current_pipeline.get_process(context)
        print(current_pipeline.process)
        print(current_process)

        checkin_mode = None
        if current_process:
            checkin_mode = current_process.get('checkin_mode')

        checkin_widget.checkin_file_objects(
            search_key=search_key,
            context=context,
            description=description,
            files_objects=files_objects_dict.get('file'),
            checkin_type=checkin_mode,
            keep_file_name=False)
    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)
Пример #8
0
    def fill_versions_widget(self, paths):
        self.treeWidget_vers.clear()
        file_names = []
        for keys, values in paths:
            for i, fl in enumerate(values['versioned']['names']):
                full_path = gf.form_path(self.repo['value'][0] + '/' + values['versioned']['paths'][i])
                item = QtGui.QTreeWidgetItem()
                item.setText(0, u''.join(fl))
                file_names.append(u''.join(fl))
                item.setText(1, full_path)
                self.treeWidget_vers.addTopLevelItem(item)

        if self.commit_item:
            self.commit_item.set_new_title(file_names[0])
        self.treeWidget_vers.resizeColumnToContents(0)
    def add_item_to_watch(self, sobject_item):
        # checking if watch folder exists
        watch_dict = self.get_watch_dict_by_skey(sobject_item.get_search_key())
        all_folders_exists = True
        base_dirs = env_tactic.get_all_base_dirs()

        for key, val in base_dirs:
            if val['value'][4] and val['value'][3] in watch_dict['rep']:
                    abs_path = u'{0}/{1}'.format(val['value'][0], watch_dict['path'])
                    if not os.path.exists(gf.form_path(abs_path)):
                        all_folders_exists = False
                        dl.warning('Folders structure for: {0} is not created. '
                                   'Watch will be ignored.'.format(abs_path),
                                   group_id='watch_folders_ui')

        if all_folders_exists:
            self.watched_items.add(sobject_item)
            self.fill_watch_folders_tree_widget()
    def handle_watch_created_event(self, event, watch):
        dl.log(u'File dropped to watch folder {}'.format(event.src_path), group_id='watch_folder')

        self.show()

        self.setWindowState(self.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
        QtGui.QDialog.activateWindow(self)
        self.show()
        self.hide()

        search_key = watch.watch_name
        pipeline = watch.pipeline

        commit_path = gf.extract_dirname(event.src_path)

        if watch.path == commit_path:
            context = 'publish'
        else:
            context = gf.form_path(commit_path, 'linux').split('/')[-1]

        description = 'From watch folder'

        skey_dict = tc.split_search_key(search_key)

        checkin_widget = env_inst.get_check_tree(
            project_code=skey_dict['project_code'],
            tab_code='checkin_out',
            wdg_code=skey_dict['pipeline_code'],

        )

        checkin_widget.do_creating_ui()

        match_template = gf.MatchTemplate(['$FILENAME.$EXT'])
        files_objects_dict = match_template.get_files_objects([event.src_path])

        stypes = self.project.get_stypes()
        current_stype = stypes.get(skey_dict['pipeline_code'])
        pipelines = current_stype.get_pipeline()

        checkin_mode = None
        if pipelines:

            # here we do pipelines routine
            current_pipeline = pipelines.get(pipeline)
            if not current_pipeline:
                # looks like we don't have pipeline with Search Type name, so we take first of all
                # Also this is totally wrong, cause we should know exactly the pipeline and its processes, so need to write proper pipeline_code when creating watch folder
                current_pipeline = pipelines.values()[0]

            current_process = current_pipeline.get_pipeline_process(context)

            if current_process:
                checkin_mode = current_process.get('checkin_mode')
            else:
                context = 'publish'

            checkin_widget.checkin_file_objects(
                search_key=search_key,
                context=context,
                description=description,
                files_objects=files_objects_dict.get('file'),
                checkin_type=checkin_mode,
                keep_file_name=False
            )
        else:
            # here we go with publish, without pipeline
            checkin_widget.checkin_file_objects(
                search_key=search_key,
                context='publish',
                description=description,
                files_objects=files_objects_dict.get('file'),
                checkin_type=checkin_mode,
                keep_file_name=False
            )