Пример #1
0
def __cast_entities( value, cur ):
    if value is None:
        return None
    if value == "" or value == '{}':
        return []

    # Convert from (f1, f2) syntax using a regular expression.
    value = value[1:len( value ) - 1]
    regexp = r"^(\"\(([^,)]+),([^,)]+),([^,)]+)\)\",?)"
    m = re.match( regexp, value )
    if m:
        ret = []
        while m:
            found = m.groups()[1:]
            ret.append( PostgresEntityType( str( found[0] ),
                                          int( found[1] ),
                                          int( found[2] ) ) )
            value = value[len( m.group( 0 ) ):]
            m = re.match( regexp, value )

        return ret
    else:
        debug.error( type( value ) )
        debug.error( value )
        raise InterfaceError( "bad entity representation: %r" % value )
Пример #2
0
    def connectAndRun(self, onlyEventIDs=None):
        self.syncomaniaSettings.load()
        if self.syncomaniaSettings.get(
                sync_settings.FIELD_CURRENT_SYNCDAEMON_ID) != self.mycode:
            debug.error("another daemon seems to have started running")
            return OTHER_SYNCDAMEON_RUNNING

        # while testing sync daemon goes into sleep mode
        if self.syncomaniaSettings.get(sync_settings.FIELD_SYNC_SLEEP
                                       ) == sync_settings.FIELD_SYNC_SLEEP_YES:
            return SYNC_DAEMON_SHOULD_SLEEP

        state_Shotgun_to_Local = self.shotgun_to_local_spooler.connectAndRun()
        if not state_Shotgun_to_Local:
            debug.debug("something not OK syncing Shotgun to Local",
                        debug.ERROR)

        state_Local_to_Shotgun = self.local_to_shotgun_spooler.connectAndRun(
            onlyEventIDs=onlyEventIDs)
        if not state_Local_to_Shotgun:
            debug.debug("something not OK syncing Local to Shotgun",
                        debug.ERROR)

        if not state_Shotgun_to_Local or not state_Local_to_Shotgun:
            return SYNCED_NOT_OK
        else:
            return SYNCED_OK
Пример #3
0
def __cast_entities(value, cur):
    if value is None:
        return None
    if value == "" or value == '{}':
        return []

    # Convert from (f1, f2) syntax using a regular expression.
    value = value[1:len(value) - 1]
    regexp = r"^(\"\(([^,)]+),([^,)]+),([^,)]+)\)\",?)"
    m = re.match(regexp, value)
    if m:
        ret = []
        while m:
            found = m.groups()[1:]
            ret.append(
                PostgresEntityType(str(found[0]), int(found[1]),
                                   int(found[2])))
            value = value[len(m.group(0)):]
            m = re.match(regexp, value)

        return ret
    else:
        debug.error(type(value))
        debug.error(value)
        raise InterfaceError("bad entity representation: %r" % value)
 def _connect( self ):
     """ establish the connections
     
     establish a connection to local server and shotgun
     """
     try:
         self.src = connectors.DatabaseModificator()
     except Exception, error: #IGNORE:W0703
         debug.error( "Unable to _connect to database server. " + unicode( error ) )
         return False
Пример #5
0
 def _connect(self):
     """ establish the connections
     
     establish a connection to local server and shotgun
     """
     try:
         self.src = connectors.DatabaseModificator()
     except Exception, error:  #IGNORE:W0703
         debug.error("Unable to _connect to database server. " +
                     unicode(error))
         return False
Пример #6
0
class LocalDBEventSpooler(object):
    """ Continuously spools events from couchdb and transfers them to shotgun """

    src = None  # local database connector
    cur = None
    sg = None

    def _connect(self):
        """ establish the connections
        
        establish a connection to local server and shotgun
        """
        try:
            self.src = connectors.DatabaseModificator()
        except Exception, error:  #IGNORE:W0703
            debug.error("Unable to _connect to database server. " +
                        unicode(error))
            return False

        try:
            self.sg = shotgun_api3.Shotgun(config.SHOTGUN_URL,
                                           config.SHOTGUN_SYNC_SKRIPT,
                                           config.SHOTGUN_SYNC_KEY)
        except Exception, error:  #IGNORE:W0703
            debug.error("Unable to _connect to Shotgun server. " +
                        unicode(error))
            return False
def main():
    """
    to be called
    """
    sg_url = "https://devilfant.shotgunstudio.com"
    sg_test1 = {"name": "test1",
                "key": "e398654c5ec1c6f7c8f71ead33349c58bbf4a058"}

    sg1 = Shotgun( sg_url,
                  sg_test1["name"],
                  sg_test1["key"] )


    entities = sg1.schema_entity_read()

    pprint( entities )

    moduleString = """# -*- coding: utf-8 -*-

\"""@package shotgun_replica.entities
Shotgun Entities

THIS FILE IS AUTO GENERATED

DO NOT EDIT IT DIRECTLY
change create_shotgun_classes.py instead 
\"""

from shotgun_replica._entity_mgmt import _ShotgunEntity
from shotgun_replica import %s

""" % FIELDDEFINITIONSMODULE

    fieldDefModuleString = """# -*- coding: utf-8 -*-

\""" 
THIS FILE IS AUTO GENERATED

DO NOT EDIT IT DIRECTLY
change create_shotgun_classes.py instead 
\"""

"""

    classes = entities.keys()
    classes.sort()

    for entitycode in classes:

        print "processing %s\n" % entitycode
        fieldDefs = sg1.schema_field_read( entitycode )

        try:
            theclass = connectors.getClassOfType( entitycode )
            localFieldDefs = theclass.shotgun_fields
        except ImportError:
            localFieldDefs = None
        except AttributeError:
            localFieldDefs = None

        if fieldDefs != localFieldDefs:
            debug.error( "%s fielddefs differ from shotgun to local" % entitycode )

        entityname = cleanSysName( entities[entitycode]["name"]["value"] )
        if entitycode.endswith( "Connection" ):
            entityname = entitycode

        ( classCode, fieldDefCode ) = _createClassCode( entities, entitycode, fieldDefs, entityname )
        moduleString += classCode
        fieldDefModuleString += fieldDefCode

        _createDBFields( entitycode, fieldDefs, entityname )

    packageDir = os.path.dirname( __file__ )
    entityFilename = os.path.join( packageDir,
                                   'entities.py' )
    entity_file = open( entityFilename, 'w' )
    entity_file.write( moduleString )
    entity_file.close()

    fieldDefFilename = os.path.join( packageDir,
                                   '%s.py' % FIELDDEFINITIONSMODULE )
    fieldDef_file = open( fieldDefFilename, 'w' )
    fieldDef_file.write( fieldDefModuleString )
    fieldDef_file.close()
Пример #8
0
def main():
    """
    to be called
    """
    sg_url = "https://devilfant.shotgunstudio.com"
    sg_test1 = {
        "name": "test1",
        "key": "e398654c5ec1c6f7c8f71ead33349c58bbf4a058"
    }

    sg1 = Shotgun(sg_url, sg_test1["name"], sg_test1["key"])

    entities = sg1.schema_entity_read()

    pprint(entities)

    moduleString = """# -*- coding: utf-8 -*-

\"""@package shotgun_replica.entities
Shotgun Entities

THIS FILE IS AUTO GENERATED

DO NOT EDIT IT DIRECTLY
change create_shotgun_classes.py instead 
\"""

from shotgun_replica._entity_mgmt import _ShotgunEntity
from shotgun_replica import %s

""" % FIELDDEFINITIONSMODULE

    fieldDefModuleString = """# -*- coding: utf-8 -*-

\""" 
THIS FILE IS AUTO GENERATED

DO NOT EDIT IT DIRECTLY
change create_shotgun_classes.py instead 
\"""

"""

    classes = entities.keys()
    classes.sort()

    for entitycode in classes:

        print "processing %s\n" % entitycode
        fieldDefs = sg1.schema_field_read(entitycode)

        try:
            theclass = connectors.getClassOfType(entitycode)
            localFieldDefs = theclass.shotgun_fields
        except ImportError:
            localFieldDefs = None
        except AttributeError:
            localFieldDefs = None

        if fieldDefs != localFieldDefs:
            debug.error("%s fielddefs differ from shotgun to local" %
                        entitycode)

        entityname = cleanSysName(entities[entitycode]["name"]["value"])
        if entitycode.endswith("Connection"):
            entityname = entitycode

        (classCode, fieldDefCode) = _createClassCode(entities, entitycode,
                                                     fieldDefs, entityname)
        moduleString += classCode
        fieldDefModuleString += fieldDefCode

        _createDBFields(entitycode, fieldDefs, entityname)

    packageDir = os.path.dirname(__file__)
    entityFilename = os.path.join(packageDir, 'entities.py')
    entity_file = open(entityFilename, 'w')
    entity_file.write(moduleString)
    entity_file.close()

    fieldDefFilename = os.path.join(packageDir,
                                    '%s.py' % FIELDDEFINITIONSMODULE)
    fieldDef_file = open(fieldDefFilename, 'w')
    fieldDef_file.write(fieldDefModuleString)
    fieldDef_file.close()