forked from ome/omero-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
omero
executable file
·122 lines (101 loc) · 2.98 KB
/
omero
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
#!/usr/bin/env python
"""
:author: Josh Moore <[email protected]>
Python driver for OMERO
Copyright (c) 2007, Glencoe Software, Inc.
See LICENSE for details.
"""
from __future__ import print_function
import logging
import os
import stat
import sys
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
# Assuming a CLI user never wants to see development details
# such as 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
if "OMERO_HOME" in os.environ:
print("WARN: OMERO_HOME usage is ignored in omero-py")
exe = readlink()
top = os.path.join(exe, os.pardir, os.pardir)
#
# This list needs to be kept in line with omero.cli.CLI._env
#
top = os.path.normpath(top)
var = os.path.join(top, "var")
vlb = os.path.join(var, "lib")
sys.path.append(vlb);
# 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 omero.cli and launch
# catching any Ctrl-Cs from the user
#
try:
try:
import omero.cli
except ImportError as ie:
OMERODIR = os.environ.get('OMERODIR', None)
print("*"*80)
print("""
ERROR: Could not import omero.cli! (%s)
This means that your installation is incomplete. Contact
the OME mailing lists for more information:
https://www.openmicroscopy.org/support/
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
OMERO_EXE=%s
OMERODIR=%s
PYTHONPATH=%s
""" % (os.getcwd(), sys.version.replace("\n", " "), top,
OMERODIR, sys.path))
sys.exit(2)
logging.basicConfig(level=logging.WARN)
rv = omero.cli.argv()
sys.exit(rv)
except KeyboardInterrupt as ki:
print("Cancelled")
sys.exit(1)