3 # Thomas Nagy, 2014 (ita)
6 This module enables automatic handling of network paths of the form \\server\share for both input
7 and output files. While a typical script may require the following::
12 node = bld.root.make_node('\\\\COMPUTER\\share\\test.txt')
14 # mark the server/share levels as folders
20 # clear the file if removed
21 if not os.path.isfile(node.abspath()):
24 # create the folder structure
25 if node.parent.height() > 2:
28 # then the task generator
30 tsk.outputs[0].write("data")
31 bld(rule=myfun, source='wscript', target=[nd])
33 this tool will make the process much easier, for example::
36 conf.load('unc') # do not import the module directly
40 tsk.outputs[0].write("data")
41 bld(rule=myfun, update_outputs=True,
43 target='\\\\COMPUTER\\share\\test.txt')
44 bld(rule=myfun, update_outputs=True,
45 source='\\\\COMPUTER\\share\\test.txt',
46 target='\\\\COMPUTER\\share\\test2.txt')
50 from waflib
import Node
, Utils
, Context
52 def find_resource(self
, lst
):
53 if isinstance(lst
, str):
54 lst
= [x
for x
in Node
.split_path(lst
) if x
and x
!= '.']
56 if lst
[0].startswith('\\\\'):
59 node
= self
.ctx
.root
.make_node(lst
[0]).make_node(lst
[1])
60 node
.cache_isdir
= True
61 node
.parent
.cache_isdir
= True
63 ret
= node
.search_node(lst
[2:])
65 ret
= node
.find_node(lst
[2:])
66 if ret
and os
.path
.isdir(ret
.abspath()):
70 return self
.find_resource_orig(lst
)
72 def find_or_declare(self
, lst
):
73 if isinstance(lst
, str):
74 lst
= [x
for x
in Node
.split_path(lst
) if x
and x
!= '.']
76 if lst
[0].startswith('\\\\'):
79 node
= self
.ctx
.root
.make_node(lst
[0]).make_node(lst
[1])
80 node
.cache_isdir
= True
81 node
.parent
.cache_isdir
= True
82 ret
= node
.find_node(lst
[2:])
84 ret
= node
.make_node(lst
[2:])
85 if not os
.path
.isfile(ret
.abspath()):
90 return self
.find_or_declare_orig(lst
)
93 """For MAX_PATH limitations"""
94 ret
= self
.abspath_orig()
95 if not ret
.startswith("\\"):
96 return "\\\\?\\" + ret
100 Node
.Node
.find_resource_orig
= Node
.Node
.find_resource
101 Node
.Node
.find_resource
= find_resource
103 Node
.Node
.find_or_declare_orig
= Node
.Node
.find_or_declare
104 Node
.Node
.find_or_declare
= find_or_declare
106 Node
.Node
.abspath_orig
= Node
.Node
.abspath
107 Node
.Node
.abspath
= abspath
109 for k
in list(Context
.cache_modules
.keys()):
110 Context
.cache_modules
["\\\\?\\" + k
] = Context
.cache_modules
[k
]