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

utility module make folders #1343 #1348

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
1 change: 1 addition & 0 deletions Bourreau/lib/boutiques_dir_maker.rb
73 changes: 73 additions & 0 deletions BrainPortal/lib/boutiques_dir_maker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

#
# CBRAIN Project
#
# Copyright (C) 2008-2023
# 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/>.
#

# Some tools expect that a directory e.g. results, etc exists in the working directory
#
# While traditionally we add to the boutiques command line prefix akin to 'mkdir -p [OUTPUT];'
# external collaborators might dislike polluting the command line with technical staff
# or need a clean boutiques descriptor which does not create any new folders
# For example :
#
#
# and in the `cbrain:integrator_modules` section look like:
#
# "BoutiquesDirMaker":
# [ "[OUTDIR]", "[OUTDIR]/[THRESHOLD]_res", "tmp" ]
#
# Absolute paths and special symbols are not supported, please use only alphanumericals,
# underscores, hyphens, spaces, and square brackets
#
module BoutiquesDirMaker

# 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:

############################################
# Bourreau (Cluster) Side Modifications
############################################

# Add mkdir to json descriptor
def descriptor_for_cluster_commands
descriptor = super.dup()
dir_names = descriptor.custom_module_info('BoutiquesDirMaker')

# Log revision information
basename = Revision_info.basename
commit = Revision_info.short_commit
self.addlog("Creating directories with BoutiquesDirMaker.")
self.addlog("#{basename} rev. #{commit}")

dir_names.each do |x|
if Pathname(x).absolute?
raise CbrainError("#{x} is absolute paths, which are presently not supported")
end
x.gsub!(/[^0-9A-Za-z.\/\-_\[\]]|(\.\.+)/, '_') # silent sanitizing and quotes
MontrealSergiy marked this conversation as resolved.
Show resolved Hide resolved
end

# adds folder creation, the quotation is used to allow for spaces
descriptor.command_line = "mkdir -p '" + dir_names.join("' '") + "'; " + descriptor.command_line

descriptor
end
end