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

Customsteps do not work when using a UNC path (Shifter guide settings) #297

Open
glendon-mooney opened this issue Sep 29, 2023 · 0 comments

Comments

@glendon-mooney
Copy link

Hello,

We are using mGear-4.0.9.
We are using the MGEAR_SHIFTER_CUSTOMSTEP_PATH environment variable to set the default custom step location to a folder on our server. (the value is normalized)

When adding other Custom Steps (located on the same server but different folder), they cannot be run and the "Edit" button does not work.
The error message that is shown when pressing the "Edit" button is:

// Error: The step can't be find or does't exists // 

When running the step, we get the following error:
custom_step_fail

Issue with running custom steps:

There is a condition in the shifter.guide.GuideSettings.addCustomStep that removes a "/" from the filePath before adding the item in the UI.

        if os.environ.get(MGEAR_SHIFTER_CUSTOMSTEP_KEY, ""):
            filePath = os.path.abspath(filePath)
            baseReplace = os.path.abspath(os.environ.get(
                MGEAR_SHIFTER_CUSTOMSTEP_KEY, ""))
            # backslashes (windows paths) can cause escape characters
            filePath = filePath.replace(baseReplace, "").replace('\\', '/')
            # remove front forward
            if '/' == filePath[0]:
                filePath = filePath[1:]

removed_first_slash

The path put in the item is then used by shifter.guide.HelperSlots.runStep to execute the step. Because the first slash of the UNC path is removed, the os.path.join that is in shifter.guide.HelperSlots.runStep is not able to join the path correctly and the file is not found.

Potential fix for running custom steps in the server location:

We have implemented a workaround which is to change the condition in shifter.guide.GuideSettings.addCustomStep to only remove the "/" if the path does not start with "//".

            # remove front forward
            if '/' == filePath[0] and '//' != filePath[:2]:
                filePath = filePath[1:]

Issue with the "Edit" button:

After modifying the condition in shifter.guide.GuideSettings.addCustomStep we can run custom steps that are outside of the MGEAR_SHIFTER_CUSTOMSTEP_PATH location, but the "Edit" button still throws an error.

This is caused by the os.startfile in shifter.guide.HelperSlots.editFile. The os.startfile can not open the UNC path unless the path has been normalized.

    def editFile(self, widgetList):
        try:
            cs_data = widgetList.selectedItems()[0].text()
            fullpath = self.get_cs_file_fullpath(cs_data)
 
            if fullpath:
                if sys.platform.startswith('darwin'):
                    subprocess.call(('open', fullpath))
                elif os.name == 'nt':
                    os.startfile(fullpath)

Potential fix "Edit" button:

A potential fix for this could be to normalize the fullPath being returned from shifter.guide.HelperSlots.get_cs_file_fullpath

    def get_cs_file_fullpath(self, cs_data):
        filepath = cs_data.split("|")[-1][1:]
        if os.environ.get(MGEAR_SHIFTER_CUSTOMSTEP_KEY, ""):
            fullpath = os.path.join(
                os.environ.get(
                    MGEAR_SHIFTER_CUSTOMSTEP_KEY, ""), filepath)
        else:
            fullpath = filepath

        return os.path.normpath(fullpath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant