fileutils Module

This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>

File operations

gluon.fileutils.parse_version(version)[source]

Attempts to parse SemVer, fallbacks on legacy

gluon.fileutils.read_file(filename, mode='r')[source]

Returns content from filename, making sure to close the file explicitly on exit.

gluon.fileutils.write_file(filename, value, mode='w')[source]

Writes <value> to filename, making sure to close the file explicitly on exit.

gluon.fileutils.readlines_file(filename, mode='r')[source]

Applies .split(‘ ‘) to the output of read_file()

gluon.fileutils.up(path)[source]
gluon.fileutils.abspath(*relpath, **base)[source]

Converts relative path to absolute path based (by default) on applications_parent

gluon.fileutils.mktree(path)[source]
gluon.fileutils.listdir(path, expression='^.+$', drop=True, add_dirs=False, sort=True, maxnum=None, exclude_content_from=None)[source]

Like os.listdir() but you can specify a regex pattern to filter files. If add_dirs is True, the returned items will have the full path.

Deletes f. If it’s a folder, also its contents will be deleted

gluon.fileutils.cleanpath(path)[source]

Turns any expression/path into a valid filename. replaces / with _ and removes special characters.

gluon.fileutils.tar(file, dir, expression='^.+$', filenames=None, exclude_content_from=None)[source]

Tars dir into file, only tars file that match expression

gluon.fileutils.untar(file, dir)[source]

Untar file into dir

gluon.fileutils.tar_compiled(file, dir, expression='^.+$', exclude_content_from=None)[source]

Used to tar a compiled application. The content of models, views, controllers is not stored in the tar file.

gluon.fileutils.get_session(request, other_application='admin')[source]

Checks that user is authorized to access other_application

gluon.fileutils.check_credentials(request, other_application='admin', expiration=3600, gae_login=True)[source]

Checks that user is authorized to access other_application

gluon.fileutils.w2p_pack(filename, path, compiled=False, filenames=None)[source]

Packs a web2py application.

Parameters:
  • filename (str) – path to the resulting archive
  • path (str) – path to the application
  • compiled (bool) – if True packs the compiled version
  • filenames (list) – adds filenames to the archive
gluon.fileutils.w2p_unpack(filename, path, delete_tar=True)[source]
gluon.fileutils.w2p_pack_plugin(filename, path, plugin_name)[source]

Packs the given plugin into a w2p file. Will match files at:

<path>/*/plugin_[name].*
<path>/*/plugin_[name]/*
gluon.fileutils.w2p_unpack_plugin(filename, path, delete_tar=True)[source]
gluon.fileutils.fix_newlines(path)[source]
gluon.fileutils.make_fake_file_like_object()[source]