forked from assumptionsoup/guppy_animation_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
197 lines (149 loc) · 5.34 KB
/
__init__.py
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
'''Guppy Animation Tools is a collection of tools to help animators
*******************************************************************************
License and Copyright
Copyright 2012-2014 Jordan Hueckstaedt
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************
'''
import os
import sys
import pymel.internal.plogging as plogging
__license__ = 'LGPL v3'
__version__ = "0.3"
# Include the scripts folder in this package. Which allows for:
# import guppy_animation_tools.cleverKeys
# As well as the less intuitive:
# import guppy_animation_tools.scripts.cleverKeys
# This allows us to use guppy_animation_tools as both a complete
# development package (including plugin, scripts, and icons), and allow
# non-technical users to drop the package into an existing folder on the
# PYTHONPATH (e.g. the maya scripts dir)
REPO_DIR = os.path.dirname(os.path.realpath(__file__))
_SCRIPTS_DIR = os.path.join(REPO_DIR, 'scripts')
__path__.append(_SCRIPTS_DIR)
__all__ = [
'arcTracer',
'cleverKeys',
'lock_n_hide',
'moveMyObjects',
'pickleAttr',
'pointOnMesh',
'selectedAttributes',
'slideAnimationKeys',
'zeroSelection',
'renameIt']
_logRegister = {}
class LogManager(object):
'''
Manager to help toggle states on loggers
'''
def __init__(self, logger, name):
self.logger = logger
self.name = name
self._previousLevel = None
def isDebugging(self):
return self.logger.level == plogging.DEBUG
def setLevel(self, level):
self._previousLevel = self.logger.level
self.logger.setLevel(level)
def restoreLevel(self):
if self._previousLevel is not None:
self.logger.setLevel(self._previousLevel)
self._previousLevel = None
def toggleDebug(self):
if self.isDebugging():
self.restoreLevel()
else:
self.setLevel(plogging.DEBUG)
@classmethod
def create(cls, name):
logger = plogging.getLogger(name)
logger = plogging.getLogger(name)
logger.setLevel(logger.INFO)
return cls(logger, name)
def getLogger(name):
if 'guppy_animation_tools' in name:
name = name.replace('guppy_animation_tools', 'gat', 1)
if name not in _logRegister:
_logRegister[name] = LogManager.create(name)
return _logRegister[name].logger
def setLoggerLevels(level, namespaces=None):
if namespaces is None:
namespaces = _logRegister.keys()
for name in namespaces:
_logRegister[name].setLevel(level)
def restoreLoggerLevels(namespaces=None):
global _logLevels
if namespaces is None:
namespaces = _logRegister.keys()
for name in namespaces:
_logRegister[name].restoreLevel()
_logLevels = {}
def toggleDebug(namespaces=None):
if namespaces is None:
namespaces = _logRegister.keys()
for name in namespaces:
_logRegister[name].toggleDebug()
logger = getLogger('guppy_animation_tools')
def reportVersion():
'''Print out commit hash and semantic version'''
import re
commit = '????'
try:
directory = os.path.dirname(__file__)
with open(os.path.join(directory, 'version_info'), 'r') as fs:
match = re.match('\$Id: (.*) \$', fs.read())
if match and match.groups():
commit = match.groups()[0]
except IOError:
pass
logger.info("\nVersion: %s\nCommit: %s",
__version__, commit)
def _addToPath(env, newLocation):
'''
Add path to os.environ[env]
'''
if not newLocation.endswith(os.path.sep):
newLocation += os.path.sep
if newLocation not in os.environ[env].split(os.pathsep):
if os.environ[env]:
os.environ[env] += os.pathsep
os.environ[env] += newLocation
def _addPluginPath(pluginLocation):
'''
Add plugin path to Maya.
'''
_addToPath('MAYA_PLUG_IN_PATH', pluginLocation)
def _addScriptPath(scriptLocation):
'''
Add mel script path to Maya.
'''
_addToPath('MAYA_SCRIPT_PATH', scriptLocation)
def _addPythonPath(scriptLocation):
'''
Add python script path to Maya.
'''
# Adding to python path just adds the parent dir for some reason
# (Guppy-Animation-Tools).
# _addToPath('PYTHONPATH', scriptLocation)
if scriptLocation not in sys.path:
sys.path.append(scriptLocation)
def _addIconPath(iconLocation):
'''
Add icon path to Maya.
'''
_addToPath('XBMLANGPATH', iconLocation)
# Add necessary folders to the PYTHONPATH
_pluginPath = os.path.join(REPO_DIR, 'plugins')
_addPluginPath(os.path.join(_pluginPath, 'python'))
_addScriptPath(os.path.join(REPO_DIR, 'AETemplates'))
_addIconPath(os.path.join(REPO_DIR, 'icons'))