Skip to content

Commit

Permalink
Merge pull request #1685 from sbesson/2591_cli_flake8
Browse files Browse the repository at this point in the history
Run flake8 on all the CLI plugins
  • Loading branch information
joshmoore committed Nov 5, 2013
2 parents f518bb8 + a656b0c commit ef1b841
Show file tree
Hide file tree
Showing 25 changed files with 1,717 additions and 1,047 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: java

env:
- BUILD="build-all" TEST="-p"
- BUILD="build-default test-compile" TEST="-py test -Dtest.with.fail=true"
- BUILD="build-all test-compile-all" TEST="-cpp test -Dtest.with.fail=true"
- BUILD=all BUILD_TARGET="build-all" TEST_TARGET="-p"
- BUILD=py BUILD_TARGET="build-default test-compile" TEST_TARGET="-py test -Dtest.with.fail=true"
- BUILD=cpp BUILD_TARGET="build-all test-compile-all" TEST_TARGET="-cpp test -Dtest.with.fail=true"

jdk:
- openjdk7
Expand All @@ -18,9 +18,11 @@ before_install:
- git config --global user.name 'Snoopy Crime Cop'
- sudo pip install scc --use-mirrors
- scc travis-merge
- if [[ $BUILD == 'py' ]]; then sudo pip install flake8 --use-mirrors; fi

install: python build.py $BUILD
install: python build.py $BUILD_TARGET

# Running python tests as script, since there's no compile step.
script:
- python build.py $TEST
- if [[ $BUILD == 'py' ]]; then flake8 -v components/tools/OmeroPy/src/omero/plugins; fi
- python build.py $TEST_TARGET
559 changes: 353 additions & 206 deletions components/tools/OmeroPy/src/omero/plugins/admin.py

Large diffs are not rendered by default.

41 changes: 27 additions & 14 deletions components/tools/OmeroPy/src/omero/plugins/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class QuitControl(BaseControl):

def __call__(self, args):
self.ctx.exit("", newline = False)
self.ctx.exit("", newline=False)


class VersionControl(BaseControl):
Expand All @@ -42,7 +42,8 @@ def __call__(self, args):
class LoadControl(BaseControl):

def _configure(self, parser):
parser.add_argument("infile", nargs="*", type=FileType("r"), default=[sys.stdin])
parser.add_argument("infile", nargs="*", type=FileType("r"),
default=[sys.stdin])
parser.set_defaults(func=self.__call__)

def __call__(self, args):
Expand All @@ -55,7 +56,9 @@ def __call__(self, args):
class ShellControl(BaseControl):

def _configure(self, parser):
parser.add_argument("--login", action="store_true", help="Logins in and sets the 'client' variable")
parser.add_argument(
"--login", action="store_true",
help="Logins in and sets the 'client' variable")
parser.add_argument("arg", nargs="*", help="Arguments for IPython.")
parser.set_defaults(func=self.__call__)

Expand All @@ -75,13 +78,13 @@ def __call__(self, args):
if args.login:
import omero
client = self.ctx.conn(args)
ns = {"client": client, "omero":omero}
ns = {"client": client, "omero": omero}

try:
# IPython 0.11 (see #7112)
from IPython import embed
embed(user_ns=ns)
except ImportError, ie:
except ImportError:
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed(args.arg)
ipshell(local_ns=ns)
Expand All @@ -94,10 +97,12 @@ class HelpControl(BaseControl):
"""

def _configure(self, parser):
self.__parser__ = parser # For formatting later
self.__parser__ = parser # For formatting later
parser.set_defaults(func=self.__call__)
parser.add_argument("--all", action="store_true", help="Print help for all topics")
parser.add_argument("topic", nargs="?", help="Topic for more information")
parser.add_argument(
"--all", action="store_true", help="Print help for all topics")
parser.add_argument(
"topic", nargs="?", help="Topic for more information")

def _complete(self, text, line, begidx, endidx):
"""
Expand All @@ -110,9 +115,12 @@ def _complete(self, text, line, begidx, endidx):
def __call__(self, args):

self.ctx.waitForPlugins()
#commands = "\n".join([" %s" % name for name in sorted(self.ctx.controls)])
#commands = "\n".join([" %s" % name for name in
#sorted(self.ctx.controls)])
#topics = "\n".join([" %s" % topic for topic in self.ctx.topics])
commands, topics = [self.__parser__._format_list(x) for x in [sorted(self.ctx.controls), sorted(self.ctx.topics)]]
commands, topics = [
self.__parser__._format_list(x) for x in
[sorted(self.ctx.controls), sorted(self.ctx.topics)]]

if args.all:
for control in sorted(self.ctx.controls):
Expand All @@ -129,6 +137,8 @@ def __call__(self, args):
self.ctx.out("\n")
elif not args.topic:
#self.ctx.invoke("-h")
key_list = {"program_name": sys.argv[0], "version": VERSION,
"commands": commands, "topics": topics}
print """usage: %(program_name)s <command> [options] args
See 'help <command>' or '<command> -h' for more information on syntax
Type 'quit' to exit
Expand All @@ -139,15 +149,18 @@ def __call__(self, args):
Other help topics:
%(topics)s
For additional information, see http://trac.openmicroscopy.org.uk/ome/wiki/OmeroCli
For additional information, see:
http://www.openmicroscopy.org/site/support/omero4/users/\
command-line-interface.html
Report bugs to <ome-users@lists.openmicroscopy.org.uk>
""" % {"program_name":sys.argv[0],"version":VERSION, "commands":commands, "topics":topics}
""" % key_list

else:
try:
c = self.ctx.controls[args.topic]
print 1
self.ctx.controls[args.topic]
self.ctx.invoke("%s -h" % args.topic)
except KeyError, ke:
except KeyError:
try:
self.ctx.out(self.ctx.topics[args.topic])
except KeyError:
Expand Down
78 changes: 48 additions & 30 deletions components/tools/OmeroPy/src/omero/plugins/cecog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@
import re
import sys

from omero.cli import BaseControl, CLI, OMERODIR
from omero_ext.argparse import FileType
from omero.cli import BaseControl, CLI

import omero
import omero.constants

from omero.rtypes import *
from omero.rtypes import rstring


class CecogControl(BaseControl):
"""CeCog integration plugin.
Provides actions for prepairing data and otherwise
integrating with Cecog. See the Run_Cecog_4.1.py
script.
Provides actions for prepairing data and otherwise integrating with Cecog. See
the Run_Cecog_4.1.py script.
"""

# [MetaMorph_PlateScanPackage]
Expand All @@ -45,8 +43,11 @@ def _configure(self, parser):
merge.add_argument("path", help="Path to image files")

rois = parser.add(sub, self.rois, self.rois.__doc__)
rois.add_argument("-f", "--file", required=True, help="Details file to be parsed")
rois.add_argument("-i", "--image", required=True, help="Image id which should have ids attached")
rois.add_argument(
"-f", "--file", required=True, help="Details file to be parsed")
rois.add_argument(
"-i", "--image", required=True,
help="Image id which should have ids attached")

for x in (merge, rois):
x.add_login_arguments()
Expand All @@ -57,28 +58,36 @@ def _configure(self, parser):
def merge(self, args):
"""Uses PIL to read multiple planes from a local folder.
Planes are combined and uploaded to OMERO as new images with additional T, C, Z dimensions.
Planes are combined and uploaded to OMERO as new images with additional T, C,
Z dimensions.
It should be run as a local script (not via scripting service) in order that it has
access to the local users file system. Therefore need EMAN2 or PIL installed locally.
It should be run as a local script (not via scripting service) in order that
it has access to the local users file system. Therefore need EMAN2 or PIL
installed locally.
Example usage:
will$ bin/omero cecog merge /Applications/CecogPackage/Data/Demo_data/0037/
$ bin/omero cecog merge /Applications/CecogPackage/Data/Demo_data/0037/
Since this dir does not contain folders, this will upload images in '0037' into a Dataset called Demo_data
in a Project called 'Data'.
Since this dir does not contain folders, this will upload images in '0037'
into a Dataset called Demo_data in a Project called 'Data'.
will$ bin/omero cecog merge /Applications/CecogPackage/Data/Demo_data/
$ bin/omero cecog merge /Applications/CecogPackage/Data/Demo_data/
Since this dir does contain folders, this will look for images in all subdirectories of 'Demo_data' and
upload images into a Dataset called Demo_data in a Project called 'Data'.
Since this dir does contain folders, this will look for images in all
subdirectories of 'Demo_data' and upload images into a Dataset called
Demo_data in a Project called 'Data'.
Images will be combined in Z, C and T according to the MetaMorph_PlateScanPackage naming convention.
E.g. tubulin_P0037_T00005_Cgfp_Z1_S1.tiff is Point 37, Timepoint 5, Channel gfp, Z 1. S?
see /Applications/CecogPackage/CecogAnalyzer.app/Contents/Resources/resources/naming_schemes.conf
Images will be combined in Z, C and T according to the \
MetaMorph_PlateScanPackage naming convention.
E.g. tubulin_P0037_T00005_Cgfp_Z1_S1.tiff is Point 37, Timepoint 5, Channel \
gfp, Z 1. S?
see \
/Applications/CecogPackage/CecogAnalyzer.app/Contents/Resources/resources/\
naming_schemes.conf
"""
"""
Processes the command args, makes project and dataset then calls uploadDirAsImages() to process and
Processes the command args, makes project and dataset then calls
uploadDirAsImages() to process and
upload the images to OMERO.
"""
from omero.rtypes import unwrap
Expand All @@ -90,7 +99,8 @@ def merge(self, args):
updateService = client.sf.getUpdateService()
pixelsService = client.sf.getPixelsService()

# if we don't have any folders in the 'dir' E.g. CecogPackage/Data/Demo_data/0037/
# if we don't have any folders in the 'dir' E.g.
# CecogPackage/Data/Demo_data/0037/
# then 'Demo_data' becomes a dataset
subDirs = []
for f in os.listdir(path):
Expand All @@ -111,7 +121,8 @@ def merge(self, args):
p = p[:-1]
p = os.path.dirname(p)
projectName = os.path.basename(p) # e.g. Data
self.ctx.err("Putting images in Project: %s Dataset: %s" % (projectName, datasetName))
self.ctx.err("Putting images in Project: %s Dataset: %s"
% (projectName, datasetName))

# create dataset
dataset = omero.model.DatasetI()
Expand All @@ -130,35 +141,42 @@ def merge(self, args):
if len(subDirs) > 0:
for subDir in subDirs:
self.ctx.err("Processing images in %s" % subDir)
rv = uploadDirAsImages(client.sf, queryService, updateService, pixelsService, subDir, dataset)
rv = uploadDirAsImages(client.sf, queryService, updateService,
pixelsService, subDir, dataset)
self.ctx.out("%s" % unwrap(rv))

# if there are no sub-directories, just put all the images in the dir
else:
self.ctx.err("Processing images in %s" % path)
rv = uploadDirAsImages(client.sf, queryService, updateService, pixelsService, path, dataset)
rv = uploadDirAsImages(client.sf, queryService, updateService,
pixelsService, path, dataset)
self.ctx.out("%s" % unwrap(rv))

def rois(self, args):
"""Parses an object_details text file, as generated by CeCog Analyzer and saves the data as ROIs on an Image in OMERO.
"""Parses an object_details text file, as generated by CeCog Analyzer
and saves the data as ROIs on an Image in OMERO.
Text file is of the form:
frame objID classLabel className centerX centerY mean sd
1 10 6 lateana 1119 41 76.8253796095 54.9305640673
1 10 6 lateana 1119 41 76.8253796095 \
54.9305640673
Example usage:
bin/omero cecog rois -f Data/Demo_output/analyzed/0037/statistics/P0037__object_details.txt -i 502
bin/omero cecog rois -f \
Data/Demo_output/analyzed/0037/statistics/P0037__object_details.txt -i 502
"""
"""
Processes the command args, parses the object_details.txt file and creates ROIs on the image specified in OMERO
Processes the command args, parses the object_details.txt file and
creates ROIs on the image specified in OMERO
"""
from omero.util.script_utils import uploadCecogObjectDetails
filePath = args.file
imageId = args.image
if not os.path.exists(filePath):
self.ctx.die(654, "Could find the object_details file at %s" % filePath)
self.ctx.die(654, "Could find the object_details file at %s"
% filePath)

client = self.ctx.conn(args)
updateService = client.sf.getUpdateService()
Expand Down
38 changes: 25 additions & 13 deletions components/tools/OmeroPy/src/omero/plugins/chgrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,37 @@
defined here will be added to the Cli class for later use.
"""

from omero.cli import BaseControl, CLI, GraphControl, ExperimenterGroupArg
from omero.cli import CLI, GraphControl, ExperimenterGroupArg
import sys

HELP="""Move data between groups
HELP = """Move data between groups
Example Usage:
omero chgrp 101 /Image:1 # Move all of Image 1 to group 101
omero chgrp Group:101 /Image:1 # Move all of Image 1 to group 101
omero chgrp ExperimenterGroup:101 /Image:1 # Move all of Image 1 to group 101
omero chgrp "My Lab" /Image:1 # Move all of Image 1 to group "myLab"
omero chgrp --edit 101 /Image:1 # Open an editor with all the chgrp
# options filled out with defaults.
omero chgrp --opt /Image:KEEP /Plate:1 # Calls chgrp on Plate, leaving all
omero chgrp 101 /Image:1 # Move all of Image 1 to \
group 101
omero chgrp Group:101 /Image:1 # Move all of Image 1 to \
group 101
omero chgrp ExperimenterGroup:101 /Image:1 # Move all of Image 1 to \
group 101
omero chgrp "My Lab" /Image:1 # Move all of Image 1 to \
group "myLab"
omero chgrp --edit 101 /Image:1 # Open an editor with all \
the chgrp
# options filled out with \
defaults.
omero chgrp --opt /Image:KEEP /Plate:1 # Calls chgrp on Plate, \
leaving all
# images in the previous group.
What data is moved is the same as that which would be deleted by a similar
call to "omero delete /Image:1"
"""


class ChgrpControl(GraphControl):

def cmd_type(self):
Expand All @@ -44,7 +52,9 @@ def cmd_type(self):
return omero.cmd.Chgrp

def _pre_objects(self, parser):
parser.add_argument("grp", nargs="?", type=ExperimenterGroupArg, help="""Group to move objects to""")
parser.add_argument(
"grp", nargs="?", type=ExperimenterGroupArg,
help="""Group to move objects to""")

def _process_request(self, req, args, client):
req.grp = args.grp.lookup(client)
Expand All @@ -57,7 +67,9 @@ def create_error_report(self, rsp):
if isinstance(rsp, omero.cmd.GraphConstraintERR):
if "Fileset" in rsp.constraints:
fileset = rsp.constraints.get("Fileset")
return "You cannot move part of fileset %s; only complete filesets can be moved to another group.\n" % ", ".join(str(x) for x in fileset)
return "You cannot move part of fileset %s; only complete" \
" filesets can be moved to another group.\n" % \
", ".join(str(x) for x in fileset)
else:
return super(ChgrpControl, self).create_error_report(rsp)
else:
Expand Down

0 comments on commit ef1b841

Please sign in to comment.