forked from shotgunsoftware/tk-framework-perforce
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsync.py
More file actions
116 lines (87 loc) · 3.61 KB
/
Copy pathsync.py
File metadata and controls
116 lines (87 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright (c) 2013 Shotgun Software Inc.
#
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
# Source Code License included in this distribution package. See LICENSE.
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.
"""
Common Perforce sync utility methods
"""
import os
import socket
import re
import threading
import sgtk
from sgtk import TankError
from sgtk.platform.qt import QtGui
from P4 import P4, P4Exception
class SgtkP4Error(TankError):
"""
Specialisation of TankError raised after catching and processing a P4Exception
"""
class SyncHandler(object):
"""
Encapsulate loading sync window. Entity data is handed directly to the UI so that
it can delegate data lookups from p4 in workers rather than stall main thread while
user waits for visual feedback of the UI init completing.
"""
def __init__(self, fw):
"""
Construction
"""
self._fw = fw
self._p4 = None
self.p4_server = self._get_p4_server()
def sync_with_dlg(self, app, entities_to_sync, specific_files=False, child_asset_ids=None):
"""
Show the sync window for user file syncing
:returns: None
"""
self.entities_to_sync = entities_to_sync
self.app = app
self.specific_files = specific_files
self.child_asset_ids = child_asset_ids
try:
# ensure this always runs on the main thread:
return self._fw.engine.execute_in_main_thread(self._sync_with_dlg)
finally:
pass
def _sync_with_dlg(self):
"""
Actual implementation of sync_with_dlg.
:returns: None
"""
server = self.p4_server
sg_user = sgtk.util.get_current_user(self._fw.sgtk)
user = self._fw.execute_hook("hook_get_perforce_user", sg_user=sg_user)
try:
from ..widgets import SyncForm
result, _ = self._fw.engine.show_modal("Perforce Sync ", self._fw, SyncForm,
self.app, self.entities_to_sync, self.specific_files, self.child_asset_ids)
if result == QtGui.QDialog.Accepted:
pass
except Exception as e:
self._fw.log_error(e)
return None
def _get_p4_server(self):
user = sgtk.util.get_current_user(self._fw.sgtk)
sg_user = self._fw.shotgun.find_one('HumanUser', [['id', 'is', user['id']]], ["sg_region"])
server_field = self._fw.get_setting("server_field")
sg_project = self._fw.shotgun.find_one('Project', [['id', 'is', self._fw.context.project['id']]], [server_field])
server = sg_project.get(server_field)
region = sg_user.get("sg_region")
sg_server = self._fw.shotgun.find_one('CustomNonProjectEntity02', [['id', 'is', server['id']]], [region])
if not sg_server:
self._fw.log_error("No server was configured for this project! Enter the p4 server in the project field '{}'".format(server_field))
return None
return str(sg_server.get(region))
def sync_with_dialog(app, entities_to_sync, specific_files=False, child_asset_ids=None):
"""
Show the Perforce sync dialog
:returns Qt UI: A new Perforce sync dialog
"""
fw = sgtk.platform.current_bundle()
return SyncHandler(fw).sync_with_dlg(app, entities_to_sync, specific_files=specific_files, child_asset_ids=child_asset_ids)