0 1 0
default
Jean-Francois Pieronne - 14 months ago 2018-11-06 11:10:49
jf.pieronne@laposte.net
lib$find file return a file with NLA0: device, fix this
1 file changed with 13 insertions and 5 deletions:
↑ Collapse Diff ↑
1
 
from vms import descrip, rmsdef
1
 
from vms import descrip, rmsdef, dvidef, devdef
2
 
from vms.rtl import lib
2 3
 
import ctypes
3 4
 

	
4 5
 

	
...
 
@@ -8,11 +9,12 @@ vms_find_file = getattr(LIBRTL,"LIB$FIND
8 9
 
vms_find_file_end = getattr(LIBRTL,"LIB$FIND_FILE_END")
9 10
 
vms_trim_filespec = getattr(LIBRTL,"LIB$TRIM_FILESPEC")
10 11
 

	
11
 
LIB_M_FIL_LONG_NAMES = 2
12
 
LIB_M_FIL_LONG_NAMES = 4
12 13
 
NAML_C_MAXRSS = 4095
13 14
 

	
14 15
 
class FindFile(object):
15
 
    def __init__(self, filespec, default_filespec=None):
16
 
    def __init__(self, filespec, default_filespec=None,
17
 
                 flags=LIB_M_FIL_LONG_NAMES):
16 18
 
        self.filespec = ctypes.create_string_buffer(filespec)
17 19
 
        self.default_filespec = None if default_filespec is None else \
18 20
 
          descrip.bydesc(ctypes.create_string_buffer(default_filespec))
...
 
@@ -20,7 +22,7 @@ class FindFile(object):
20 22
 
             ctypes.create_string_buffer(NAML_C_MAXRSS + 1)
21 23
 
        self.context = ctypes.c_uint32()
22 24
 
        self.nullArg = ctypes.c_voidp()
23
 
        self.flags = ctypes.c_uint(LIB_M_FIL_LONG_NAMES)
25
 
        self.flags = ctypes.c_uint(flags)
24 26
 
        self.new_filespec = ctypes.create_string_buffer(NAML_C_MAXRSS + 1)
25 27
 
        self.resultant_length = ctypes.c_uint16()
26 28
 

	
...
 
@@ -48,7 +50,13 @@ class FindFile(object):
48 50
 
                              descrip.bydesc(self.new_filespec),
49 51
 
                              self.nullArg,
50 52
 
                              ctypes.byref(self.resultant_length))
51
 
        return self.new_filespec[:self.resultant_length.value]
53
 
        res = self.new_filespec[:self.resultant_length.value]
54
 
        # Check if the device is file oriented, lib$find_file return a file if
55
 
        # a device like NLA0: is used
56
 
        if (lib.getdvi(dvidef.DVI__DEVCHAR, device_name=res)[1] &
57
 
             devdef.DEV_M_FOD) == 0:
58
 
            raise StopIteration
59
 
        return res
52 60
 
     
53 61
 
    def next(self):
54 62
 
        return self.__next__()
0 comments (0 inline, 0 general)