From f38b5fd705309ed9041dba6c267654f485d29d1d Mon Sep 17 00:00:00 2001 From: Gina Guerrero Date: Sat, 6 Jun 2015 21:42:05 -0400 Subject: [PATCH 1/3] Prelim Update Subs Maya UI --- dpa/data/config/maya/shelves.cfg | 8 + .../config/product/subscription/update.cfg | 27 +++ dpa/ui/product/__init__.py | 0 dpa/ui/product/subscription/__init__.py | 0 dpa/ui/product/subscription/update.py | 187 ++++++++++++++++++ 5 files changed, 222 insertions(+) create mode 100644 dpa/data/config/product/subscription/update.cfg create mode 100644 dpa/ui/product/__init__.py create mode 100644 dpa/ui/product/subscription/__init__.py create mode 100644 dpa/ui/product/subscription/update.py diff --git a/dpa/data/config/maya/shelves.cfg b/dpa/data/config/maya/shelves.cfg index cb1895a..a487480 100644 --- a/dpa/data/config/maya/shelves.cfg +++ b/dpa/data/config/maya/shelves.cfg @@ -55,3 +55,11 @@ Pipeline: annotation: Create references from subscriptions image: "icon:///images/icons/import_32x32.png" + updatesubs: + command: | + from dpa.ui.product.subscription.update import ProductSubscriptionUpdateDialog + ProductSubscriptionUpdateDialog().show() + label: Update Subscriptions + annotation: Update subscriptions + image: "icon:///images/icons/import_32x32.png" + diff --git a/dpa/data/config/product/subscription/update.cfg b/dpa/data/config/product/subscription/update.cfg new file mode 100644 index 0000000..2f062d9 --- /dev/null +++ b/dpa/data/config/product/subscription/update.cfg @@ -0,0 +1,27 @@ +options: + + outdated_subs: + type: list + help: Outdated Subscriptions + label: "Choose Outdated Subs to Update" + required: True + choices: [] + default: + + unofficial_subs: + type: list + help: Subscriptions that aren't official + label: "Unofficial Subscriptions" + required: False + multiple: False + choices: [] + default: + + current_subs: + type: list + help: Subcriptions that are current + label: "Up-to-date Subscriptions" + required: False + multiple: False + choices: [] + default: diff --git a/dpa/ui/product/__init__.py b/dpa/ui/product/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dpa/ui/product/subscription/__init__.py b/dpa/ui/product/subscription/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dpa/ui/product/subscription/update.py b/dpa/ui/product/subscription/update.py new file mode 100644 index 0000000..504103e --- /dev/null +++ b/dpa/ui/product/subscription/update.py @@ -0,0 +1,187 @@ +"""Check/Update subscriptions of the supplied ptask.""" +from collections import defaultdict + +from PySide import QtCore, QtGui + +from dpa.action import ActionError +from dpa.action.registry import ActionRegistry +from dpa.ptask import PTask, PTaskError +from dpa.ptask.area import PTaskArea +from dpa.ui.app.session import SessionActionDialog +from dpa.ui.icon.factory import IconFactory +from dpa.app.session import SessionRegistry + +# ----------------------------------------------------------------------------- + +VERSION_ICON_URI = "icon:///images/icons/import_32x32.png" +VERSION_OPTIONS_CONFIG = "config/product/subscription/update.cfg" + +# ----------------------------------------------------------------------------- +class ProductSubscriptionUpdateDialog(SessionActionDialog): + + # ------------------------------------------------------------------------- + def __init__(self): + + self._ptask_area = PTaskArea.current() + options_config = self._ptask_area.config(VERSION_OPTIONS_CONFIG, + composite_ancestors=True) + + self.check_subscriptions() + + if 'outdated' in self.sublist: + options_config['options']['outdated_subs'].set('choices', + self.sublist['outdated'].keys()) + + if 'unofficial' in self.sublist: + options_config['options']['unofficial_subs'].set('choices', + self.sublist['unofficial'].keys()) + + if 'current' in self.sublist: + options_config['options']['current_subs'].set('choices', + self.sublist['current'].keys()) + + try: + self._ptask = PTask.get(self._ptask_area.spec) + except PTaskError as e: + error_dialog = QtGui.QErrorMessage(self) + error_dialog.setWindowTitle('Subscription Update Failure') + error_dialog.showMessage("Unable to update subscriptions.") + return + + icon_path = IconFactory().disk_path(VERSION_ICON_URI) + + super(ProductSubscriptionUpdateDialog, self).__init__( + title='Update Existing Subscriptions', + options_config=options_config, + icon_path=icon_path, + action_button_text='Update', + modal=False, + ) + + # ------------------------------------------------------------------------- + def accept(self): + print "before confirm" + + if not self._confirm(): + return + + # Just like in PTaskVersionDialog, this needs to + # Call the session's reload()-like feature (should be written) + # Necessary for programs like Mari, not necessarily Maya + + # handles closing the dialog + super(ProductSubscriptionUpdateDialog, self).accept() + + try: + if len(self.updatelist) > 0: + version_action_cls = ActionRegistry().get_action('update', 'subs') + version_action = version_action_cls(self._ptask, self.updatelist['subs'][0]) + version_action() + except ActionError as e: + error_dialog = QtGui.QErrorMessage(self.parent()) + error_dialog.setWindowTitle('Update Subscription Failure') + error_dialog.showMessage( + "There was an error updating the subscriptions." + ) + else: + QtGui.QMessageBox.question(self, "Updating Subscriptions Successful", + "Updating subscriptions was successful.", + buttons=QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Ok, + defaultButton=QtGui.QMessageBox.NoButton, + ) + + # ------------------------------------------------------------------------- + def _confirm(self): + self._to_update = defaultdict(dict) + self._to_update['subs'] = [] + + for pspec in self.options.value['outdated_subs']: + self._to_update['subs'].append(self.sublist['outdated'][pspec]) + + confirm_message = """ + Confirm subscription update:
+ + + + + + + + """.format( + ptask=self._ptask.spec, + ) + + i = 0 + for spec in self.options.value.outdated_subs: + to_version = self.updatelist['subs'][0][i].product_version.product.official_version + if not to_version: + to_version = self.updatelist['subs'][0][i].product_version.product.latest_published().number + + cur_version = self.updatelist['subs'][0][i].product_version.number + confirm_message += """ + + + + + + """.format( + k=spec, + v=cur_version, + nv=to_version + ) + i += 1 + + confirm_message += """ +
Product Spec:  Version  New Version
{k} :  {v}   {nv}


+ This will also refresh your import directory and attempt to reload.

+ Update Subscriptions? + """ + + # info dialog showing what will be done + proceed = QtGui.QMessageBox.question( + self, + "Version Up Confirmation", + confirm_message, + buttons=QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Yes, + defaultButton=QtGui.QMessageBox.NoButton, + ) + + return proceed == QtGui.QMessageBox.Yes + + + # ------------------------------------------------------------------------- + def check_subscriptions(self): + sublist = defaultdict(dict) + + # get existing subscriptions, exclude deprecated + for sub in SessionRegistry().current().ptask_version.subscriptions: + sub_prod = sub.product_version.product + + if sub.product_version.number == sub_prod.latest_published().number: + sublist['current'][sub_prod.spec] = [sub] + + if sub.product_version.number != sub_prod.official_version: + sublist['unofficial'][sub_prod.spec] = [sub] + else: + sublist['outdated'][sub_prod.spec] = [sub] + + if sub.product_version.number != sub_prod.official_version: + sublist['unofficial'][sub_prod.spec] = [sub] + + self._sublist = sublist + + # ------------------------------------------------------------------------- + @property + def sublist(self): + if not hasattr(self, '_sublist'): + return defaultdict(dict) + + return self._sublist + + # ------------------------------------------------------------------------- + @property + def updatelist(self): + if not hasattr(self, '_to_update'): + return defaultdict(dict) + + return self._to_update From bb27365298d5ef60899ad0b959b35a7ffe611235 Mon Sep 17 00:00:00 2001 From: Gina Guerrero Date: Sat, 6 Jun 2015 21:53:34 -0400 Subject: [PATCH 2/3] Now I changed a few names, and fixed the variable issue. --- dpa/product/subscription/action/update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpa/product/subscription/action/update.py b/dpa/product/subscription/action/update.py index 660fa8e..c6d6744 100644 --- a/dpa/product/subscription/action/update.py +++ b/dpa/product/subscription/action/update.py @@ -163,7 +163,7 @@ def validate(self): for sub in self._subs: if isinstance(sub, ProductSubscription): - subs_to_udpate.append(sub) + subs.append(sub) continue try: From d1bbd86d197e2c6260b07f4f25d1c32b9eec71b8 Mon Sep 17 00:00:00 2001 From: Gina Guerrero Date: Sat, 6 Jun 2015 21:57:33 -0400 Subject: [PATCH 3/3] Changed dialogue on success. --- dpa/ui/product/subscription/update.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dpa/ui/product/subscription/update.py b/dpa/ui/product/subscription/update.py index 504103e..7abf24e 100644 --- a/dpa/ui/product/subscription/update.py +++ b/dpa/ui/product/subscription/update.py @@ -13,8 +13,8 @@ # ----------------------------------------------------------------------------- -VERSION_ICON_URI = "icon:///images/icons/import_32x32.png" -VERSION_OPTIONS_CONFIG = "config/product/subscription/update.cfg" +UPDATE_ICON_URI = "icon:///images/icons/import_32x32.png" +UPDATE_OPTIONS_CONFIG = "config/product/subscription/update.cfg" # ----------------------------------------------------------------------------- class ProductSubscriptionUpdateDialog(SessionActionDialog): @@ -23,7 +23,7 @@ class ProductSubscriptionUpdateDialog(SessionActionDialog): def __init__(self): self._ptask_area = PTaskArea.current() - options_config = self._ptask_area.config(VERSION_OPTIONS_CONFIG, + options_config = self._ptask_area.config(UPDATE_OPTIONS_CONFIG, composite_ancestors=True) self.check_subscriptions() @@ -48,7 +48,7 @@ def __init__(self): error_dialog.showMessage("Unable to update subscriptions.") return - icon_path = IconFactory().disk_path(VERSION_ICON_URI) + icon_path = IconFactory().disk_path(UPDATE_ICON_URI) super(ProductSubscriptionUpdateDialog, self).__init__( title='Update Existing Subscriptions', @@ -74,9 +74,9 @@ def accept(self): try: if len(self.updatelist) > 0: - version_action_cls = ActionRegistry().get_action('update', 'subs') - version_action = version_action_cls(self._ptask, self.updatelist['subs'][0]) - version_action() + update_action_cls = ActionRegistry().get_action('update', 'subs') + update_action_cls = update_action_cls(self._ptask, self.updatelist['subs'][0]) + update_action_cls() except ActionError as e: error_dialog = QtGui.QErrorMessage(self.parent()) error_dialog.setWindowTitle('Update Subscription Failure') @@ -84,8 +84,8 @@ def accept(self): "There was an error updating the subscriptions." ) else: - QtGui.QMessageBox.question(self, "Updating Subscriptions Successful", - "Updating subscriptions was successful.", + QtGui.QMessageBox.question(self, "Updating Subscriptions Results", + "Please verify results in the console.", buttons=QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Ok, defaultButton=QtGui.QMessageBox.NoButton, )