allpy
changeset 783:84ac7e748e26
change cached_download_pdb not to raise if cache_dir is read-only
author | boris (kodomo) <bnagaev@gmail.com> |
---|---|
date | Wed, 13 Jul 2011 00:41:11 +0400 |
parents | 1f78a0cd124e |
children | 78597d31d423 |
files | allpy/structure.py |
diffstat | 1 files changed, 12 insertions(+), 10 deletions(-) [+] |
line diff
1.1 --- a/allpy/structure.py Tue Jul 12 23:55:28 2011 +0400 1.2 +++ b/allpy/structure.py Wed Jul 13 00:41:11 2011 +0400 1.3 @@ -12,6 +12,7 @@ 1.4 import urllib2 1.5 from copy import copy 1.6 import json 1.7 +from cStringIO import StringIO 1.8 1.9 from Bio.PDB import PDBParser 1.10 from Bio.PDB import Select 1.11 @@ -68,17 +69,18 @@ 1.12 path = os.path.join(self.cache_dir, code + '.pdb') 1.13 if os.path.exists(path): 1.14 return open(path) 1.15 + in_file = self.download_pdb(code) 1.16 if not os.path.exists(self.cache_dir): 1.17 - os.mkdir(self.cache_dir) 1.18 - try: 1.19 - with open(path, 'w') as out_file: 1.20 - in_file = self.download_pdb(code) 1.21 - out_file.write(in_file.read()) 1.22 - in_file.close() 1.23 - except BaseException: 1.24 - os.unlink(path) 1.25 - raise 1.26 - return open(path) 1.27 + try: 1.28 + os.mkdir(self.cache_dir) 1.29 + with open(path, 'w') as out_file: 1.30 + s = in_file.read() 1.31 + out_file.write(s) 1.32 + in_file = StringIO(s) 1.33 + os.unlink(path) 1.34 + except: 1.35 + pass 1.36 + return in_file 1.37 cached_download_pdb = CachedDownloadPdb() 1.38 1.39 class SequenceMixin(base.Sequence):