File Register Example

How to use an XML based file register class.

Import pyMez

The XMLModels module (pyMez.Code.DataHandlers.XMLModels) has the FileRegister class.

In [1]:
from pyMez import *
Importing pyMez, this should take roughly 30 seconds
Importing Code.DataHandlers.GeneralModels
It took 6.065 s to import Code.DataHandlers.GeneralModels
Importing Code.DataHandlers.HTMLModels
It took 0.464 s to import Code.DataHandlers.HTMLModels
Importing Code.DataHandlers.NISTModels
It took 16.802 s to import Code.DataHandlers.NISTModels
Importing Code.DataHandlers.TouchstoneModels
It took 0.013 s to import Code.DataHandlers.TouchstoneModels
Importing Code.DataHandlers.XMLModels
It took 0.649 s to import Code.DataHandlers.XMLModels
Importing Code.DataHandlers.ZipModels
It took 0.066 s to import Code.DataHandlers.ZipModels
Importing Code.InstrumentControl.Experiments
It took 2.243 s to import Code.InstrumentControl.Experiments
Importing Code.InstrumentControl.Instruments
It took 0.017 s to import Code.InstrumentControl.Instruments
Importing Code.Utils.Names
It took 0.012 s to import Code.Utils.Names
It took 26.332 s to import all of the active modules
In [2]:
# Create a new file register
new_file_register=FileRegister()
In [3]:
# now add all the files in the current working directory
new_file_register.add_tree(os.getcwd())
In [4]:
# now we have created an xml sheet with all of the current files and directories and a ip like id
new_file_register.get_data_dictionary_list()[0]
Out[4]:
{'Date': '2018-11-14T17:08:34.082000',
 'Host': '672PIF-AS1.campus.nist.gov',
 'Id': '132.163.48.125.11.11.11.11.11.11.11.11.11.11',
 'Type': 'Directory',
 'URL': 'file:C:/ProgramData/Anaconda2/Lib/site-packages/pyMez/Documentation/Examples/jupyter/.html_checkpoints'}
In [5]:
# we can create html and show it
html_text=new_file_register.to_HTML(os.path.join(TESTS_DIRECTORY,"../XSL/FR_STYLE.xsl"))
In [6]:
html=HTMLBase(html_text=html_text)
In [7]:
html.show()
file://c:/users/sandersa/appdata/local/temp/1/tmpibiagb.html
In [8]:
# we can add another file
new_file_register.add_entry(os.path.join(PYMEASURE_ROOT,"Documentation/pyMez_Documentation.html"))
In [9]:
# now we have a dictionary representation
new_file_register.get_data_dictionary_list()[-1]
Out[9]:
{'Date': '2018-11-14T17:09:02.630000',
 'Host': '672PIF-AS1.campus.nist.gov',
 'Id': '132.163.48.125.11.11.11.12.11.11.11.11.11.11.11.21',
 'Type': 'Ordinary',
 'URL': 'file:C:/ProgramData/Anaconda2/lib/site-packages/pyMez/Code/InstrumentControl/../../Documentation/pyMez_Documentation.html'}
In [10]:
# A list representation
new_file_register.get_data()[0]
Out[10]:
['2018-11-14T17:08:34.082000',
 'file:C:/ProgramData/Anaconda2/Lib/site-packages/pyMez/Documentation/Examples/jupyter/.html_checkpoints',
 '672PIF-AS1.campus.nist.gov',
 'Directory',
 '132.163.48.125.11.11.11.11.11.11.11.11.11.11']
In [11]:
# and we can use xpath syntax
print(new_file_register[".//File"][0])
<File Date="2018-11-14T17:08:34.082000" Host="672PIF-AS1.campus.nist.gov" Id="132.163.48.125.11.11.11.11.11.11.11.11.11.11" Type="Directory" URL="file:C:/ProgramData/Anaconda2/Lib/site-packages/pyMez/Documentation/Examples/jupyter/.html_checkpoints"/>