Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3673 from pypeclub/feature/use_get_projects
Browse files Browse the repository at this point in the history
General: Use client projects getter
  • Loading branch information
iLLiCiTiT authored Aug 17, 2022
2 parents 3f805bc + 68ca589 commit f4aa1c7
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 92 deletions.
8 changes: 6 additions & 2 deletions openpype/modules/kitsu/utils/update_zou_with_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import gazu
from pymongo import UpdateOne

from openpype.client import get_project, get_assets
from openpype.client import (
get_projects,
get_project,
get_assets,
)
from openpype.pipeline import AvalonMongoDB
from openpype.api import get_project_settings
from openpype.modules.kitsu.utils.credentials import validate_credentials
Expand Down Expand Up @@ -37,7 +41,7 @@ def sync_zou(login: str, password: str):
dbcon = AvalonMongoDB()
dbcon.install()

op_projects = [p for p in dbcon.projects()]
op_projects = list(get_projects())
for project_doc in op_projects:
sync_zou_from_op_project(project_doc["name"], dbcon, project_doc)

Expand Down
9 changes: 3 additions & 6 deletions openpype/modules/sync_server/sync_server_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import copy
from collections import deque, defaultdict


from openpype.client import get_projects
from openpype.modules import OpenPypeModule
from openpype_interfaces import ITrayModule
from openpype.settings import (
Expand Down Expand Up @@ -913,7 +913,7 @@ def get_enabled_projects(self):
enabled_projects = []

if self.enabled:
for project in self.connection.projects(projection={"name": 1}):
for project in get_projects(fields=["name"]):
project_name = project["name"]
if self.is_project_enabled(project_name):
enabled_projects.append(project_name)
Expand Down Expand Up @@ -1242,10 +1242,7 @@ def set_sync_project_settings(self, exclude_locals=False):
def _prepare_sync_project_settings(self, exclude_locals):
sync_project_settings = {}
system_sites = self.get_all_site_configs()
project_docs = self.connection.projects(
projection={"name": 1},
only_active=True
)
project_docs = get_projects(fields=["name"])
for project_doc in project_docs:
project_name = project_doc["name"]
sites = copy.deepcopy(system_sites) # get all configured sites
Expand Down
3 changes: 2 additions & 1 deletion openpype/tools/launcher/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import qtawesome

from openpype.client import (
get_projects,
get_project,
get_assets,
)
Expand Down Expand Up @@ -527,7 +528,7 @@ def refresh_projects(self):
current_project = self.project_name
project_names = set()
project_docs_by_name = {}
for project_doc in self._dbcon.projects(only_active=True):
for project_doc in get_projects():
project_name = project_doc["name"]
project_names.add(project_name)
project_docs_by_name[project_name] = project_doc
Expand Down
4 changes: 2 additions & 2 deletions openpype/tools/libraryloader/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from Qt import QtWidgets, QtCore, QtGui

from openpype import style
from openpype.client import get_project
from openpype.client import get_projects, get_project
from openpype.pipeline import AvalonMongoDB
from openpype.tools.utils import lib as tools_lib
from openpype.tools.loader.widgets import (
Expand Down Expand Up @@ -239,7 +239,7 @@ def _set_projects(self):

def get_filtered_projects(self):
projects = list()
for project in self.dbcon.projects():
for project in get_projects(fields=["name", "data.library_project"]):
is_library = project.get("data", {}).get("library_project", False)
if (
(is_library and self.show_libraries) or
Expand Down
7 changes: 2 additions & 5 deletions openpype/tools/project_manager/project_manager/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from Qt import QtCore, QtGui

from openpype.client import (
get_projects,
get_project,
get_assets,
get_asset_ids_with_subsets,
Expand Down Expand Up @@ -54,12 +55,8 @@ def refresh(self):
self._items_by_name[None] = none_project
new_project_items.append(none_project)

project_docs = self.dbcon.projects(
projection={"name": 1},
only_active=True
)
project_names = set()
for project_doc in project_docs:
for project_doc in get_projects(fields=["name"]):
project_name = project_doc.get("name")
if not project_name:
continue
Expand Down
6 changes: 3 additions & 3 deletions openpype/tools/sceneinventory/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from Qt import QtWidgets, QtCore
import qtawesome

from openpype.pipeline import legacy_io
from openpype import style
from openpype.client import get_projects
from openpype.pipeline import legacy_io
from openpype.tools.utils.delegates import VersionDelegate
from openpype.tools.utils.lib import (
qt_app_context,
Expand Down Expand Up @@ -195,8 +196,7 @@ def show(root=None, debug=False, parent=None, items=None):

if not os.environ.get("AVALON_PROJECT"):
any_project = next(
project for project in legacy_io.projects()
if project.get("active", True) is not False
project for project in get_projects()
)

project_name = any_project["name"]
Expand Down
66 changes: 25 additions & 41 deletions openpype/tools/settings/settings/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from Qt import QtWidgets, QtCore, QtGui
import qtawesome

from openpype.client import get_projects
from openpype.pipeline import AvalonMongoDB
from openpype.style import get_objected_colors
from openpype.tools.utils.widgets import ImageButton
Expand Down Expand Up @@ -783,8 +784,6 @@ def __init__(self, only_active, *args, **kwargs):

self.setColumnCount(2)

self.dbcon = None

self._only_active = only_active
self._default_item = None
self._items_by_name = {}
Expand Down Expand Up @@ -828,9 +827,6 @@ def flags(self, index):
index = self.index(index.row(), 0, index.parent())
return super(ProjectModel, self).flags(index)

def set_dbcon(self, dbcon):
self.dbcon = dbcon

def refresh(self):
# Change id of versions refresh
self._version_refresh_id = uuid.uuid4()
Expand All @@ -846,31 +842,30 @@ def refresh(self):

self._default_item.setData("", PROJECT_VERSION_ROLE)
project_names = set()
if self.dbcon is not None:
for project_doc in self.dbcon.projects(
projection={"name": 1, "data.active": 1},
only_active=self._only_active
):
project_name = project_doc["name"]
project_names.add(project_name)
if project_name in self._items_by_name:
item = self._items_by_name[project_name]
else:
item = QtGui.QStandardItem(project_name)

self._items_by_name[project_name] = item
new_items.append(item)

is_active = project_doc.get("data", {}).get("active", True)
item.setData(project_name, PROJECT_NAME_ROLE)
item.setData(is_active, PROJECT_IS_ACTIVE_ROLE)
item.setData("", PROJECT_VERSION_ROLE)
item.setData(False, PROJECT_IS_SELECTED_ROLE)

if not is_active:
font = item.font()
font.setItalic(True)
item.setFont(font)
for project_doc in get_projects(
inactive=not self._only_active,
fields=["name", "data.active"]
):
project_name = project_doc["name"]
project_names.add(project_name)
if project_name in self._items_by_name:
item = self._items_by_name[project_name]
else:
item = QtGui.QStandardItem(project_name)

self._items_by_name[project_name] = item
new_items.append(item)

is_active = project_doc.get("data", {}).get("active", True)
item.setData(project_name, PROJECT_NAME_ROLE)
item.setData(is_active, PROJECT_IS_ACTIVE_ROLE)
item.setData("", PROJECT_VERSION_ROLE)
item.setData(False, PROJECT_IS_SELECTED_ROLE)

if not is_active:
font = item.font()
font.setItalic(True)
item.setFont(font)

root_item = self.invisibleRootItem()
for project_name in tuple(self._items_by_name.keys()):
Expand Down Expand Up @@ -1067,8 +1062,6 @@ def __init__(self, parent, only_active=False):
self.project_model = project_model
self.inactive_chk = inactive_chk

self.dbcon = None

def set_entity(self, entity):
self._entity = entity

Expand Down Expand Up @@ -1211,15 +1204,6 @@ def refresh(self):
selected_project = index.data(PROJECT_NAME_ROLE)
break

if not self.dbcon:
try:
self.dbcon = AvalonMongoDB()
self.dbcon.install()
except Exception:
self.dbcon = None
self.current_project = None

self.project_model.set_dbcon(self.dbcon)
self.project_model.refresh()

self.project_proxy.sort(0)
Expand Down
8 changes: 3 additions & 5 deletions openpype/tools/standalonepublish/widgets/widget_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import qtawesome

from openpype.client import (
get_projects,
get_project,
get_asset_by_id,
)
Expand Down Expand Up @@ -291,9 +292,7 @@ def _add_last_project(self, project_name):
def _set_projects(self):
project_names = list()

for doc in self.dbcon.projects(projection={"name": 1},
only_active=True):

for doc in get_projects(fields=["name"]):
project_name = doc.get("name")
if project_name:
project_names.append(project_name)
Expand All @@ -320,8 +319,7 @@ def _set_projects(self):
def on_project_change(self):
projects = list()

for project in self.dbcon.projects(projection={"name": 1},
only_active=True):
for project in get_projects(fields=["name"]):
projects.append(project['name'])
project_name = self.combo_projects.currentText()
if project_name in projects:
Expand Down
4 changes: 0 additions & 4 deletions openpype/tools/utils/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,6 @@ def _refresh(self):
if profiles:
# Make sure connection is installed
# - accessing attribute which does not have auto-install
self.dbcon.install()
database = getattr(self.dbcon, "database", None)
if database is None:
database = self.dbcon._database
asset_doc = get_asset_by_name(
project_name, asset_name, fields=["data.tasks"]
) or {}
Expand Down
47 changes: 24 additions & 23 deletions openpype/tools/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import Qt
from Qt import QtCore, QtGui
from openpype.client import get_projects
from .constants import (
PROJECT_IS_ACTIVE_ROLE,
PROJECT_NAME_ROLE,
Expand Down Expand Up @@ -296,29 +297,29 @@ def refresh(self):
self._default_item = item

project_names = set()
if self.dbcon is not None:
for project_doc in self.dbcon.projects(
projection={"name": 1, "data.active": 1},
only_active=self._only_active
):
project_name = project_doc["name"]
project_names.add(project_name)
if project_name in self._items_by_name:
item = self._items_by_name[project_name]
else:
item = QtGui.QStandardItem(project_name)

self._items_by_name[project_name] = item
new_items.append(item)

is_active = project_doc.get("data", {}).get("active", True)
item.setData(project_name, PROJECT_NAME_ROLE)
item.setData(is_active, PROJECT_IS_ACTIVE_ROLE)

if not is_active:
font = item.font()
font.setItalic(True)
item.setFont(font)
project_docs = get_projects(
inactive=not self._only_active,
fields=["name", "data.active"]
)
for project_doc in project_docs:
project_name = project_doc["name"]
project_names.add(project_name)
if project_name in self._items_by_name:
item = self._items_by_name[project_name]
else:
item = QtGui.QStandardItem(project_name)

self._items_by_name[project_name] = item
new_items.append(item)

is_active = project_doc.get("data", {}).get("active", True)
item.setData(project_name, PROJECT_NAME_ROLE)
item.setData(is_active, PROJECT_IS_ACTIVE_ROLE)

if not is_active:
font = item.font()
font.setItalic(True)
item.setFont(font)

root_item = self.invisibleRootItem()
for project_name in tuple(self._items_by_name.keys()):
Expand Down

0 comments on commit f4aa1c7

Please sign in to comment.