jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.7KB

  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2014 (ita)
  4. """
  5. This module enables automatic handling of network paths of the form \\server\share for both input
  6. and output files. While a typical script may require the following::
  7. import os
  8. def build(bld):
  9. node = bld.root.make_node('\\\\COMPUTER\\share\\test.txt')
  10. # mark the server/share levels as folders
  11. k = node.parent
  12. while k:
  13. k.cache_isdir = True
  14. k = k.parent
  15. # clear the file if removed
  16. if not os.path.isfile(node.abspath()):
  17. node.sig = None
  18. # create the folder structure
  19. if node.parent.height() > 2:
  20. node.parent.mkdir()
  21. # then the task generator
  22. def myfun(tsk):
  23. tsk.outputs[0].write("data")
  24. bld(rule=myfun, source='wscript', target=[nd])
  25. this tool will make the process much easier, for example::
  26. def configure(conf):
  27. conf.load('unc') # do not import the module directly
  28. def build(bld):
  29. def myfun(tsk):
  30. tsk.outputs[0].write("data")
  31. bld(rule=myfun, update_outputs=True,
  32. source='wscript',
  33. target='\\\\COMPUTER\\share\\test.txt')
  34. bld(rule=myfun, update_outputs=True,
  35. source='\\\\COMPUTER\\share\\test.txt',
  36. target='\\\\COMPUTER\\share\\test2.txt')
  37. """
  38. import os
  39. from waflib import Node, Utils, Context
  40. def find_resource(self, lst):
  41. if isinstance(lst, str):
  42. lst = [x for x in Node.split_path(lst) if x and x != '.']
  43. if lst[0].startswith('\\\\'):
  44. if len(lst) < 3:
  45. return None
  46. node = self.ctx.root.make_node(lst[0]).make_node(lst[1])
  47. node.cache_isdir = True
  48. node.parent.cache_isdir = True
  49. ret = node.search_node(lst[2:])
  50. if not ret:
  51. ret = node.find_node(lst[2:])
  52. if ret and os.path.isdir(ret.abspath()):
  53. return None
  54. return ret
  55. return self.find_resource_orig(lst)
  56. def find_or_declare(self, lst):
  57. if isinstance(lst, str):
  58. lst = [x for x in Node.split_path(lst) if x and x != '.']
  59. if lst[0].startswith('\\\\'):
  60. if len(lst) < 3:
  61. return None
  62. node = self.ctx.root.make_node(lst[0]).make_node(lst[1])
  63. node.cache_isdir = True
  64. node.parent.cache_isdir = True
  65. ret = node.find_node(lst[2:])
  66. if not ret:
  67. ret = node.make_node(lst[2:])
  68. if not os.path.isfile(ret.abspath()):
  69. ret.sig = None
  70. ret.parent.mkdir()
  71. return ret
  72. return self.find_or_declare_orig(lst)
  73. def abspath(self):
  74. """For MAX_PATH limitations"""
  75. ret = self.abspath_orig()
  76. if not ret.startswith("\\"):
  77. return "\\\\?\\" + ret
  78. return ret
  79. if Utils.is_win32:
  80. Node.Node.find_resource_orig = Node.Node.find_resource
  81. Node.Node.find_resource = find_resource
  82. Node.Node.find_or_declare_orig = Node.Node.find_or_declare
  83. Node.Node.find_or_declare = find_or_declare
  84. Node.Node.abspath_orig = Node.Node.abspath
  85. Node.Node.abspath = abspath
  86. for k in list(Context.cache_modules.keys()):
  87. Context.cache_modules["\\\\?\\" + k] = Context.cache_modules[k]