Pyyaks file utilities
Get file(s) matching fileglob. If the number of matching files is less than minfiles or more than maxfiles then an exception is raised.
| Parameters: |
|
|---|
Make a local copy of or link to infile, gunzipping if necessary.
Examples:
>>> import pyyaks.fileutil
>>> import random, tempfile
>>> a = os.linesep.join([str(random.random()) for i in range(100)])
>>> tmpfile = tempfile.mkstemp()[1]
>>> open(tmpfile, 'w').write(a)
>>> stat = subprocess.Popen(['gzip', '--stdout', tmpfile], stdout=open(tmpfile+'.gz','w')).communicate()
>>> tmplocal = pyyaks.fileutil.make_local_copy(tmpfile, clobber=True)
>>> a == open(tmplocal).read()
True
>>> tmplocal = pyyaks.fileutil.make_local_copy(tmpfile+'.gz', clobber=True)
>>> a == open(tmplocal).read()
True
>>> os.unlink(tmpfile)
>>> os.unlink(tmplocal)
| Parameters: |
|
|---|---|
| Return type: | Output file name |
Find relative path from current directory to path.
Example usage:
>>> from pyyaks.fileutil import relpath
>>> relpath('/a/b/hello/there', cwd='/a/b/c/d')
'../../hello/there'
>>> relpath('/a/b/c/d/e/hello/there', cwd='/a/b/c/d')
'e/hello/there'
>>> # Special case - don't go up to root and back
>>> relpath('/x/y/hello/there', cwd='/a/b/c/d')
'/x/y/hello/there'
| Parameters: |
|
|---|---|
| Return type: | Relative path |
Bases: object
Create a temporary directory that gets automatically removed. Any object initialization parameters are passed through to tempfile.mkdtemp.
>>> import pyyaks.fileutil
>>> tmpdir = pyyaks.fileutil.TempDir(dir='.')
>>> tmpdir.name
'./tmpcCH_l-'
>>> del tmpdir