orngServerFiles: Orange's file repository

Module orngServerFiles allows users to download files from a common repository. It was designed to simplify the download and updates of external data sources for Orange Genomics add-on. Furthermore, an authenticated user can also manage the repository files with this module.

Each file managed by orngServerFiles is described by domain and file name. Domains are like folders - a place where files are put in.

Local file management

Downloaded files are saved under Orange's settings directory, subdirectory buffer/bigfiles. For each new domain a subdirectory containing the downloaded files is created. With every download a corresponding info file is created with the same name plus ".info" extension. It contains file's title, tags, size and date and time of the upload.

Methods used for managing local files

download(domain, filename [,serverfiles])
Downloads file from the repository to local orange installation. To download files as an authenticated user you should also pass an instance of ServerFiles class.
listdomains()
List all domains on local orange installation.
listfiles(domain)
List all files in a domain on local orange installation.
info(domain, filename)
Returns a dictionary containing downloaded file info. Keys: title, tags, size, datetime.
localpath(domain [,filename])
Returns local path for the domain. If filename is present, return local path to than filename.

ServerFiles: the repository

To work with the repository, you need to create an instance of ServerFiles. To access the repository as an authenticated user, an username and password should be passed to the constructor. Afterwards you can use the instance's methods. All password protected operations and transfers are secured by SSL; this secures both password and content.

Repository files are set as protected when first uploaded: only authenticated users can see them. They need to be unprotected for public use.

Constructor([username, password])
Creates a ServerFiles instance. Pass your username and password to use the repository as an authenticated user.

Ordinary users

download(domain, filename, target)
Downloads file from the repository to a given target name.
listfiles(domain)
List all files in a repository domain.
info(domain, filename)
Returns a dictionary containing repository file info. Keys: title, tags, size, datetime.
downloadFH(domain, filename)
Returns a file handle to the file that we would like to download.

Authenticated users

Authenticated users can use methods described in "Ordinary users" section, but they will also work for protected files.
create_domain(domain)
Creates a repository domain.
remove_domain(domain [,force])
Removes a domain. If force is True, domain is removed even if it contains files.
remove(domain, filename)
Removes a file from the repository.
protect(domain, filename)
Hide file from non-authenticated users.
unprotect(domain, filename)
Put a file into public use.
upload(domain, filename, localfile [, title, tags])
Uploads a file "localfile" to the domain where it is saved with filename "filename". If file does not exist yet, set it as protected. Parameter localfile can be a file handle open for reading or a file name.

Examples

Downloading and listing files

Listing local files, files from the repository and downloading all available files from domain "demo".

import orngServerFiles repository = orngServerFiles.ServerFiles() print "My files", orngServerFiles.listfiles('demo') print "Repository files", repository.listfiles('demo') print "Downloading all files in domain 'test'" for file in repository.listfiles('demo'): print "Datetime for", file, repository.info('demo', file)["datetime"] orngServerFiles.download('demo', file) print "My files after download", orngServerFiles.listfiles('demo') print "My domains", orngServerFiles.listdomains()

Output for first run (and current repository state):

My files [] Repository files ['orngServerFiles.py', 'urllib2_file.py'] Downloading all files in domain 'test' Datetime for orngServerFiles.py 2008-08-20 12:25:54.624000 Datetime for urllib2_file.py 2008-08-20 12:25:54.827000 My files after download ['urllib2_file.py', 'orngServerFiles.py'] My domains ['demo']

Creating a domain, uploading files

A similar domain as "demo" in previous example can be built as follows. import orngServerFiles ordinary = orngServerFiles.ServerFiles() authenticated = orngServerFiles.ServerFiles(username, password) try: authenticated.remove_domain('demo2', force=True) except: pass authenticated.create_domain('demo2') authenticated.upload('demo2', 'orngServerFiles.py', 'orngServerFiles.py', \ title="orngServerFiles client", tags=["basic", "fileManagement"]) authenticated.upload('demo2', 'urllib2_file.py', 'urllib2_file.py') print "Ordinary users see:", ordinary.listfiles('demo2') print "Authenticated users see:", authenticated.listfiles('demo2') authenticated.unprotect('demo2', 'orngServerFiles.py') authenticated.unprotect('demo2', 'urllib2_file.py') print "Ordinary users now see:", ordinary.listfiles('demo2') print "orngServerFiles.py file info:" import pprint; pprint.pprint(ordinary.info('demo2', 'orngServerFiles.py'))

Output:

Ordinary users see: [''] Authenticated users see: ['orngServerFiles.py', 'urllib2_file.py'] Ordinary users now see: ['orngServerFiles.py', 'urllib2_file.py'] orngServerFiles.py file info: {'datetime': '2008-08-26 10:30:05.373000', 'size': '10165', 'tags': ['basic', 'fileManagement'], 'title': 'orngServerFiles client'}