Skip to content

Commit

Permalink
Merge pull request ome#229 from manics/omero-entrypoint
Browse files Browse the repository at this point in the history
bin/omero entrypoint
  • Loading branch information
joshmoore authored Jul 9, 2020
2 parents 11ae6e3 + ebcf86e commit c347426
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 168 deletions.
122 changes: 0 additions & 122 deletions bin/omero

This file was deleted.

6 changes: 0 additions & 6 deletions bin/omero.bat

This file was deleted.

24 changes: 0 additions & 24 deletions bin/setpythonpath.bat

This file was deleted.

15 changes: 0 additions & 15 deletions bin/winconfig.bat

This file was deleted.

4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ def read(fname):
'omero.gateway': ['pilfonts/*'],
'omero.gateway.scripts': ['imgs/*']},
py_modules=packageless,
scripts=glob.glob(os.path.sep.join(["bin", "*"])),
entry_points={
'console_scripts': ['omero=omero.main:main'],
},
python_requires='>=3',
install_requires=[
'future',
Expand Down
129 changes: 129 additions & 0 deletions src/omero/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/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 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:
# This platform doesn't support effective uid
# So nothing to worry about.
return None


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]
if not os.path.exists(file) and sys.platform == 'win32':
file += '.exe'
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


def main():
not_root()

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:
print("Cancelled")
sys.exit(1)
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ commands =
rst-lint README.rst
python setup.py install
pytest {posargs:-n4 -m "not broken" --reruns 5 -rf test -s}
omero version

0 comments on commit c347426

Please sign in to comment.