-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathodectl
executable file
·148 lines (129 loc) · 4.49 KB
/
odectl
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2018 Bhojpur Consulting Private Limited, India. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import logging
import os
import stat
import sys
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
# Assuming a Bhojpur ODE CLI user never wants to see development details
# such as: source code that has been deprecated.
def not_root():
"""
Check that the effective current user is not 0
on systems supporting os.geteuid()
"""
try:
euid = os.geteuid()
if euid == 0:
print("FATAL: Running %s as root can corrupt your directory permissions." % sys.argv[0])
sys.exit(1)
else:
return euid
except AttributeError as ae:
# This platform doesn't support effective uid
# So nothing to worry about.
return None
euid = not_root()
def readlink(file=sys.argv[0]):
"""
Resolve symlinks and similar. This is useful to allow
linking this file under /usr/bin/, for example.
"""
import stat
file = sys.argv[0]
while stat.S_ISLNK(os.lstat(file)[stat.ST_MODE]):
target = os.readlink(file)
if target[0] != "/":
file = os.path.join(os.path.dirname(file), target)
else:
file = target
file = os.path.abspath(file)
return file
print("Bhojpur ODE client engine (python)")
print("Copyright (c) 2018 by Bhojpur Consulting Private Limited, India.")
print("All rights reserved.\n")
ode_home = None
if os.environ.__contains__("ODE_HOME"):
ode_home = os.environ["ODE_HOME"]
if not os.path.exists(ode_home):
print("ODE_HOME=%s cannot be found" % ode_home)
sys.exit(3)
if ode_home:
top = ode_home
else:
exe = readlink()
top = os.path.join(exe, os.pardir, os.pardir)
#
# This list needs to be kept in line with ode.cli.CLI._env
#
top = os.path.normpath(top)
lib = os.path.join(top, "pkg","client")
lpy = os.path.join(top, "pkg","client","python")
ipy = os.path.join(top, "pkg","client","fallback")
var = os.path.join(top, "var")
vlb = os.path.join(var, "lib",)
sys.path.insert(0,vlb);
sys.path.insert(0,lpy);
sys.path.append(ipy)
if not os.path.exists(lib):
print("WARN: %s does not exist. It is unlikely that Bhojpur ODE will run properly" % lib)
#
# Testing shortcut. If the first argument is an
# empty string, exit sucessfully.
#
if len(sys.argv) == 2 and sys.argv[1] == "": sys.exit(0)
#
# Primary activity: import ode.cli and launch
# catching any Ctrl-Cs from the user
#
try:
try:
import ode.cli
except ImportError as ie:
print("*"*80)
print("""
ERROR: Could not import Bhojpur ODE (ode.cli) (%s)
This means that your installation is incomplete. Contact
the Bhojpur ODE mailing lists for more information:
https://desk.bhojpur-consulting.com/
If you are building from source, please supply the build log
as well as which version you are building from. If you
downloaded a distribution, please provide which link you
used.
""" % ie)
print("*"*80)
print("""
Debugging Info:
--------------
CWD=%s
VERSION=%s
ODE_HOME=%s
PYTHONPATH=%s
""" % (os.getcwd(), sys.version.replace("\n"," "), ode_home, sys.path))
sys.exit(2)
logging.basicConfig(level=logging.WARN)
rv = ode.cli.argv()
sys.exit(rv)
except KeyboardInterrupt as ki:
print("Cancelled")
sys.exit(1)