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

switch to relative path #231

Merged
merged 1 commit into from
Jul 23, 2020
Merged

switch to relative path #231

merged 1 commit into from
Jul 23, 2020

Conversation

rouille
Copy link
Collaborator

@rouille rouille commented Jul 10, 2020

Purpose

Use relative path in place of absolute path when creating a symbolic link to a base profile in the temporary folder of a scenario. That way, the link won'th break if we change the root of the file system (e.g. /home/EGM/v2 is renamed /home/BES) or when we move a scenario to a backup disk.

What is the code doing?

There is no code.

Where to look

In the _create_link_to_base_profile method of the Simulation Input class. I use the cd command to move into the temporary folder of the scenario and then create a symbolic link to the base profile using a relative path.

Time estimate

2min. This can be tested on creating, running, extracting a dummy scenario and then moving it to RE-Storage.

@rouille rouille added the refactor Code that is being refactored label Jul 10, 2020
@rouille rouille added this to the The Last Dance milestone Jul 10, 2020
@jenhagg
Copy link
Collaborator

jenhagg commented Jul 10, 2020

Just checking, we don't have any code that assumes the current directory (so cd won't break anything)? If not, then this looks good.

@danielolsen
Copy link
Contributor

Just checking, we don't have any code that assumes the current directory (so cd won't break anything)? If not, then this looks good.

Could we end the command with cd - to go back to wherever we were before?

@jenhagg
Copy link
Collaborator

jenhagg commented Jul 10, 2020

Could we end the command with cd - to go back to wherever we were before?

@danielolsen nice, I didn't know that one.

@rouille
Copy link
Collaborator Author

rouille commented Jul 10, 2020

When you execute a command on the server using paramiko, the command will always be interpreted from the user's home folder as shown below:

>>> from powersimdata.utility.transfer_data import setup_server_connection
>>> client = setup_server_connection()
>>> stdin, stdout, stderr = client.exec_command("cd /home/EGM/; ls -l")
>>> stdout.readlines()
['total 12\n', '-rw-rw-r--  1 kmueller regroup  654 Apr 15 13:26 gurobi.lic\n', 'drwxrwsr-x 10 brdo     regroup 4096 Jul 10 11:11 v2\n', '-rwxrwxr--  1 brdo     regroup  600 Jun  8 22:19 zeus2heracles.sh\n']
>>>
>>> stdin, stdout, stderr = client.exec_command("ls -l")
>>> stdout.readlines()
['total 100\n', '-rw-rw-r-- 1 brdo brdo        0 Jun 19  2019 200\n', 'drwxr-xr-x 2 brdo brdo     4096 May 14  2019 Desktop\n', 'drwxr-xr-x 3 brdo brdo     4096 May 15  2019 Documents\n', 'drwxr-xr-x 2 brdo brdo     4096 May 14  2019 Downloads\n', '-rw-rw-r-- 1 brdo brdo      654 Apr 15 13:30 gurobi.lic\n', 'drwxrwsr-x 2 brdo regroup 53248 Feb 20 11:34 input\n', 'drwxr-xr-x 2 brdo brdo     4096 Jul  4 11:24 Music\n', 'drwxr-xr-x 2 brdo brdo     4096 May 14  2019 Pictures\n', 'drwxrwxr-x 4 brdo brdo     4096 Apr 29 15:02 PowerSimData\n', 'drwxrwxr-x 4 brdo brdo     4096 Apr 29 17:05 PreREISE\n', 'drwxr-xr-x 2 brdo brdo     4096 May 14  2019 Public\n', 'drwxr-xr-x 2 brdo brdo     4096 May 14  2019 Templates\n', 'drwxr-xr-x 2 brdo brdo     4096 May 14  2019 Videos\n', '-rwxrwxr-- 1 brdo brdo      603 Jun  7 20:30 zeus2heracles.sh\n']

In the first command, I change directory and list it. In the second command I list the current directory, which happen to be my home.

command = "ln -s %s %s" % (
posixpath.join(const.BASE_PROFILE_DIR, source),
posixpath.join(self.TMP_DIR, target),
command = "cd %s; ln -s %s %s" % (
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we cd instead of doing posixpath.join(self.TMP_DIR, target)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure how we could get a link with a relative path if we don't first move into self.TMP_DIR and pointing to the source from there. Maybe I don't understand the question.

Copy link
Contributor

@danielolsen danielolsen Jul 11, 2020

Choose a reason for hiding this comment

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

My understanding of relative path symlinks is that they are like a string, and are only resolved when they are accessed (i.e. after they are created). So we should be able to write that string to the target folder no matter where we call ln from.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@rouille rouille merged commit 2954f77 into develop Jul 23, 2020
@rouille rouille deleted the ben/path branch July 23, 2020 21:01
@ahurli ahurli mentioned this pull request Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code that is being refactored
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants