Beispiel #1
0
def propagate(collectionid,field,current_value):
    from gnmvidispine.vs_collection import VSCollection, VSItem
    import traceback
    #from pprint import pprint
    try:
        import raven
        from django.conf import settings
        raven_client = raven.Client(settings.RAVEN_CONFIG['dsn'])

    except StandardError as e:
        logger.error("Raven client either not installed (pip install raven) or set up (RAVEN_CONFIG in localsettings.py).  Unable to report errors to Sentry")
        raven_client = None

    from django.conf import settings

    collection_obj = VSCollection(url=settings.VIDISPINE_URL,port=settings.VIDISPINE_PORT,user=settings.VIDISPINE_USERNAME,passwd=settings.VIDISPINE_PASSWORD)
    collection_obj.populate(collectionid, specificFields=['title','gnm_asset_category'])

    n=0
    for subitem in collection_obj.content(shouldPopulate=False):
        logger.debug("propagating value from parent {0} to child {1} ({2})".format(collectionid,subitem.name,subitem.__class__))

        subitem.populate(subitem.name, specificFields=['title','gnm_asset_category','gnm_type','__collection_size',field])
        logger.debug(u"title: {0}, category: {1}, type: {2}".format(subitem.get('title'),subitem.get('gnm_asset_category'),
                                                                    subitem.get('gnm_type')))
        type = '(unknown)'
        if isinstance(subitem,VSItem):
            type = "item"
            try:
                if int(subitem.get('__collection_size')) > 1:
                    logger.warning("Item {0} in collection {1} is linked {2} times, so not flagging".format(
                        subitem.name,
                        collectionid,
                        subitem.get('__collection_size')
                    ))
                    continue
            except TypeError:
                #this means that __collection_size was None or an invalid value
                logger.warning("{0} {1} had no __collection_size".format(type,subitem.name))
            except StandardError as e:
                logger.error(e)
                if raven_client is not None: raven_client.captureException()
                raise
        elif isinstance(subitem,VSCollection):
            type = "collection"

        if subitem.get(field) != current_value:
            try:
                subitem.set_metadata({field: current_value})
            except StandardError as e:
                if raven_client is not None: raven_client.captureException()
                raise

        logger.info("value set on {0} {1}".format(type, subitem.name))
        n+=1

    logger.info("Propagation run completed for {0}.  Affected {1} items".format(collectionid, n))
 def reattach(self, itemid, collectionid):
     coll = VSCollection(host=self.config.value('vs_host'), port=self.config.value('vs_port'),
                         user=self.config.value('vs_user'), passwd=self.config.value('vs_password'))
     coll.name = collectionid
     coll.addToCollection(itemid, type="item")
     self.logger.info("Attached item {0} to {1}".format(itemid, collectionid))
     
     self.logger.info("Updating management metadata for {0}".format(itemid))
     completed = False
     held = False
     deletable = False
     sensitive = False
     deep_archive = False
     
     if coll.get('gnm_project_status') == 'Completed':
         completed = True
     elif coll.get('gnm_project_status') == 'Held':
         held = True
     if coll.get('gnm_storage_rule_deletable') == 'storage_rule_deletable':
         deletable = True
     if coll.get('gnm_storage_rule_sensitive') == 'storage_rule_sensitive':
         sensitive = True
     if coll.get('gnm_storage_ruke_deep_archive') == 'storage_rule_deep_archive':
         deep_archive = True
         
     item = VSItem(host=self.options.vshost, port=self.options.vsport, user=self.options.vsuser, passwd=self.options.vspass)
     item.name = itemid
     item.set_metadata({
         'gnm_storage_rule_projects_completed': ['storage_rule_projects_completed' if completed else ''],
         'gnm_storage_rule_projects_held'     : ['storage_rule_projects_held' if held else ''],
         'gnm_storage_rule_deletable'         : ['storage_rule_deletable' if deletable else ''],
         'gnm_storage_rule_sensitive'         : ['storage_rule_sensitive' if sensitive else ''],
         'gnm_storage_rule_deep_archive'      : ['storage_rule_deep_archive' if deep_archive else '']
     })
     self.logger.info("Updated metadata for item {0}".format(item.name))
Beispiel #3
0
    def reattach(self, itemid, collectionid):
        coll = VSCollection(host=self.config.value('vs_host'),
                            port=self.config.value('vs_port'),
                            user=self.config.value('vs_user'),
                            passwd=self.config.value('vs_password'))
        coll.name = collectionid
        coll.addToCollection(itemid, type="item")
        self.logger.info("Attached item {0} to {1}".format(
            itemid, collectionid))

        self.logger.info("Updating management metadata for {0}".format(itemid))
        completed = False
        held = False
        deletable = False
        sensitive = False
        deep_archive = False

        if coll.get('gnm_project_status') == 'Completed':
            completed = True
        elif coll.get('gnm_project_status') == 'Held':
            held = True
        if coll.get('gnm_storage_rule_deletable') == 'storage_rule_deletable':
            deletable = True
        if coll.get('gnm_storage_rule_sensitive') == 'storage_rule_sensitive':
            sensitive = True
        if coll.get('gnm_storage_ruke_deep_archive'
                    ) == 'storage_rule_deep_archive':
            deep_archive = True

        item = VSItem(host=self.options.vshost,
                      port=self.options.vsport,
                      user=self.options.vsuser,
                      passwd=self.options.vspass)
        item.name = itemid
        item.set_metadata({
            'gnm_storage_rule_projects_completed':
            ['storage_rule_projects_completed' if completed else ''],
            'gnm_storage_rule_projects_held':
            ['storage_rule_projects_held' if held else ''],
            'gnm_storage_rule_deletable':
            ['storage_rule_deletable' if deletable else ''],
            'gnm_storage_rule_sensitive':
            ['storage_rule_sensitive' if sensitive else ''],
            'gnm_storage_rule_deep_archive':
            ['storage_rule_deep_archive' if deep_archive else '']
        })
        self.logger.info("Updated metadata for item {0}".format(item.name))
Beispiel #4
0
    def test_get_metadata_attributes(self):
        fake_data = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MetadataDocument xmlns="http://xml.vidispine.com/schema/vidispine">
    <revision>KP-19029938,KP-19008430,KP-19008428,KP-19008429</revision>
    <timespan start="-INF" end="+INF">
        <field uuid="6062c7ee-b4fe-4bbb-b61e-5d3debb05713" user="******" timestamp="2017-06-02T17:46:59.926+01:00" change="KP-19029938">
            <name>gnm_commission_status</name>
            <value uuid="d44f4268-f7af-46aa-884f-905855026c74" user="******" timestamp="2017-06-02T17:46:59.926+01:00" change="KP-19029938">Completed</value>
        </field>
        <field uuid="9860f876-b9e8-4799-8e68-cb292818a9cd" user="******" timestamp="2017-06-02T11:26:41.478+01:00" change="KP-19008429">
            <name>gnm_commission_owner</name>
            <value uuid="19e2cfdd-dd4c-4dc6-b910-6ce55b0c9c93" user="******" timestamp="2017-06-02T11:26:41.478+01:00" change="KP-19008429">11</value>
            <value uuid="EF41268C-00B4-431D-A36E-6D3B4D59A06A" user="******" timestamp="2017-06-02T11:26:44.478+01:00" change="KP-19008430">14</value>
        </field>
    </timespan>
</MetadataDocument>"""

        from gnmvidispine.vs_collection import VSCollection
        i = VSCollection(host=self.fake_host, port=self.fake_port, user=self.fake_user, passwd=self.fake_passwd)
        i.collectionId="VX-1234"
        i.fromXML(fake_data, objectClass="collection")

        result = i.get_metadata_attributes("gnm_commission_status")
        self.assertEqual(result[0].uuid,"6062c7ee-b4fe-4bbb-b61e-5d3debb05713")
        self.assertEqual(str(result[0].values),'[VSMetadataValue("Completed")]')

        result2 = i.get_metadata_attributes("gnm_commission_owner")
        self.assertEqual(str(result2[0].values),'[VSMetadataValue("11"), VSMetadataValue("14")]')

        result3 = i.get_metadata_attributes("invalidfieldname")
        self.assertEqual(result3, None)
Beispiel #5
0
 def get_collection_for_id(self, projectid, expected_type="Project"):
     """
     Returns a VSCollection for the given project ID. Raises VSNotFound if the collection does not exist, or
     exceptions.NotAProject if it is not a project.
     :return:
     """
     collection = VSCollection(url=settings.VIDISPINE_URL,user=settings.VIDISPINE_USERNAME,passwd=settings.VIDISPINE_PASSWORD)
     collection.populate(projectid)
     if collection.get('gnm_type')!=expected_type:
         raise NotAProjectError("{0} is a {1}".format(projectid, collection.get('gnm_type')))
     return collection
Beispiel #6
0
    def attempt_add_to_project(self, filepath, preludeproject, cubaseref,
                               vsfile):
        VSprojectRef = VSCollection(host=self.cfg.value('vs_host'),
                                    port=self.cfg.value('vs_port'),
                                    user=self.cfg.value('vs_user'),
                                    passwd=self.cfg.value('vs_password'))
        if preludeproject:
            #if the item is attached to a prelude project that will immediately give us the project ID to attach to
            projectId = re.sub(u'\.[^\.]+$', '', preludeproject['filename'])
            # VSprojectRef.populate(projectId)
            VSprojectRef.name = projectId

            VSprojectRef.addToCollection(vsfile.memberOfItem, type="item")
            return True
        elif cubaseref:
            #if it's got a Cubase reference we can get the project ID from there
            try:
                VSprojectRef.populate(cubaseref['project_id'])
                VSprojectRef.addToCollection(vsfile.memberOfItem, type="item")
                return True
            except Exception as e:
                self.db.insert_sysparam(
                    "warning", "Unable to add %s to collection %s: %s" %
                    (vsfile.memberOfItem, cubaseref['project_id'], e.message))
                self.logger.warning("Warning: %s" % e.message)
                self.db.commit()
        else:
            #otherwise, ask Pluto's gnm_asset_folder plugin to look up the file path for us
            projectId = self.ask_pluto_for_projectid(filepath)
            if projectId is None:
                self.db.insert_sysparam(
                    "warning",
                    "Pluto has no record of asset folder for %s" % filepath)
                self.logger.warning(
                    "Pluto has no record of asset folder for %s" % filepath)
                self.db.commit()
            else:
                VSprojectRef.name = projectId
                VSprojectRef.addToCollection(vsfile.memberOfItem, type="item")
                return True
        return False
 def attempt_add_to_project(self, filepath, preludeproject, cubaseref, vsfile):
     VSprojectRef = VSCollection(host=self.cfg.value('vs_host'), port=self.cfg.value('vs_port'),
                                 user=self.cfg.value('vs_user'), passwd=self.cfg.value('vs_password'))
     if preludeproject:
         #if the item is attached to a prelude project that will immediately give us the project ID to attach to
         projectId = re.sub(u'\.[^\.]+$', '', preludeproject['filename'])
         # VSprojectRef.populate(projectId)
         VSprojectRef.name = projectId
     
         VSprojectRef.addToCollection(vsfile.memberOfItem, type="item")
         return True
     elif cubaseref:
         #if it's got a Cubase reference we can get the project ID from there
         try:
             VSprojectRef.populate(cubaseref['project_id'])
             VSprojectRef.addToCollection(vsfile.memberOfItem, type="item")
             return True
         except Exception as e:
             self.db.insert_sysparam("warning", "Unable to add %s to collection %s: %s" % (
                 vsfile.memberOfItem, cubaseref['project_id'], e.message))
             self.logger.warning("Warning: %s" % e.message)
             self.db.commit()
     else:
         #otherwise, ask Pluto's gnm_asset_folder plugin to look up the file path for us
         projectId = self.ask_pluto_for_projectid(filepath)
         if projectId is None:
             self.db.insert_sysparam("warning", "Pluto has no record of asset folder for %s" % filepath)
             self.logger.warning("Pluto has no record of asset folder for %s" % filepath)
             self.db.commit()
         else:
             VSprojectRef.name = projectId
             VSprojectRef.addToCollection(vsfile.memberOfItem, type="item")
             return True
     return False
Beispiel #8
0
    def post(self, request):
        from pprint import pformat
        from gnmvidispine.vidispine_api import VSException
        from gnmvidispine.vs_item import VSItem
        from gnmvidispine.vs_collection import VSCollection
        from gnmvidispine.vs_metadata import VSMetadata
        from django.conf import settings
        from portal.plugins.gnm_masters.models import VSMaster, MasterModel
        from portal.plugins.gnm_projects.models import VSProject
        from django.contrib.auth.models import User
        import re

        is_vsid = re.compile(r'^\w{2}-\d+')

        try:
            comm_id = request.POST['plutoconverter_commission_id_input']
            proj_id = request.POST['plutoconverter_project_id_input']
            item_id = request.POST['plutoconverter_item_id_input']
        except StandardError as e:
            return Response({'status': 'error', 'error': unicode(e)},status=400)

        if not is_vsid.match(comm_id) or not is_vsid.match(proj_id) or not is_vsid.match(item_id):
            return Response({'status': 'error', 'error': 'Not a valid Vidispine ID'},status=400)

        try:
            item = VSItem(user=settings.VIDISPINE_USERNAME, passwd=settings.VIDISPINE_PASSWORD, url=settings.VIDISPINE_URL)
            item.populate(item_id)

            if item.get('gnm_type') == 'master':
                return Response({'status': 'error', 'error': '{0} is already a master'.format(item_id)},status=400)

            project = VSCollection(user=settings.VIDISPINE_USERNAME, passwd=settings.VIDISPINE_PASSWORD, url=settings.VIDISPINE_URL)
            project.populate(proj_id)

            commission_id = project.get('__parent_collection')
            logger.info("Project {0} belongs to commission {1}".format(project.name, commission_id))

            commission = VSCollection(user=settings.VIDISPINE_USERNAME, passwd=settings.VIDISPINE_PASSWORD, url=settings.VIDISPINE_URL)
            commission.populate(commission_id)

            md_to_set = {
                'gnm_commission_title'         : commission.get('gnm_commission_title'),
                'gnm_commission_workinggroup'  : commission.get('gnm_commission_workinggroup'),
                'gnm_project_headline'         : project.get('gnm_project_headline'),
                'gnm_master_website_headline'  : item.get('title'),
                'gnm_master_website_standfirst': item.get('gnm_asset_description'),
                'gnm_master_website_byline'    : item.get('gnm_asset_owner'),
                # 'gnm_master_website_tags': breakout_tags(item.get('gnm_asset_user_keywords',allowArray=True),
                #                                         host=options.vshost,user=options.vsuser,passwd=options.vspasswd),
                'gnm_type'                     : 'Master',
                'gnm_master_language'          : settings.LANGUAGE_CODE[0:2],
            }

            logger.info("Going to add {0} to project {1}".format(item_id,md_to_set))
            project.addToCollection(item)
            logger.info("Going to set metadata on {0}: {1}".format(item_id, md_to_set))
            item.set_metadata(md_to_set)
            logger.info("SUCCESS: item {0} has been converted to master".format(item_id))

            admin_user = User.objects.get(username=settings.VIDISPINE_USERNAME)

            vs_project = VSProject(proj_id, admin_user)
            vs_master = VSMaster(item_id, admin_user)
            vs_project.add_master(vs_master)

            return Response({'status': 'success', 'itemid': item_id },status=200)
        except VSException as e:
            if raven_client is not None:
                raven_client.captureException()
            return Response({'status': 'error', 'error': "Vidispine said {0}".format(unicode(e))},status=500)
        except StandardError as e:
            if raven_client is not None:
                raven_client.captureException()
            return Response({'status': 'error', 'error': unicode(e)},status=500)
def process_premiere_project(filepath,
                             raven_client,
                             vs_pathmap=None,
                             db=None,
                             cfg=None):
    """
    Main function to process a Premiere project file
    :param filepath: file path to process
    :param db: asset importer database object
    :param cfg: asset importer configuration object
    :return:
    """
    lg.debug("---------------------------------")
    lg.info("Premiere project: %s" % filepath)

    collection_vsid = id_from_filepath(filepath)
    lg.info("Project's Vidispine ID: %s" % collection_vsid)
    vsproject = VSCollection(host=cfg.value('vs_host'),
                             port=cfg.value('vs_port'),
                             user=cfg.value('vs_user'),
                             passwd=cfg.value('vs_password'))
    vsproject.setName(
        collection_vsid
    )  #we don't need the actual metadata so don't bother getting it.

    pp = PremiereProject()
    try:
        pp.load(filepath)
    except Exception as e:
        lg.error("Unable to read '%s': %s" % (filepath, e.message))
        lg.error(traceback.format_exc())
        print "Unable to read '%s': %s" % (filepath, e.message)
        traceback.print_exc()
        raven_client.captureException()
        return (0, 0, 0)

    lg.debug("determining project details and updating database...")
    try:
        projectDetails = pp.getParticulars()

        project_id = db.upsert_edit_project(
            os.path.dirname(filepath),
            os.path.basename(filepath),
            projectDetails['uuid'],
            projectDetails['version'],
            desc="Adobe Premiere Project",
            opens_with=
            "/Applications/Adobe Premiere Pro CC 2014/Adobe Premiere Pro CC 2014.app/Contents/MacOS/Adobe Premiere Pro CC 2014"
        )
    except ValueError as e:
        project_id = db.log_project_issue(os.path.dirname(filepath),
                                          os.path.basename(filepath),
                                          problem="Invalid project file",
                                          detail="{0}: {1} {2}".format(
                                              e.__class__, str(e),
                                              traceback.format_exc()))
        lg.error("Unable to read project file '{0}' - {1}".format(
            filepath, str(e)))
        lg.error(traceback.format_exc())
        raven_client.captureException()
        return (0, 0, 0)
    except KeyError as e:
        project_id = db.log_project_issue(os.path.dirname(filepath),
                                          os.path.basename(filepath),
                                          problem="Invalid project file",
                                          detail="{0}: {1} {2}".format(
                                              e.__class__, str(e),
                                              traceback.format_exc()))
        db.insert_sysparam(
            "warning",
            "Unable to read project file '{0}' - {1}".format(filepath, str(e)))
        lg.error("Unable to read project file '{0}' - {1}".format(
            filepath, str(e)))
        lg.error(traceback.format_exc())
        raven_client.captureException()
        return (0, 0, 0)

    except InvalidDataError as e:
        db.insert_sysparam(
            "warning",
            "Corrupted project file: {0} {1}".format(filepath, unicode(e)))
        raven_client.captureException()
        return (0, 0, 0)

    total_files = 0
    no_vsitem = 0
    not_in_db = 0

    lg.debug("looking for referenced media....")
    for filepath in pp.getReferencedMedia():
        total_files += 1
        try:
            lg.debug("Looking up {0}".format(filepath))
        except UnicodeEncodeError:
            lg.debug("Looking up {0}".format(filepath.encode('utf-8')))
        try:
            server_path = re.sub(u'^/Volumes', '/srv',
                                 filepath).encode('utf-8')
        except UnicodeDecodeError:
            server_path = re.sub(u'^/Volumes', '/srv',
                                 filepath.decode('utf-8'))
        try:
            item = process_premiere_fileref(filepath,
                                            server_path,
                                            project_id,
                                            vs_pathmap=vs_pathmap,
                                            db=db,
                                            cfg=cfg)
            #using this construct to avoid loading more data from VS than necessary.  We simply check whether the ID exists
            #in the parent collections list (cached on the item record) without lifting any more info out of VS
            if vsproject.name in map(
                    lambda x: x.name,
                    item.parent_collections(shouldPopulate=False)):
                lg.info("File %s is already in project %s" %
                        (filepath, vsproject.name))
                continue

            vsproject.addToCollection(
                item=item
            )  #this call will apparently succeed if the item is already added to said collection, but it won't be added twice.
        except VSNotFound:
            try:
                lg.error(
                    "File {0} could not be found in either Vidispine or the asset importer database"
                    .format(server_path))
            except UnicodeEncodeError:
                lg.error(
                    "File {0} could not be found in either Vidispine or the asset importer database"
                    .format(server_path.encode('utf-8')))
            if "Internet Downloads" in filepath:
                #note - this could raise a 400 exception IF there is a conflict with something else trying to add info to the same field
                vsproject.set_metadata(
                    {'gnm_project_invalid_media_paths': filepath}, mode="add")
            continue
        except NotInDatabaseError:
            not_in_db += 1
            try:
                lg.warning("File %s could not be found in the database" %
                           filepath)
            except UnicodeEncodeError:
                lg.warning("File %s could not be found in the database" %
                           filepath.encode('utf-8'))
            continue
        except AlreadyLinkedError as e:
            try:
                lg.info("File %s with id %s is already linked to project %s" %
                        (filepath, e.fileid, e.vsprojectid))
            except UnicodeEncodeError:
                lg.info("File %s with id %s is already linked to project %s" %
                        (filepath.encode('utf-8'), e.fileid, e.vsprojectid))
            continue

    lg.info(
        "Run complete. Out of a total of %d referenced files, %d did not have a Vidispine item and %d were not in the Asset Importer database"
        % (total_files, no_vsitem, not_in_db))
    return (total_files, no_vsitem, not_in_db)
Beispiel #10
0
def process_premiere_project(filepath, raven_client, vs_pathmap=None, db=None, cfg=None):
    """
    Main function to process a Premiere project file
    :param filepath: file path to process
    :param db: asset importer database object
    :param cfg: asset importer configuration object
    :return:
    """
    lg.debug("---------------------------------")
    lg.info("Premiere project: %s" % filepath)

    collection_vsid = id_from_filepath(filepath)
    lg.info("Project's Vidispine ID: %s" % collection_vsid)
    vsproject = VSCollection(host=cfg.value('vs_host'), port=cfg.value('vs_port'), user=cfg.value('vs_user'),
                             passwd=cfg.value('vs_password'))
    vsproject.populate(collection_vsid)

    pp = PremiereProject()
    try:
        pp.load(filepath)
    except Exception as e:
        lg.error("Unable to read '%s': %s" % (filepath,e.message))
        lg.error(traceback.format_exc())
        print "Unable to read '%s': %s" % (filepath,e.message)
        traceback.print_exc()
        raven_client.captureException()
        return (0,0,0)

    lg.debug("determining project details and updating database...")
    try:
        projectDetails = pp.getParticulars()

        project_id = db.upsert_edit_project(os.path.dirname(filepath), os.path.basename(filepath),
                                            projectDetails['uuid'], projectDetails['version'],
                                            desc="Adobe Premiere Project",
                                            opens_with="/Applications/Adobe Premiere Pro CC 2014/Adobe Premiere Pro CC 2014.app/Contents/MacOS/Adobe Premiere Pro CC 2014")
    except ValueError as e:
        project_id = db.log_project_issue(os.path.dirname(filepath), os.path.basename(filepath), problem="Invalid project file", detail="{0}: {1} {2}".format(e.__class__,str(e),traceback.format_exc()))
        lg.error("Unable to read project file '{0}' - {1}".format(filepath,str(e)))
        lg.error(traceback.format_exc())
        raven_client.captureException()
        return (0,0,0)
    except KeyError as e:
        project_id = db.log_project_issue(os.path.dirname(filepath), os.path.basename(filepath), problem="Invalid project file", detail="{0}: {1} {2}".format(e.__class__,str(e),traceback.format_exc()))
        db.insert_sysparam("warning","Unable to read project file '{0}' - {1}".format(filepath, str(e)))
        lg.error("Unable to read project file '{0}' - {1}".format(filepath,str(e)))
        lg.error(traceback.format_exc())
        raven_client.captureException()
        return (0,0,0)

    except InvalidDataError as e:
        db.insert_sysparam("warning","Corrupted project file: {0} {1}".format(filepath,unicode(e)))
        raven_client.captureException()
        return (0,0,0)

    total_files = 0
    no_vsitem = 0
    not_in_db = 0
    invalid_media_paths = []

    lg.debug("looking for referenced media....")
    for filepath in pp.getReferencedMedia():
        total_files += 1
        try:
            lg.debug("Looking up {0}".format(filepath))
        except UnicodeEncodeError:
            lg.debug("Looking up {0}".format(filepath.encode('utf-8')))
        try:
            server_path = re.sub(u'^/Volumes', '/srv', filepath).encode('utf-8')
        except UnicodeDecodeError:
            server_path = re.sub(u'^/Volumes', '/srv', filepath.decode('utf-8'))
        try:
            item=process_premiere_fileref(filepath, server_path, project_id, vs_pathmap=vs_pathmap, db=db, cfg=cfg)
            #using this construct to avoid loading more data from VS than necessary.  We simply check whether the ID exists
            #in the parent collections list (cached on the item record) without lifting any more info out of VS
            if vsproject.name in map(lambda x: x.name,item.parent_collections(shouldPopulate=False)):
                lg.info("File %s is already in project %s" % (filepath,vsproject.name))
                continue

            vsproject.addToCollection(item=item)    #this call will apparently succeed if the item is already added to said collection, but it won't be added twice.
        except VSNotFound:
            try:
                lg.error("File {0} could not be found in either Vidispine or the asset importer database".format(server_path))
            except UnicodeEncodeError:
                lg.error("File {0} could not be found in either Vidispine or the asset importer database".format(server_path.encode('utf-8')))

            invalid_path_data = ['Internet Downloads', 'Editorial Users']

            if cfg.value('invalid_path_strings'):
                invalid_path_data = cfg.value('invalid_path_strings').split(',')

            if any(x in filepath for x in invalid_path_data):
                filepath_doctored = filepath.replace(',', '')
                #note - this could raise a 400 exception IF there is a conflict with something else trying to add info to the same field
                invalid_media_paths.append(filepath_doctored)
            continue
        except NotInDatabaseError:
            not_in_db += 1
            try:
                lg.warning("File %s could not be found in the database" % filepath)
            except UnicodeEncodeError:
                lg.warning("File %s could not be found in the database" % filepath.encode('utf-8'))
            continue
        except AlreadyLinkedError as e:
            try:
                lg.info("File %s with id %s is already linked to project %s" % (filepath, e.fileid, e.vsprojectid))
            except UnicodeEncodeError:
                lg.info("File %s with id %s is already linked to project %s" % (filepath.encode('utf-8'), e.fileid, e.vsprojectid))
            continue

    update_invalid_media_paths(vsproject, invalid_media_paths)

    lg.info(
        "Run complete. Out of a total of %d referenced files, %d did not have a Vidispine item and %d were not in the Asset Importer database" % (
            total_files, no_vsitem, not_in_db))
    return (total_files, no_vsitem, not_in_db)
Beispiel #11
0
def process_premiere_project(filepath, db=None, cfg=None):
    global vs_pathmap
    lg.debug("---------------------------------")
    lg.info("Premiere project: %s" % filepath)

    collection_vsid = id_from_filepath(filepath)
    lg.info("Project's Vidispine ID: %s" % collection_vsid)
    vsproject = VSCollection(host=cfg.value('vs_host'),
                             port=cfg.value('vs_port'),
                             user=cfg.value('vs_user'),
                             passwd=cfg.value('vs_password'))
    vsproject.setName(
        collection_vsid
    )  #we don't need the actual metadata so don't bother getting it.

    #pprint(vs_pathmap)

    pp = PremiereProject()
    try:
        pp.load(filepath)
    except Exception as e:
        lg.error("Unable to read '%s': %s" % (filepath, e.message))
        lg.error(traceback.format_exc())
        print "Unable to read '%s': %s" % (filepath, e.message)
        traceback.print_exc()
        raven_client.captureException()
        return (0, 0, 0)

    lg.debug("determining project details and updating database...")
    try:
        projectDetails = pp.getParticulars()

        project_id = db.upsert_edit_project(
            os.path.dirname(filepath),
            os.path.basename(filepath),
            projectDetails['uuid'],
            projectDetails['version'],
            desc="Adobe Premiere Project",
            opens_with=
            "/Applications/Adobe Premiere Pro CC 2014/Adobe Premiere Pro CC 2014.app/Contents/MacOS/Adobe Premiere Pro CC 2014"
        )
    except ValueError as e:
        project_id = db.log_project_issue(os.path.dirname(filepath),
                                          os.path.basename(filepath),
                                          problem="Invalid project file",
                                          detail="{0}: {1} {2}".format(
                                              e.__class__, str(e),
                                              traceback.format_exc()))
        lg.error("Unable to read project file '{0}' - {1}".format(
            filepath, str(e)))
        lg.error(traceback.format_exc())
        raven_client.captureException()
        return (0, 0, 0)
    except KeyError as e:
        project_id = db.log_project_issue(os.path.dirname(filepath),
                                          os.path.basename(filepath),
                                          problem="Invalid project file",
                                          detail="{0}: {1} {2}".format(
                                              e.__class__, str(e),
                                              traceback.format_exc()))
        db.insert_sysparam(
            "warning",
            "Unable to read project file '{0}' - {1}".format(filepath, str(e)))
        lg.error("Unable to read project file '{0}' - {1}".format(
            filepath, str(e)))
        lg.error(traceback.format_exc())
        raven_client.captureException()
        return (0, 0, 0)

    except InvalidDataError as e:
        db.insert_sysparam(
            "warning",
            "Corrupted project file: {0} {1}".format(filepath, unicode(e)))
        raven_client.captureException()
        return (0, 0, 0)

    total_files = 0
    no_vsitem = 0
    not_in_db = 0

    lg.debug("looking for referenced media....")
    for filepath in pp.getReferencedMedia():
        total_files += 1
        server_path = re.sub(u'^/Volumes', '/srv', filepath).encode('utf-8')

        vsid = db.get_vidispine_id(server_path)
        # this call will return None if the file is not from an asset folder, e.g. newswire
        if vsid is None:
            try:
                vsid = find_item_id_for_path(server_path)
                if vsid is None:
                    lg.error(
                        "File {0} is found by Vidispine but has not been imported yet"
                        .format(server_path))
                    continue
            except VSNotFound:
                lg.error(
                    "File {0} could not be found in either Vidispine or the asset importer database"
                    .format(server_path))
                continue

        item = VSItem(host=cfg.value('vs_host'),
                      port=cfg.value('vs_port'),
                      user=cfg.value('vs_user'),
                      passwd=cfg.value('vs_password'))
        item.populate(vsid, specificFields=['gnm_asset_category'])
        try:
            if item.get('gnm_asset_category').lower() == 'branding':
                lg.info("File %s is branding, not adding to project" %
                        (filepath, ))
                continue
        except AttributeError:
            lg.warning("File %s has no value for gnm_asset_catetory" %
                       (filepath, ))

        lg.debug("Got filepath %s" % filepath)
        fileid = db.fileId(server_path)
        if fileid:
            try:
                db.link_file_to_edit_project(fileid, project_id)
                lg.debug("Linked file %s with id %s to project %s" %
                         (filepath, fileid, project_id))
            except AlreadyLinkedError:
                lg.info("File %s with id %s is already linked to project %s" %
                        (filepath, fileid, project_id))
                continue
        else:
            not_in_db += 1
            lg.warning("File %s could not be found in the database" % filepath)
            continue
        n = 0
        found = False

        #using this construct to avoid loading more data from VS than necessary.  We simply check whether the ID exists
        #in the parent collections list (cached on the item record) without lifting any more info out of VS
        if vsproject.name in map(
                lambda x: x.name,
                item.parent_collections(shouldPopulate=False)):
            lg.info("File %s is already in project %s" %
                    (filepath, vsproject.name))
            continue

        vsproject.addToCollection(
            item=item
        )  #this call will apparently succeed if the item is already added to said collection, but it won't be added twice.

    lg.info(
        "Run complete. Out of a total of %d referenced files, %d did not have a Vidispine item and %d were not in the Asset Importer database"
        % (total_files, no_vsitem, not_in_db))
    return (total_files, no_vsitem, not_in_db)