Sha256: 49a4493329bf711e2a46430cf413eeb2ef0dc2c202fd870511202dfb608c768c

Contents?: true

Size: 1.71 KB

Versions: 53

Compression:

Stored size: 1.71 KB

Contents

#!/usr/bin/env python
# Copyright (c) 2011 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""These functions are executed via gyp-flock-tool when using the Makefile
generator.  Used on systems that don't have a built-in flock."""

import fcntl
import os
import struct
import subprocess
import sys


def main(args):
  executor = FlockTool()
  executor.Dispatch(args)


class FlockTool(object):
  """This class emulates the 'flock' command."""
  def Dispatch(self, args):
    """Dispatches a string command to a method."""
    if len(args) < 1:
      raise Exception("Not enough arguments")

    method = "Exec%s" % self._CommandifyName(args[0])
    getattr(self, method)(*args[1:])

  def _CommandifyName(self, name_string):
    """Transforms a tool name like copy-info-plist to CopyInfoPlist"""
    return name_string.title().replace('-', '')

  def ExecFlock(self, lockfile, *cmd_list):
    """Emulates the most basic behavior of Linux's flock(1)."""
    # Rely on exception handling to report errors.
    # Note that the stock python on SunOS has a bug
    # where fcntl.flock(fd, LOCK_EX) always fails
    # with EBADF, that's why we use this F_SETLK
    # hack instead.
    fd = os.open(lockfile, os.O_WRONLY|os.O_NOCTTY|os.O_CREAT, 0666)
    if sys.platform.startswith('aix'):
      # Python on AIX is compiled with LARGEFILE support, which changes the
      # struct size.
      op = struct.pack('hhIllqq', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
    else:
      op = struct.pack('hhllhhl', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
    fcntl.fcntl(fd, fcntl.F_SETLK, op)
    return subprocess.call(cmd_list)


if __name__ == '__main__':
  sys.exit(main(sys.argv[1:]))

Version data entries

53 entries across 46 versions & 18 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
disco_app-0.18.0 test/dummy/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
disco_app-0.18.2 test/dummy/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
tang-0.2.1 spec/tang_app/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
ruby2js-4.0.4 lib/tasks/testrails/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
ruby2js-4.0.3 lib/tasks/testrails/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
tang-0.2.0 spec/tang_app/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
tang-0.1.0 spec/tang_app/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
tang-0.0.9 spec/tang_app/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
enju_library-0.3.8 spec/dummy/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
ilog-0.4.1 node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
ilog-0.4.0 node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
ilog-0.3.3 node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
jester-data-8.0.0 node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
ezii-os-5.2.1 node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
ezii-os-2.0.1 node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
ezii-os-1.1.0 node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py
ezii-os-1.0.0 node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py