Skip to content

Commit

Permalink
File name verifier (#1451)
Browse files Browse the repository at this point in the history
Boutiques output file name verification #1447
  • Loading branch information
MontrealSergiy authored Jan 16, 2025
1 parent 2a41096 commit 057739d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions Bourreau/lib/boutiques_file_name_verifier.rb
72 changes: 72 additions & 0 deletions BrainPortal/lib/boutiques_file_name_verifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

#
# CBRAIN Project
#
# Copyright (C) 2008-2024
# The Royal Institution for the Advancement of Learning
# McGill University
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# This module offers automatic verification of the
# files (or directories) names generated as tool output, and therefore have comply with CBRAIN file name conventions.
#
# For example, in the "inputs" section we might have:
#
# {
# "description": "The name of the folder to store outputs of XCPD processing.",
# "id": "output_dir",
# "name": "output_dir",
# "optional": false,
# "type": "String",
# "value-key": "[OUTPUT_DIR]",
# "default-value": "xcpd_output"
# }
#
# And the custom property is specified like
#
# "cbrain:integrator_modules": {
# "BoutiquesFileNameVerifier": [
# "output_dir",
# "another_id"
# ]
# }
module BoutiquesFileNameVerifier

# Note: to access the revision info of the module,
# you need to access the constant directly, the
# object method revision_info() won't work.
Revision_info=CbrainFileRevision[__FILE__] #:nodoc:

def after_form #:nodoc:
descriptor = self.descriptor_for_after_form
verifs = descriptor.custom_module_info('BoutiquesFileNameVerifier') || []
verifs.each do |inputid| # 'myinput'
found_match = Array(invoke_params[inputid])
.map(&:presence)
.compact
.all? do |fname|
Userfile.is_legal_filename?(fname)
end
if ! found_match
input = descriptor.input_by_id(inputid)
params_errors.add(input.cb_invoke_name, "is not suitable for naming an output file. Please, change to a value that starts with a letter or number and avoid special or unprintable symbols")
end
end

super # call all the normal code
end

end

0 comments on commit 057739d

Please sign in to comment.