Advertisement
ylSiew

localLocation

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