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

fix user contributed example #986

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 34 additions & 33 deletions source/customizations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -281,47 +281,48 @@ The following example adds all directories within the specified base directories


.. code-block:: ruby
# /etc/ood/config/apps/dashboard/initializers/ood.rb

Rails.application.config.after_initialize do
OodFilesApp.candidate_favorite_paths.tap do |paths|

# Hash of base paths to check for additional directories with titles
# location => Title
base_paths = {
'/home/share/' => 'Shared home',
'/srv/scratch/shares/' => 'Shared scratch',
'/srv/scratch/groups/' => 'Group scratch',
'/srv/fast/users/' => 'Fast user'
# Add more paths and titles here if needed
}

base_paths.each do |base_path, title|

# Check if the base path exists and is a directory, to avoid error
next unless Dir.exist?(base_path)

# Get all entries in the current base path
Dir.entries(base_path).each do |entry|
# Construct the full path for the current entry
full_path = File.join(base_path, entry)
# /etc/ood/config/apps/dashboard/initializers/ood.rb

# Skip if it's not a directory or if it's a special entry like '.' or '..'
next unless File.directory?(full_path) && !['.', '..'].include?(entry)
Rails.application.config.after_initialize do
OodFilesApp.candidate_favorite_paths.tap do |paths|

# Check if the directory is readable and executable
if File.readable?(full_path) && File.executable?(full_path)
# Access the value of the current base_path using the `title` variable
paths << FavoritePath.new(full_path, title: "#{title}: #{File.basename(full_path)}")
# Hash of base paths to check for additional directories with titles
# location => Title
base_paths = {
'/home/share/' => 'Shared home',
'/srv/scratch/shares/' => 'Shared scratch',
'/srv/scratch/groups/' => 'Group scratch',
'/srv/fast/users/' => 'Fast user'
# Add more paths and titles here if needed
}

base_paths.each do |base_path, title|

# Check if the base path exists and is a directory, to avoid error
next unless Dir.exist?(base_path)

# Get all entries in the current base path
Dir.entries(base_path).each do |entry|
# Construct the full path for the current entry
full_path = File.join(base_path, entry)

# Skip if it's not a directory or if it's a special entry like '.' or '..'
next unless File.directory?(full_path) && !['.', '..'].include?(entry)

# Check if the directory is readable and executable
if File.readable?(full_path) && File.executable?(full_path)
# Access the value of the current base_path using the `title` variable
paths << FavoritePath.new(full_path, title: "#{title}: #{File.basename(full_path)}")
end
end
end
end
end
end

- The variable ``base_paths`` is an hash (``dirname`` => ``Title``) of all directories you want to parse. For the directory ``OSC_test`` in ``/srv/scratch/groups/``; the favorite path will be display as following

|Group scratch OSC_test: /srv/scratch/groups/OSC_test
- The variable ``base_paths`` is an hash (``dirname`` => ``Title``) of all directories you want to parse.
For the directory ``OSC_test`` in ``/srv/scratch/groups/``; the favorite path will be display as following
``Group scratch OSC_test: /srv/scratch/groups/OSC_test``


On each request, the Dashboard will check for the existence of the directories
Expand Down
Loading