File: pythoncmd

package info (click to toggle)
brltty 6.8-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,776 kB
  • sloc: ansic: 150,447; java: 13,484; sh: 9,667; xml: 5,702; tcl: 2,634; makefile: 2,328; awk: 713; lisp: 366; python: 321; ml: 301
file content (119 lines) | stat: -rwxr-xr-x 3,158 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
###############################################################################
# libbrlapi - A library providing access to braille terminals for applications.
#
# Copyright (C) 2005-2025 by
#   Alexis Robert <alexissoft@free.fr>
#   Samuel Thibault <Samuel.Thibault@ens-lyon.org>
#
# libbrlapi comes with ABSOLUTELY NO WARRANTY.
#
# This is free software, placed under the terms of the
# GNU Lesser General Public License, as published by the Free Software
# Foundation; either version 2.1 of the License, or (at your option) any
# later version. Please see the file LICENSE-LGPL for details.
#
# Web Page: http://brltty.app/
#
# This software is maintained by Dave Mielke <dave@mielke.cc>.
###############################################################################

import sys
import os

def putProgramMessage(message):
  sys.stderr.write("%s: %s%s" % (programName, message, os.linesep))

def syntaxError(message):
  putProgramMessage(message)
  sys.exit(2)

def nextProgramArgument():
  return sys.argv.pop(0)

def verifyNoMoreProgramArguments():
  if (len(sys.argv) > 0):
    syntaxError("too many parameters")

programPath = nextProgramArgument()
programName = os.path.basename(programPath)

try:
  actionName = nextProgramArgument()
except IndexError:
  syntaxError("action not specified")

try:
  import sysconfig
# putProgramMessage("sysconfig")
  if hasattr(sysconfig, 'get_default_scheme'):
    scheme = sysconfig.get_default_scheme()
  else:
    scheme = sysconfig._get_default_scheme()

  if scheme == 'posix_local':
    # Debian's default scheme installs to /usr/local/ but we want to find headers in /usr/
    scheme = 'posix_prefix'

  def getIncludeDirectory():
    return sysconfig.get_path("include", scheme)

  def getLibraryDirectory():
    return sysconfig.get_path("stdlib", scheme)

  def getPackageDirectory():
    return sysconfig.get_path("platlib", scheme)

  def getConfigurationVariable(name):
    return sysconfig.get_config_var(name)

except ModuleNotFoundError:
  from distutils import sysconfig
# putProgramMessage("distutils")

  def getIncludeDirectory():
    return sysconfig.get_python_inc()

  def getLibraryDirectory():
    return sysconfig.get_python_lib(0, 1)

  def getPackageDirectory():
    return sysconfig.get_python_lib(True, False)

  def getConfigurationVariable(name):
    return sysconfig.get_config_var(name)

class ActionHanlers:
  def version():
    verifyNoMoreProgramArguments()
    print(sys.version_info[0])

  def incdir():
    verifyNoMoreProgramArguments()
    print(getIncludeDirectory())

  def libdir():
    verifyNoMoreProgramArguments()
    print(getLibraryDirectory())

  def pkgdir():
    verifyNoMoreProgramArguments()
    print(getPackageDirectory())

  def libopts():
    verifyNoMoreProgramArguments()
    print(getConfigurationVariable("LIBS"))

  def linkopts():
    verifyNoMoreProgramArguments()
    print(getConfigurationVariable("LINKFORSHARED"))

actionHandlers = globals()["ActionHanlers"]

try:
  actionHandler = getattr(actionHandlers, actionName)
except AttributeError:
  syntaxError("unknown action: %s" % actionName)

actionHandler()
sys.exit(0)