commit/galaxy-central: jmchilton: Merged in abretaud/galaxy-central (pull request #577)
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/6363c839528c/ Changeset: 6363c839528c User: jmchilton Date: 2014-12-15 05:17:31+00:00 Summary: Merged in abretaud/galaxy-central (pull request #577) Add an API to remove items from tool data tables Affected #: 2 files diff -r ac537b0a4167cbd14e0cb93175cc85c096275697 -r 6363c839528ca8bbbbc60c1b3784c788468d9445 lib/galaxy/tools/data/__init__.py --- a/lib/galaxy/tools/data/__init__.py +++ b/lib/galaxy/tools/data/__init__.py @@ -211,6 +211,13 @@ self.add_entry( entry, allow_duplicates=allow_duplicates, persist=persist, persist_on_error=persist_on_error, entry_source=entry_source, **kwd ) return self._loaded_content_version + def _remove_entry(self, values): + raise NotImplementedError( "Abstract method" ) + + def remove_entry(self, values): + self._remove_entry( values ) + return self._update_version() + def is_current_version( self, other_version ): return self._loaded_content_version == other_version @@ -506,6 +513,42 @@ data_table_fh.write( "%s\n" % ( self.separator.join( fields ) ) ) return not is_error + def _remove_entry( self, values): + + # update every file + for filename in self.filenames: + + if os.path.exists( filename ): + values = self._replace_field_separators( values ) + self.filter_file_fields( filename, values ) + else: + log.warn( "Cannot find index file '%s' for tool data table '%s'" % ( filename, self.name ) ) + + self.reload_from_files() + + def filter_file_fields( self, loc_file, values ): + """ + Reads separated lines from file and print back only the lines that pass a filter. + """ + separator_char = (lambda c: '<TAB>' if c == '\t' else c)(self.separator) + + with open(loc_file) as reader: + rval = "" + for i, line in enumerate( reader ): + if line.lstrip().startswith( self.comment_char ): + rval += line + else: + line_s = line.rstrip( "\n\r" ) + if line_s: + fields = line_s.split( self.separator ) + if fields != values: + rval += line + + with open(loc_file, 'wb') as writer: + writer.write(rval) + + return rval + def _replace_field_separators( self, fields, separator=None, replace=None, comment_char=None ): #make sure none of the fields contain separator #make sure separator replace is different from comment_char, diff -r ac537b0a4167cbd14e0cb93175cc85c096275697 -r 6363c839528ca8bbbbc60c1b3784c788468d9445 lib/galaxy/webapps/galaxy/api/tool_data.py --- a/lib/galaxy/webapps/galaxy/api/tool_data.py +++ b/lib/galaxy/webapps/galaxy/api/tool_data.py @@ -20,3 +20,44 @@ @web.expose_api def show( self, trans, id, **kwds ): return trans.app.tool_data_tables.data_tables[id].to_dict(view='element') + + @web.require_admin + @web.expose_api + def delete( self, trans, id, **kwd ): + """ + DELETE /api/tool_data/{id} + Removes an item from a data table + + :type id: str + :param id: the id of the data table containing the item to delete + :type kwd: dict + :param kwd: (required) dictionary structure containing: + + * payload: a dictionary itself containing: + * values: <TAB> separated list of column contents, there must be a value for all the columns of the data table + """ + decoded_tool_data_id = id + + try: + data_table = trans.app.tool_data_tables.data_tables.get(decoded_tool_data_id) + except: + data_table = None + if not data_table: + trans.response.status = 400 + return "Invalid data table id ( %s ) specified." % str( decoded_tool_data_id ) + + values = None + if kwd.get( 'payload', None ): + values = kwd['payload'].get( 'values', '' ) + + if not values: + trans.response.status = 400 + return "Invalid data table item ( %s ) specified." % str( values ) + + split_values = values.split("\t") + + if len(split_values) != len(data_table.get_column_name_list()): + trans.response.status = 400 + return "Invalid data table item ( %s ) specified. Wrong number of columns (%s given, %s required)." % ( str( values ), str(len(split_values)), str(len(data_table.get_column_name_list()))) + + return data_table.remove_entry(split_values) Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org