The PyA File System

Well, “file system” is not really true. It is only a tool to manage access to PyA’s data directory

class PyAstronomy.pyaC.pyaPermanent.PyAFS

Manage access to PyA’s data directory.

This class provides a convenient interface to create, read, and modify files in PyA’s data directory.

Methods

composeFilename(rfn)

Returns full filename.

createSubfolder(folder)

Create subfolders (relative to data root directory).

downloadToFile(url, fn[, clobber, verbose, ...])

Download content from URL.

fileExists(fn)

Check whether file exists

getFullPath(rpath)

Return full path for relative path

globglob(rpath, ge)

Apply glob.glob on relative path

removeFile(fn)

Remove a file from PyA's data directory.

requestFile(relName[, mode, openMethod])

Obtain a file object within the PyA data path.

touchFile(relName)

Create an empty file in PyA's data directory.

composeFilename(rfn)

Returns full filename.

Parameters
rfnstring

Relative file name (in PyA data path).

Returns
filenamestring

Absolute filename.

createSubfolder(folder)

Create subfolders (relative to data root directory).

Ignores already existing folders. This method can handle recursive directory creation.

downloadToFile(url, fn, clobber=False, verbose=True, openMethod=<built-in function open>, context=None)

Download content from URL.

Parameters
urlstring

The location of the content.

fnstring

The relative or absolute name of the file to which the download shall be saved.

clobberboolean, optional

If True, an existing file will be overwritten.

verboseboolean, optional

If True, information on the download will be printed to the screen.

openMethodcallable

The method used to open the file to write to (default is open, other choices may be gzip.open or io.ipen)

contextssl context

SSL context parameter handed to urlopen.

fileExists(fn)

Check whether file exists

Parameters
fnstring

The filename either relative to PyA’s data path or absolute.

Returns
Flagboolean

True if file exists and False otherwise.

getFullPath(rpath)

Return full path for relative path

Parameters
rpathstring or list of strings

Relative path in PyA data directory or individual constituents of path

Returns
Pathstring

Absolute path

globglob(rpath, ge)

Apply glob.glob on relative path

Parameters
rpathstring

Relative path

gestring

Glob expression (e.g., .)

Returns
Fnslist of strings

Glob results (relative paths)

removeFile(fn)

Remove a file from PyA’s data directory.

If the file does not exist, the request is ignored.

Parameters
fnstring

The filename either absolute or relative.

requestFile(relName, mode='r', openMethod=<built-in function open>, *args, **kwargs)

Obtain a file object within the PyA data path.

This method opens and creates files within PyA’s data path. If the directory in which a file shall be created does not yet exist, it will be created.

Parameters
relNamestring

The filename. Usually, it will be given relative to the PyA data path, but it can also be an absolute filename.

modestring, optional

The opening mode (e.g., “r” or “w”). This flag is given to the openMethod. The default is “r” for “read”.

openMethodmethod, optional

The method used to create the file object. The default is Python’s built-in open method. Another example could be gzip.open.

Returns
The file object.
touchFile(relName)

Create an empty file in PyA’s data directory.

Parameters
relNamestring

The filename. Usually, it will be given relative to the PyA data path, but it can also be an absolute filename.