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 time 
 17  from urllib import FancyURLopener 
 18   
 19  from Bio.Restriction.RanaConfig import * 
 20   
 21   
22 -class RebaseUpdate(FancyURLopener):
23
24 - def __init__(self, e_mail='', ftpproxy=''):
25 """RebaseUpdate([e_mail[, ftpproxy]]) -> new RebaseUpdate instance. 26 27 if e_mail and ftpproxy are not given RebaseUpdate uses the corresponding 28 variable from RanaConfig. 29 30 e_mail is the password for the anonymous ftp connection to Rebase. 31 ftpproxy is the proxy to use if any.""" 32 proxy = {'ftp' : ftpproxy or ftp_proxy} 33 global Rebase_password 34 Rebase_password = e_mail or Rebase_password 35 if not Rebase_password: 36 raise FtpPasswordError('Rebase') 37 if not Rebase_name: 38 raise FtpNameError('Rebase') 39 FancyURLopener.__init__(self, proxy)
40
41 - def prompt_user_passwd(self, host, realm):
43
44 - def openRebase(self, name = ftp_Rebase):
45 print '\n Please wait, trying to connect to Rebase\n' 46 try: 47 self.open(name) 48 except: 49 raise ConnectionError('Rebase') 50 return
51
52 - def getfiles(self, *files):
53 print '\n', 54 for file in self.update(*files): 55 print 'copying', file 56 fn = os.path.basename(file) 57 #filename = os.path.join(Rebase, fn) 58 filename = os.path.join(os.getcwd(), fn) 59 print 'to', filename 60 self.retrieve(file, filename) 61 self.close() 62 return
63
64 - def localtime(self):
65 t = time.gmtime() 66 year = str(t.tm_year)[-1] 67 month = str(t.tm_mon) 68 if len(month) == 1: 69 month = '0' + month 70 return year+month
71
72 - def update(self, *files):
73 if not files: 74 files = [ftp_emb_e, ftp_emb_s, ftp_emb_r] 75 return [x.replace('###', self.localtime()) for x in files]
76
77 - def __del__(self):
78 if hasattr(self, 'tmpcache'): 79 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
94 -class FtpPasswordError(ValueError):
95
96 - def __init__(self, which_server):
97 print "\n\ 98 \n In order to connect to %s ftp server, you must provide a password.\ 99 \n Use the --e-mail switch to enter your e-mail address.\ 100 \n\n" % which_server 101 sys.exit()
102 103
104 -class ConnectionError(IOError):
105
106 - def __init__(self, which_server):
107 print '\ 108 \n Unable to connect to the %s ftp server, make sure your computer\ 109 \n is connected to the internet and that you have correctly configured\ 110 \n the ftp proxy.\ 111 \n Use the --proxy switch to enter the address of your proxy\ 112 \n' % which_server 113 sys.exit()
114 115 116 __all__ = ['RebaseUpdate', 'FtpNameError', 'FtpPasswordError'] 117