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

Saved imported directory into lookup_file for shared projects #4189

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

harshit-soora
Copy link
Contributor

Related to Issue #4120

This is the second PR, to add the directory of shared project path into a user's own project lookup file.
First PR: #4178

Later, we will show the list of shared projects in import form based upon user's group-id.

Comment on lines 28 to 31
manifest_path = Pathname("#{dir.to_s}/.ondemand/manifest.yml")
unless manifest_path.exist?
Rails.logger.warn("Imported directory is not a Open OnDemand project")
return false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some sort of class method helper that's like self.from_directory. I feel like that would clean some of this up. Let it return nil if it can't make a project out of the directory, and a real Project object if it can.

Comment on lines 34 to 49
contents = File.read(manifest_path)
raw_opts = YAML.safe_load(contents)
id = raw_opts["id"]
new_table = Project.lookup_table.merge(Hash[id, dir.to_s])

@project = Project.find(id)
if @project.nil?
File.write(Project.lookup_file, new_table.to_yaml)
else
Rails.logger.info("Imported project #{dir} already exists in lookup file")
end
true
rescue StandardError => e
Rails.logger.warn("Cannot import project #{dir} to lookup file due to error #{e}")
false
end
Copy link
Contributor

@johrstrom johrstrom Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you instantiate a Project, if it's valid you can use the member function add_to_lookup like so:

project = Project.from_directory(dir)
project.nil? ? false : project.add_to_lookup(:import) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants