Analysis Properties Metadata

# This script gets dxp metadata info into an md variable and stores it to a documentProperty variable

# Config section
myDocProp = "FileInfoMetaData" #if you change this, make sure such doc property exists

# Global string to hold metadata info
# Ddocumentation here: https://docs.tibco.com/pub/doc_remote/spotfire/6.5.0/api/?topic=html/P_Spotfire_Dxp_Application_DocumentMetadata_FileNameUsedBySave.htm

from Spotfire.Dxp.Application import DocumentMetadata
dmd = Application.DocumentMetadata 
md = "============ DXP info ================="
md += "\nLoadedFromLibraryPath: " + str(dmd.LoadedFromLibraryPath)
md += "\nIsDirty: " + str(dmd.IsDirty)
#md += "\nLibraryItemUsedBySave: " + str(dmd.LibraryItemUsedBySave)
md += "\nLoadedFromFileName: " + str(dmd.LoadedFromFileName)
md += "\nLoadedFromLibraryItem: " + str(dmd.LoadedFromLibraryItem)
md += "\nLoadedFromLibraryPath: " + str(dmd.LoadedFromLibraryPath)

# Gets library metadata if LibraryItemUsedBySave exists
# Reference: https://docs.tibco.com/pub/doc_remote/spotfire/6.5.0/api/html/AllMembers_T_Spotfire_Dxp_Framework_Library_LibraryItem.htm
from Spotfire.Dxp.Framework.Library import LibraryItemType
if dmd.LibraryItemUsedBySave !=None:
 li = dmd.LibraryItemUsedBySave
 md += "\n\n=== LibraryItemUsedBySave info ===="
 md += "\nContentSize:" + str(li.ContentSize)
 md += "\nCreated:" + str(li.Created)
 md += "\nDescription:" + str(li.Description)
 md += "\nHasBeenAccessed:" + str(li.HasBeenAccessed)
 md += "\nId:" + str(li.Id)
 md += "\nItemType.Analysis:" + str(li.ItemType.Analysis == LibraryItemType.Analysis)
 md += "\nItemType.Folder:" + str(li.ItemType.Folder == LibraryItemType.Folder)
 md += "\nItemType.InformationLink:" + str(li.ItemType.InformationLink == LibraryItemType.InformationLink)
 md += "\nLastAccess:" + str(li.LastAccess)
 md += "\nLastModified:" + str(li.LastModified)
 md += "\nPath:" + str(li.Path)
 md += "\n:Title" + str(li.Title)

# Gets file metadata if LoadedFromFileName exists
# Documentation here: http://msdn.microsoft.com/en-us/library/system.io.fileinfo_properties(v=vs.110).aspx

# check if LoadedFromFileName, if so, extract attributes from such file
if dmd.LoadedFromFileName!=None:
 md += "\n\n=== LoadedFromFileName info ===="
 from System.IO import FileInfo
 fi = FileInfo(dmd.LoadedFromFileName)
 md += "\n CreationTime: " + fi.CreationTime.ToString()
 md += "\n Directory: " + fi.Directory.ToString()
 md += "\n LastAccessTime: " + fi.LastAccessTime.ToString()
 md += "\n LastWriteTime: " + fi.LastWriteTime.ToString()

#stores md in doc property
Document.Properties[myDocProp]=md

#debug, preview output
print md


Example outputs from a dxp saved in local computer connecting to an excel file:

============ DXP info =================
LoadedFromLibraryPath: None
IsDirty: False
LoadedFromFileName: C:\Users\Jose\Documents\WGC\FileInfo\FileInfo.xlsx
LoadedFromLibraryItem: None
LoadedFromLibraryPath: None

=== LoadedFromFileName info ====
CreationTime: 10/8/2014 2:37:29 PM
Directory: C:\Users\Jose\Documents\WGC\FileInfo
LastAccessTime: 10/8/2014 4:19:25 PM
LastWriteTime: 10/8/2014 4:19:26 PM


Example outputs from a dxp saved in Library connecting to an excel file:

============ DXP info =================
LoadedFromLibraryPath: None
IsDirty: False
LoadedFromFileName: C:\Users\Jose\Documents\WGC\FileInfo\FileInfo.xlsx
LoadedFromLibraryItem: None
LoadedFromLibraryPath: None

=== LibraryItemUsedBySave info ====
ContentSize:40290
Created:10/8/2014 3:18:00 PM
Description:Shows data source metadata
HasBeenAccessed:False
Id:27266955-7578-4343-b8d4-2a702ebc5568
ItemType.Analysis:True
ItemType.Folder:True
ItemType.InformationLink:True
LastAccess:1/1/0001 12:00:00 AM
LastModified:10/9/2014 3:43:19 PM
Path:/Users/Jose Leviaguirre/FileInfo
:TitleFileInfo

=== LoadedFromFileName info ====
CreationTime: 10/8/2014 2:37:29 PM
Directory: C:\Users\Jose\Documents\WGC\FileInfo
LastAccessTime: 10/8/2014 4:19:25 PM
LastWriteTime: 10/8/2014 4:19:26 PM


Example of a dxp file connecting to an infolink not saved anywhere
============ DXP info =================
LoadedFromLibraryPath: None
IsDirty: True
LoadedFromFileName: None
LoadedFromLibraryItem: None
LoadedFromLibraryPath: None


Example of a dxp file connecting form infolink saved in library
============ DXP info =================
LoadedFromLibraryPath: None
IsDirty: False
LoadedFromFileName: None
LoadedFromLibraryItem: None
LoadedFromLibraryPath: None

=== LibraryItemUsedBySave info ====
ContentSize:33091
Created:10/9/2014 3:54:28 PM
Description:
HasBeenAccessed:False
Id:ef80f41e-3dc4-4c63-a815-99cebbbd42f9
ItemType.Analysis:True
ItemType.Folder:True
ItemType.InformationLink:True
LastAccess:1/1/0001 12:00:00 AM
LastModified:10/9/2014 3:54:28 PM
Path:/Users/Jose Leviaguirre/test
:Titletest


Previous
Next Post »