Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor parseint refactoring, tweaks #684

Merged
merged 4 commits into from
Sep 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/galaxy/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,24 @@ def galaxy_directory():
return os.path.abspath(galaxy_root_path)


def parse_int(value, min_val=None, max_val=None, default=None, allow_none=False):
try:
value = int(value)
if min_val is not None and value < min_val:
return min_val
if max_val is not None and value > max_val:
return max_val
return value
except ValueError:
if allow_none:
if default is None or value == "None":
return None
if default:
return default
else:
raise


class ExecutionTimer(object):

def __init__(self):
Expand All @@ -1261,7 +1279,6 @@ def __str__(self):
elapsed = (time.time() - self.begin) * 1000.0
return "(%0.3f ms)" % elapsed


if __name__ == '__main__':
import doctest
doctest.testmod(sys.modules[__name__], verbose=False)
17 changes: 2 additions & 15 deletions lib/galaxy/webapps/galaxy/controllers/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from galaxy import web
from galaxy.model.item_attrs import UsesAnnotations
from galaxy.model.item_attrs import UsesItemRatings
from galaxy.util import nice_size, Params
from galaxy.util import nice_size, Params, parse_int
from galaxy.util.odict import odict
from galaxy.util.sanitize_html import sanitize_html
from galaxy.web import url_for
Expand Down Expand Up @@ -651,19 +651,6 @@ def view( self, trans, id=None, show_deleted=False, show_hidden=False, use_panel
user_is_owner=user_is_owner, history_is_current=history_is_current,
show_deleted=show_deleted, show_hidden=show_hidden, use_panels=use_panels )

def _parse_int( self, value, min=None, max=None, **kwargs ):
try:
value = int( value )
if min is not None and value < min:
return min
if max is not None and value > max:
return max
return value
except ValueError:
if 'default' in kwargs:
return kwargs.get( 'default' )
raise

# @web.require_login( "use more than one Galaxy history" )
@web.expose
def view_multiple( self, trans, include_deleted_histories=False, order='update_time', limit=10 ):
Expand All @@ -680,7 +667,7 @@ def view_multiple( self, trans, include_deleted_histories=False, order='update_t
# TODO: allow specifying user_id for admin?
include_deleted_histories = galaxy.util.string_as_bool( include_deleted_histories )
order_by = self.history_manager.parse_order_by( order, default='update_time' )
limit = self._parse_int( limit, min=1 ) if limit != 'None' else None
limit = parse_int( limit, min_val=1, default=10, allow_none=True)

deleted_filter = None
if not include_deleted_histories:
Expand Down