Note
Functions for performing file searching.
Module author: Adam Gagorik <adam.gagorik@gmail.com>
A method for searching for files and directories using patterns.
Parameters: |
|
---|
>>> import os
>>> work = os.getcwd()
>>> pkls = find(work, ext='txt*') # find all txt files in work
Search for directories that contain “runs”.
Parameters: |
---|
>>> systems = lm.find.systems(r'/home/adam/simulations')
>>> print '\n'.join(systems)
'/home/adam/simulations/systemA'
'/home/adam/simulations/systemB'
'/home/adam/simulations/systemC'
'/home/adam/simulations/systemD'
Search for directories that contain “parts”.
Parameters: |
---|
>>> work = r'/home/adam/simulations/systemA/run.0'
>>> sims = lm.find.sims(work, stub='voltage.right')
>>> print '\n'.join(systems)
'/home/adam/simulations/systemA/run.0/voltage.right_+0.0'
'/home/adam/simulations/systemA/run.0/voltage.right_+0.2'
'/home/adam/simulations/systemA/run.0/voltage.right_+0.4'
'/home/adam/simulations/systemA/run.0/voltage.right_+0.8'
Search for directories of the form run*.
Parameters: |
---|
>>> runs = lm.find.runs(r'/home/adam/simulations/systemA/')
>>> print '\n'.join(runs)
'/home/adam/simulations/systemA/run.0/'
'/home/adam/simulations/systemA/run.1/'
'/home/adam/simulations/systemA/run.2/'
'/home/adam/simulations/systemA/run.3/'
Search for a single directory of the form run*.
Parameters: |
---|
>>> run = lm.find.run(r'/home/adam/simulations/systemA')
RuntimeError: found multiple run* in directory:
/home/adam/simulations/systemA
run.0
run.1
run.2
run.3
Search for directories of the form part*.
Parameters: |
---|
>>> prts = lm.find.parts(r'~/simulations/systemA/run.0/voltage.right_+0.0')
>>> print '\n'.join(prts)
'/home/adam/simulations/systemA/run.0/voltage.right_+0.0/part.0/'
'/home/adam/simulations/systemA/run.0/voltage.right_+0.0/part.1/'
Search for a single directory of the form part*.
Parameters: |
---|
>>> part = lm.find.parts(r'~/simulations/systemA/run.0/voltage.right_+0.0')
RuntimeError: found multiple part* in directory:
/home/adam/simulations/systemA/run.0/voltage.right_+0.0
part.0
part.1
Search for files of the form .inp.
Parameters: |
---|
>>> inps = lm.find.inps('.')
Search for a single file of the form .inp.
Parameters: |
---|
>>> inp = lm.find.inp('.')
Search for files of the form .chk.
Parameters: |
---|
>>> chks = lm.find.chks('.')
Search for a single file of the form .chk.
Parameters: |
---|
>>> chk = lm.find.chk('.')
Search for files of the form .parm.
Parameters: |
---|
>>> parms = lm.find.parms('.')
Search for a single file of the form .parm.
Parameters: |
---|
>>> parm = lm.find.parm('.')
Search for files of the form .dat.
Parameters: |
---|
>>> dats = lm.find.dats('.')
Search for a single file of the form .dat.
Parameters: |
---|
>>> dat = lm.find.dat('.')
Search for files of the form .txt.
Parameters: |
---|
>>> txts = lm.find.txts('.')
Search for a single file of the form .txt.
Parameters: |
---|
>>> txt = lm.find.txt('.')
Search for files of the form .pkl.
Parameters: |
---|
>>> pkls = lm.find.pkls('.')
Search for a single file of the form .pkl.
Parameters: |
---|
>>> pkl = lm.find.pkl('.')
Search for files of the form .png.
Parameters: |
---|
>>> pngs = lm.find.pngs('.')
Search for a single file of the form .png.
Parameters: |
---|
>>> png = lm.find.png('.')
Return dirname of path where the regex matches.
Parameters: |
---|
>>> print slice_path('r/home/adam/Desktop', 'adam')
'/home/adam'
Return dirname of path where run directory is.
Parameters: | path (str) – path to parse |
---|
>>> print slice_path('r/system/run/sim/part')
'/system/run/sim/part'
Return dirname of path where sim directory is.
Parameters: | path (str) – path to parse |
---|
>>> print slice_path('r/system/run/sim/part')
'/system/run/sim'
Return dirname of path where run directory is.
Parameters: | path (str) – path to parse |
---|
>>> print slice_path('r/system/run/sim/part')
'/system/run'