MCPcopy Create free account
hub / github.com/nodejs/node / FlockTool

Class FlockTool

tools/gyp/pylib/gyp/flock_tool.py:21–51  ·  view source on GitHub ↗

This class emulates the 'flock' command.

Source from the content-addressed store, hash-verified

19
20
21class FlockTool:
22 """This class emulates the 'flock' command."""
23
24 def Dispatch(self, args):
25 """Dispatches a string command to a method."""
26 if len(args) < 1:
27 raise Exception("Not enough arguments")
28
29 method = "Exec%s" % self._CommandifyName(args[0])
30 getattr(self, method)(*args[1:])
31
32 def _CommandifyName(self, name_string):
33 """Transforms a tool name like copy-info-plist to CopyInfoPlist"""
34 return name_string.title().replace("-", "")
35
36 def ExecFlock(self, lockfile, *cmd_list):
37 """Emulates the most basic behavior of Linux's flock(1)."""
38 # Rely on exception handling to report errors.
39 # Note that the stock python on SunOS has a bug
40 # where fcntl.flock(fd, LOCK_EX) always fails
41 # with EBADF, that's why we use this F_SETLK
42 # hack instead.
43 fd = os.open(lockfile, os.O_WRONLY | os.O_NOCTTY | os.O_CREAT, 0o666)
44 if sys.platform.startswith("aix") or sys.platform == "os400":
45 # Python on AIX is compiled with LARGEFILE support, which changes the
46 # struct size.
47 op = struct.pack("hhIllqq", fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
48 else:
49 op = struct.pack("hhllhhl", fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
50 fcntl.fcntl(fd, fcntl.F_SETLK, op)
51 return subprocess.call(cmd_list)
52
53
54if __name__ == "__main__":

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected