ubelt.util_platform module

ubelt.util_platform.platform_resource_dir()[source]

Returns a directory which should be writable for any application This should be used for persistent configuration files.

Returns:path to the resource dir used by the current operating system
Return type:str
ubelt.util_platform.platform_cache_dir()[source]

Returns a directory which should be writable for any application This should be used for temporary deletable data.

Returns:path to the cache dir used by the current operating system
Return type:str
ubelt.util_platform.get_app_resource_dir(appname, *args)[source]

Returns a writable directory for an application This should be used for persistent configuration files.

Parameters:
  • appname (str) – the name of the application
  • *args – any other subdirectories may be specified
Returns:

dpath: writable resource directory for this application

Return type:

str

SeeAlso:
ensure_app_resource_dir
ubelt.util_platform.ensure_app_resource_dir(appname, *args)[source]

Calls get_app_resource_dir but ensures the directory exists.

SeeAlso:
get_app_resource_dir

Example

>>> import ubelt as ub
>>> dpath = ub.ensure_app_resource_dir('ubelt')
>>> assert exists(dpath)
ubelt.util_platform.get_app_cache_dir(appname, *args)[source]

Returns a writable directory for an application. This should be used for temporary deletable data.

Parameters:
  • appname (str) – the name of the application
  • *args – any other subdirectories may be specified
Returns:

dpath: writable cache directory for this application

Return type:

str

SeeAlso:
ensure_app_cache_dir
ubelt.util_platform.ensure_app_cache_dir(appname, *args)[source]

Calls get_app_cache_dir but ensures the directory exists.

SeeAlso:
get_app_cache_dir

Example

>>> import ubelt as ub
>>> dpath = ub.ensure_app_cache_dir('ubelt')
>>> assert exists(dpath)
ubelt.util_platform.startfile(fpath, verbose=True)[source]

Uses default program defined by the system to open a file. This is done via os.startfile on windows, open on mac, and xdg-open on linux.

Parameters:
  • fpath (str) – a file to open using the program associated with the files extension type.
  • verbose (int) – verbosity

References

http://stackoverflow.com/questions/2692873/quote-posix

DisableExample:
>>> # This test interacts with a GUI frontend, not sure how to test.
>>> import ubelt as ub
>>> base = ub.ensure_app_cache_dir('ubelt')
>>> fpath1 = join(base, 'test_open.txt')
>>> ub.touch(fpath1)
>>> proc = ub.startfile(fpath1)
ubelt.util_platform.editfile(fpath, verbose=True)[source]

Opens a file or code corresponding to a live python object in your preferred visual editor. This function is mainly useful in an interactive IPython session.

The visual editor is determined by the VISUAL environment variable. If this is not specified it defaults to gvim.

Parameters:
  • fpath (str) – a file path or python module / function
  • verbose (int) – verbosity
DisableExample:
>>> # This test interacts with a GUI frontend, not sure how to test.
>>> import ubelt as ub
>>> ub.editfile(ub.util_platform.__file__)
>>> ub.editfile(ub)
>>> ub.editfile(ub.editfile)