Package Bio :: Package Restriction :: Package _Update :: Module Update
[hide private]
[frames] | no frames]

Source Code for Module Bio.Restriction._Update.Update

  1  #!/usr/bin/env python 
  2  # 
  3  #      Restriction Analysis Libraries. 
  4  #      Copyright (C) 2004. Frederic Sohm. 
  5  # 
  6  # This code is part of the Biopython distribution and governed by its 
  7  # license.  Please see the LICENSE file that should have been included 
  8  # as part of this package. 
  9  # 
 10   
 11  """Update the Rebase emboss files used by Restriction to build the 
 12  Restriction_Dictionary.py module.""" 
 13   
 14  import os 
 15  import sys 
 16  import sre 
 17  import time 
 18  import gzip 
 19  from urllib import FancyURLopener 
 20   
 21  from Bio.Restriction.RanaConfig import * 
 22   
 23   
24 -class RebaseUpdate(FancyURLopener) :
25
26 - def __init__(self, e_mail='', ftpproxy='') :
27 """RebaseUpdate([e_mail[, ftpproxy]]) -> new RebaseUpdate instance. 28 29 if e_mail and ftpproxy are not given RebaseUpdate uses the corresponding 30 variable from RanaConfig. 31 32 e_mail is the password for the anonymous ftp connection to Rebase. 33 ftpproxy is the proxy to use if any.""" 34 proxy = {'ftp' : ftpproxy or ftp_proxy} 35 global Rebase_password 36 Rebase_password = e_mail or Rebase_password 37 if not Rebase_password : 38 raise FtpPasswordError, 'Rebase' 39 if not Rebase_name : 40 raise FtpNameError, 'Rebase' 41 FancyURLopener.__init__(self, proxy)
42
43 - def prompt_user_passwd(self, host, realm) :
45
46 - def openRebase(self, name = ftp_Rebase) :
47 print '\n Please wait, trying to connect to Rebase\n' 48 try : 49 self.open(name) 50 except : 51 raise ConnectionError, 'Rebase' 52 return
53
54 - def getfiles(self, *files) :
55 print '\n', 56 for file in self.update(*files) : 57 print 'copying', file 58 fn = os.path.basename(file) 59 #filename = os.path.join(Rebase, fn) 60 filename = os.path.join(os.getcwd(), fn) 61 print 'to', filename 62 self.retrieve(file, filename) 63 self.close() 64 return
65
66 - def localtime(self) :
67 t = time.gmtime() 68 year = str(t.tm_year)[-1] 69 month = str(t.tm_mon) 70 if len(month) == 1 : month = '0'+month 71 return year+month
72
73 - def update(self, *files):
74 if not files : 75 files = [ftp_emb_e, ftp_emb_s, ftp_emb_r] 76 return [x.replace('###', self.localtime()) for x in files]
77
78 - def __del__(self) :
79 if hasattr(self, 'tmpcache') : self.close() 80 # 81 # self.tmpcache is created by URLopener.__init__ method. 82 # 83 return
84 85
86 -class FtpNameError(ValueError) :
87
88 - def __init__(self, which_server) :
89 print " In order to connect to %s ftp server, you must provide a name.\ 90 \n Please edit Bio.Restriction.RanaConfig\n" % which_server 91 sys.exit()
92
93 -class FtpPasswordError(ValueError) :
94
95 - def __init__(self, which_server) :
96 print "\n\ 97 \n In order to connect to %s ftp server, you must provide a password.\ 98 \n Use the --e-mail switch to enter your e-mail address.\ 99 \n\n" % which_server 100 sys.exit()
101 102
103 -class ConnectionError(IOError) :
104
105 - def __init__(self, which_server) :
106 print '\ 107 \n Unable to connect to the %s ftp server, make sure your computer\ 108 \n is connected to the internet and that you have correctly configured\ 109 \n the ftp proxy.\ 110 \n Use the --proxy switch to enter the address of your proxy\ 111 \n' % which_server 112 sys.exit()
113 114 115 116 __all__ = ['RebaseUpdate', 'FtpNameError', 'FtpPasswordError'] 117