Advertisement
ylSiew

localLocation

May 14th, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. import logging
  2. import sys
  3. import os
  4. import socket
  5.  
  6. from ftrack import \
  7.     ensureLocation, Location, DiskAccessor
  8.  
  9.  
  10. logger = logging.getLogger(__name__)
  11.  
  12. # Get Frostburn-specific structure
  13. try:
  14.     from stkToolkit_3dsmax.ftrackPlugin.event.structure.frostburnProjectStructure \
  15.         import FrostburnProjectStructure
  16. except ImportError:
  17.     logger.warning('# Unable to perform absolute import, continuing...')
  18.  
  19.     structurePath = os.path.join(
  20.         os.path.dirname(
  21.             os.path.dirname(
  22.                 os.path.abspath(__file__))), 'structure')
  23.  
  24.     sys.path.append(structurePath)
  25.  
  26.     # noinspection PyUnresolvedReferences
  27.     from frostburnProjectStructure import FrostburnProjectStructure
  28.  
  29.  
  30. def register(registry, **kw):
  31.     """
  32.    This method registers the Location in the ftrack database.
  33.    It is automatically called when this module is found in the
  34.    ``FTRACK_LOCATION_PLUGIN_PATH``.
  35.    :param registry:
  36.    :param kw:
  37.    :return:
  38.    """
  39.  
  40.     # Check if location environment variable has been set,
  41.     # if not, download to temporary directory
  42.     locationDownloadsPath = os.environ.get('FTRACK_LOCAL_LOCATION_DIR',
  43.                                            'C:\\ftrackDownloads\\')
  44.  
  45.     # Create an identifier for this particular location
  46.     # validate the machine's domain name
  47.     machineName = socket.getfqdn()
  48.  
  49.     if '.frostburnstudios.com'in machineName:
  50.  
  51.         userName = os.environ.get('USER')
  52.  
  53.         userName = userName.replace('.', '-')
  54.  
  55.         """Register custom location."""
  56.         locationName = 'local.location.{0}.{1}'.format(userName, machineName)
  57.  
  58.         # Ensure location is registered in the database.
  59.         ensureLocation(locationName)
  60.  
  61.         # Create the new location plugin.
  62.         location = Location(
  63.             locationName,
  64.  
  65.             # Use Frostburn Studios-specific project structure
  66.             structure=FrostburnProjectStructure(),
  67.  
  68.             # The location will be a local disk.
  69.             accessor=DiskAccessor(prefix=locationDownloadsPath),
  70.  
  71.             # Set priority to below S3 Location
  72.             priority=10
  73.         )
  74.  
  75.         # Register the location plugin.
  76.         registry.add(location)
  77.  
  78.         logger.debug('Location plugin registered: {0}'.format(os.path.abspath(__file__)))
  79.  
  80.     else:
  81.         logger.warning('# Did not register local Location plugin since machine name is invalid!')
  82.         return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement