~hjd/ubuntu/wily/gyp/debian-merged

« back to all changes in this revision

Viewing changes to pylib/gyp/sun_tool.py

  • Committer: Hans Joachim Desserud
  • Date: 2015-10-31 12:46:59 UTC
  • mfrom: (6.2.6 sid)
  • Revision ID: hans_joachim_desserud-20151031124659-lzxekr6woskh4k0b
Merge latest Debian version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# Copyright (c) 2011 Google Inc. All rights reserved.
3
 
# Use of this source code is governed by a BSD-style license that can be
4
 
# found in the LICENSE file.
5
 
 
6
 
"""These functions are executed via gyp-sun-tool when using the Makefile
7
 
generator."""
8
 
 
9
 
import fcntl
10
 
import os
11
 
import struct
12
 
import subprocess
13
 
import sys
14
 
 
15
 
 
16
 
def main(args):
17
 
  executor = SunTool()
18
 
  executor.Dispatch(args)
19
 
 
20
 
 
21
 
class SunTool(object):
22
 
  """This class performs all the SunOS tooling steps. The methods can either be
23
 
  executed directly, or dispatched from an argument list."""
24
 
 
25
 
  def Dispatch(self, args):
26
 
    """Dispatches a string command to a method."""
27
 
    if len(args) < 1:
28
 
      raise Exception("Not enough arguments")
29
 
 
30
 
    method = "Exec%s" % self._CommandifyName(args[0])
31
 
    getattr(self, method)(*args[1:])
32
 
 
33
 
  def _CommandifyName(self, name_string):
34
 
    """Transforms a tool name like copy-info-plist to CopyInfoPlist"""
35
 
    return name_string.title().replace('-', '')
36
 
 
37
 
  def ExecFlock(self, lockfile, *cmd_list):
38
 
    """Emulates the most basic behavior of Linux's flock(1)."""
39
 
    # Rely on exception handling to report errors.
40
 
    # Note that the stock python on SunOS has a bug
41
 
    # where fcntl.flock(fd, LOCK_EX) always fails
42
 
    # with EBADF, that's why we use this F_SETLK
43
 
    # hack instead.
44
 
    fd = os.open(lockfile, os.O_WRONLY|os.O_NOCTTY|os.O_CREAT, 0666)
45
 
    op = struct.pack('hhllhhl', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0)
46
 
    fcntl.fcntl(fd, fcntl.F_SETLK, op)
47
 
    return subprocess.call(cmd_list)
48
 
 
49
 
 
50
 
if __name__ == '__main__':
51
 
  sys.exit(main(sys.argv[1:]))