From 6f6ce8ddd345f49af5df688858e83696eb93e5ef Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 15 Aug 2010 08:18:47 -0400 Subject: [PATCH] Fix existing Driver.is_me's crashes if path is a directory. I didn't add this at the curve level, since it seems reasonable that someone might develop a curve format where the 'file' is a directory. --- hooke/driver/__init__.py | 1 + hooke/driver/hdf5.py | 4 ++++ hooke/driver/hemingway.py | 3 +++ hooke/driver/jpk.py | 2 ++ hooke/driver/mcs.py | 2 ++ hooke/driver/mfp1d.py | 2 ++ hooke/driver/mfp1dexport.py | 3 +++ hooke/driver/mfp3d.py | 3 +++ hooke/driver/picoforce.py | 3 +++ hooke/driver/tutorial.py | 4 ++++ hooke/driver/wtk.py | 2 ++ 11 files changed, 29 insertions(+) diff --git a/hooke/driver/__init__.py b/hooke/driver/__init__.py index 4e37d79..bc38a24 100644 --- a/hooke/driver/__init__.py +++ b/hooke/driver/__init__.py @@ -25,6 +25,7 @@ to write your own to handle your lab's specific format. """ import logging +import os.path from ..config import Setting from ..util.pluggable import IsSubclass, construct_graph diff --git a/hooke/driver/hdf5.py b/hooke/driver/hdf5.py index 2614319..f338324 100644 --- a/hooke/driver/hdf5.py +++ b/hooke/driver/hdf5.py @@ -21,6 +21,8 @@ """Driver for text-exported HDF5 files from Igor pro """ +import os.path + from .. import curve as lhc from .. import libhooke as lh @@ -40,6 +42,8 @@ class hdf5Driver(lhc.Driver): self.filedata.close() def is_me(self): + if os.path.isdir(path): + return False self.raw_header=self.lines[0] if 'IGP-HDF5-Hooke' in self.raw_header: diff --git a/hooke/driver/hemingway.py b/hooke/driver/hemingway.py index 0c8ff36..5803800 100644 --- a/hooke/driver/hemingway.py +++ b/hooke/driver/hemingway.py @@ -20,6 +20,7 @@ """Library for interpreting Hemingway force spectroscopy files. """ +import os.path import numpy from .. import curve as curve @@ -35,6 +36,8 @@ class HemingwayDriver (Driver): super(HemingwayDriver, self).__init__(name='hemingway') def is_me(self, path): + if os.path.isdir(path): + return False headlines = [] with Closing(file(path, 'r')) as f: for i in range(2): diff --git a/hooke/driver/jpk.py b/hooke/driver/jpk.py index 2cbb852..31d9810 100644 --- a/hooke/driver/jpk.py +++ b/hooke/driver/jpk.py @@ -39,6 +39,8 @@ class JPKDriver (Driver): super(JPKDriver, self).__init__(name='jpk') def is_me(self, path): + if os.path.isdir(path): + return False if zipfile.is_zipfile(path): # JPK file versions since at least 0.5 with Closing(zipfile.ZipFile(path, 'r')) as f: if 'header.properties' not in f.namelist(): diff --git a/hooke/driver/mcs.py b/hooke/driver/mcs.py index 366e978..50a5029 100644 --- a/hooke/driver/mcs.py +++ b/hooke/driver/mcs.py @@ -99,6 +99,8 @@ class mcsDriver(lib.driver.Driver): return plot def is_me(self): + if os.path.isdir(path): + return False if self.filename[-3:].lower()=='mcs': return True else: diff --git a/hooke/driver/mfp1d.py b/hooke/driver/mfp1d.py index 7f9f2f8..2c314bd 100644 --- a/hooke/driver/mfp1d.py +++ b/hooke/driver/mfp1d.py @@ -210,6 +210,8 @@ class mfp1dDriver(lib.driver.Driver): self.filedata.close() def is_me(self): + if os.path.isdir(path): + return False if len(self.lines) < 34: return False diff --git a/hooke/driver/mfp1dexport.py b/hooke/driver/mfp1dexport.py index aefb5a5..174696b 100644 --- a/hooke/driver/mfp1dexport.py +++ b/hooke/driver/mfp1dexport.py @@ -21,6 +21,7 @@ """ import os +import os.path from .. import libhooke as lh from .. import curve as lhc @@ -48,6 +49,8 @@ class mfp1dexportDriver(lhc.Driver): self.filedata.close() def is_me(self): + if os.path.isdir(path): + return False try: self.raw_header = self.lines[0:38] except: diff --git a/hooke/driver/mfp3d.py b/hooke/driver/mfp3d.py index 63c1a28..5e5c58f 100644 --- a/hooke/driver/mfp3d.py +++ b/hooke/driver/mfp3d.py @@ -31,6 +31,7 @@ Hooke submission: Rolf Schmidt, Alberto Gomez-Casado 2009 """ import copy +import os.path import pprint import numpy @@ -53,6 +54,8 @@ class MFP3DDriver (Driver): def is_me(self, path): """Look for identifying fields in the IBW note. """ + if os.path.isdir(path): + return False if not path.endswith('.ibw'): return False targets = ['Version:', 'XOPVersion:', 'ForceNote:'] diff --git a/hooke/driver/picoforce.py b/hooke/driver/picoforce.py index 94339d4..1f1fefb 100644 --- a/hooke/driver/picoforce.py +++ b/hooke/driver/picoforce.py @@ -21,6 +21,7 @@ """Driver for Veeco PicoForce force spectroscopy files. """ +import os.path import pprint import re import time @@ -41,6 +42,8 @@ class PicoForceDriver (Driver): super(PicoForceDriver, self).__init__(name='picoforce') def is_me(self, path): + if os.path.isdir(path): + return False f = file(path, 'r') header = f.read(30) f.close() diff --git a/hooke/driver/tutorial.py b/hooke/driver/tutorial.py index 7dfb6e8..7fe5298 100644 --- a/hooke/driver/tutorial.py +++ b/hooke/driver/tutorial.py @@ -61,6 +61,8 @@ file format is as following:: that is, two plots with two datasets each. """ +import os.path + # The following are relative imports. See PEP 328 for details # http://www.python.org/dev/peps/pep-0328/ from .. import curve as curve # this module defines data containers. @@ -105,6 +107,8 @@ class TutorialDriver (Driver): Hooke to understand what kind of files we're looking at automatically. """ + if os.path.isdir(path): + return False f = open(path, 'r') header = f.readline() # we only need the first line diff --git a/hooke/driver/wtk.py b/hooke/driver/wtk.py index 2b536fa..b39bdd9 100644 --- a/hooke/driver/wtk.py +++ b/hooke/driver/wtk.py @@ -74,6 +74,8 @@ class WTKDriver (Driver): ] def is_me(self, path): + if os.path.isdir(path): + return False if not path.endswith('_unfold'): return False for p in self._paths(path): -- 2.26.2