Changeset 7744:ccb8bd3760c0 in orange


Ignore:
Timestamp:
03/15/11 15:01:11 (3 years ago)
Author:
markotoplak
Branch:
default
Convert:
07029ab1535e62ba413dc47b8f1fe577ec0c84bb
Message:

serverfiles: update and needs_update take an optional ServerFiles object instead of access_code. orngServerFiles modified for backwards compatibility.

Location:
orange
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/misc/serverfiles.py

    r7742 r7744  
    559559    return dic 
    560560 
    561 def needs_update(domain, filename, access_code=None): 
     561def needs_update(domain, filename, serverfiles=None): 
    562562    """True if a file does not exist in the local repository 
    563563    or if there is a newer version on the server.""" 
     564    if serverfiles == None: serverfiles = ServerFiles() 
    564565    if filename not in listfiles(domain): 
    565566        return True 
     
    567568    dt_local = datetime.datetime.strptime( 
    568569        info(domain, filename)["datetime"][:19], dt_fmt) 
    569     server = ServerFiles(access_code=access_code) 
    570570    dt_server = datetime.datetime.strptime( 
    571         server.info(domain, filename)["datetime"][:19], dt_fmt) 
     571        serverfiles.info(domain, filename)["datetime"][:19], dt_fmt) 
    572572    return dt_server > dt_local 
    573573 
    574 def update(domain, filename, access_code=None, verbose=True): 
     574def update(domain, filename, serverfiles=None, **kwargs): 
    575575    """Downloads the corresponding file from the server and places it in  
    576576    the local repository, but only if the server copy of the file is newer  
    577     or the local copy does not exist. An optional access_code can be given  
    578     to allow server access if the file is protected. 
    579     """ 
    580     if needs_update(domain, filename, access_code=access_code): 
    581         if not access_code: 
    582             download(domain, filename, verbose=verbose) 
    583         else: 
    584             server = orngServerFiles.ServerFiles(access_code=access_code) 
    585             download(domain, filename, serverfiles=server) 
     577    or the local copy does not exist. An optional  :class:`ServerFiles` object 
     578    can be passed for authenticated access. 
     579    """ 
     580    if serverfiles == None: serverfiles = ServerFiles() 
     581    if needs_update(domain, filename, serverfiles=serverfiles): 
     582        download(domain, filename, serverfiles=serverfiles, **kwargs) 
    586583         
    587584def _searchinfo(): 
  • orange/orngServerFiles.py

    r7742 r7744  
    11from Orange.misc.serverfiles import * 
     2import Orange 
    23 
     4#for backward compatibility 
     5 
     6def _sf_with_code(access_code=None): 
     7    if not access_code: 
     8        return ServerFiles() 
     9    else: 
     10        return ServerFiles(access_code=access_code) 
     11 
     12def needs_update(domain, filename, access_code=None): 
     13    sf = _sf_with_code(access_code=access_code) 
     14    return Orange.misc.serverfiles.needs_update(domain, filename, serverfiles=sf) 
     15 
     16def update(domain, filename, access_code=None, verbose=True): 
     17    sf = _sf_with_code(access_code=access_code) 
     18    return Orange.misc.serverfiles.update(domain, filename, serverfiles=sf, verbose=verbose) 
Note: See TracChangeset for help on using the changeset viewer.