edx/pyfs

Name: pyfs

Owner: edX

Description: Fork: This is a fork of pyfs which fixes some bugs.

Forked from: pmitros/pyfs

Created: 2017-07-07 15:37:32.0

Updated: 2017-07-07 15:37:34.0

Pushed: 2014-09-15 17:07:50.0

Homepage:

Size: 1824

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

PyFilesystem

This is a fork of pyfilesystem. The main version is on Google Code. It fixes an issue with authentication over VPC. My hope is the change will be merged back into pyfilesystem, and this repository will become obsolete.

PyFilesystem is an abstraction layer for filesystems. In the same way that Python's file-like objects provide a common way of accessing files, PyFilesystem provides a common way of accessing entire filesystems. You can write platform-independent code to work with local files, that also works with any of the supported filesystems (zip, ftp, S3 etc.).

Pyfilesystem works with Linux, Windows and Mac.

Suported Filesystems

Here are a few of the filesystems that can be accessed with Pyfilesystem:

Example

The following snippet prints the total number of bytes contained in all your Python files in C:/projects (including sub-directories)::

from fs.osfs import OSFS
projects_fs = OSFS('C:/projects')
print sum(projects_fs.getsize(path)
          for path in projects_fs.walkfiles(wildcard="*.py"))

That is, assuming you are on Windows and have a directory called 'projects' in your C drive. If you are on Linux / Mac, you might replace the second line with something like::

projects_fs = OSFS('~/projects')

If you later want to display the total size of Python files stored in a zip file, you could make the following change to the first two lines::

from fs.zipfs import ZipFS
projects_fs = ZipFS('source.zip')

In fact, you could use any of the supported filesystems above, and the code would continue to work as before.

An alternative to explicity importing the filesystem class you want, is to use an FS opener which opens a filesystem from a URL-like syntax::

from fs.opener import fsopendir
projects_fs = fsopendir('C:/projects')

You could change C:/projects to zip://source.zip to open the zip file, or even ftp://ftp.example.org/code/projects/ to sum up the bytes of Python stored on an ftp server.

Screencast

This is from an early version of PyFilesystem, but still relevant

http://vimeo.com/12680842

Discussion Group

http://groups.google.com/group/pyfilesystem-discussion

Further Information

http://www.willmcgugan.com/tag/fs/


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.