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

Issue #138 - Update GUI static file configuration parameters #178

Merged
merged 7 commits into from
Nov 16, 2020

Conversation

Futabay
Copy link
Contributor

@Futabay Futabay commented Sep 21, 2020

No description provided.

@Futabay Futabay requested review from a team as code owners September 21, 2020 18:58
@MJJoyce
Copy link
Member

MJJoyce commented Sep 30, 2020

Hey @Futabay, thanks for throwing this up. It looks like there's some initial work that was done in line with this at https://github.com/NASA-AMMOS/AIT-GUI/blob/master/ait/gui/__init__.py#L282

I like the approach of keeping it internal to the Plugin better than globally. Perhaps the code in the plugin could be extended (if necessary for functionality) and documentation could be updated to reflect this config option in this PR? This is definitely something users will want to change so we want to make sure the options aren't hidden.

This will also need updates pushed to Core config if there's still the "old" GUI config listed in there (note, I'm not sure there is, just a note for us to check that).

Copy link
Member

@MJJoyce MJJoyce left a comment

Choose a reason for hiding this comment

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

See prev comment for change ideas

@Futabay
Copy link
Contributor Author

Futabay commented Oct 1, 2020

Hi @MJJoyce, Thank you for the review. I will remove the line specifying User and update documentation and Core config.

@MJJoyce
Copy link
Member

MJJoyce commented Oct 12, 2020

Hey @Futabay,

Thanks for throwing some changes. I apologize because I don't think I explained what I was getting at clearly in my previous post. Let me see if I can elaborate on what we want to see here vs what we have in master

We want all Plugin config to be passed via the "grouped plugin config" that users define in their server code. For the GUI we'd have something on the order of the following:

    - plugin:
        name: ait.gui.AITGUIPlugin
        inputs:
            - log_stream
            - telem_stream
        outputs:
            - command_stream

Extra plugin keys beyond the necessary name, inputs, and outputs are just passed along with the config to the Plugin during initialization and are accessible to the code. The __init__ code in master already sort of does this by extracting the User HTML directory from kwargs.

    def __init__(self, inputs, outputs, zmq_args=None, **kwargs):
        super(AITGUIPlugin, self).__init__(inputs, outputs, zmq_args, **kwargs)

        try:
            HTMLRoot.User = kwargs['html']['directory']
        except:
            pass

        bottle.TEMPLATE_PATH.append(HTMLRoot.User)

        gevent.spawn(self.init)

However, the current HTMLRoot code pulls a location out of the config. This config inspection is using the wrong location (which your PR fixed) and not really keeping config properly isolated given the new plugin approach (which your PR doesn't address).

class HTMLRoot:
    Static = pkg_resources.resource_filename('ait.gui', 'static/')
    User   = ait.config.get('gui.html.directory', Static)

It seems like the best approach is to default User to Static in HTMLRoot and leave the custom User parsing in the GUI plugin.

Thoughts?

@Futabay
Copy link
Contributor Author

Futabay commented Nov 3, 2020

Hi @MJJoyce
Following change have been made base on the comment above and conversation we had:
-Set HTMLRoot.User to the same path of Static in class HTMLRoot:
-Add example of config.yaml static dir setting in the document.

Is it a good idea to put this try/except clause inside of class AITGUIPlugin(Plugin):? Since this is GUI plugin related?

AIT-GUI/ait/gui/__init__.py

Lines 264 to 271 in 66dfe59

try:
with open(os.path.join(HTMLRoot.Static, 'package.json')) as infile:
package_data = json.loads(infile.read())
VERSION = 'AIT GUI v{}'.format(package_data['version'])
log.info('Running {}'.format(VERSION))
except:
VERSION = ''
log.warn('Unable to determine which AIT GUI Version is running')

@Futabay Futabay requested a review from MJJoyce November 3, 2020 12:44
@MJJoyce
Copy link
Member

MJJoyce commented Nov 3, 2020

Changes look good @Futabay!

What do you think about adding some logging into the try / except when we're updating the static file locations?

        try:
            HTMLRoot.User = kwargs['html']['directory']
        except:
            pass

Would be nice to notify users if the path is set or if it's not.

Regarding the other changes, seems reasonable to open a ticket to make that change as well. I'm not sure that there's anything relying on it existing outside of the plugin. We could review that on the other ticket though.

@Futabay
Copy link
Contributor Author

Futabay commented Nov 3, 2020

ok! I will add the log, and create a separate ticket for the gui version log try/except clause

except:
log.warn('[GUI Plugin Configuration] Unable to locate static file direcotry in config.yaml. '\
'The directory is set to {}'.format(HTMLRoot.User))
pass
Copy link
Member

Choose a reason for hiding this comment

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

Drop this pass

@MJJoyce
Copy link
Member

MJJoyce commented Nov 9, 2020

@Futabay,

Changes look great! Thanks for the updates. There's an extra pass that got left in the try/except block that needs removed. Other than that, looks good to merge!

@Futabay
Copy link
Contributor Author

Futabay commented Nov 9, 2020

Hi @MJJoyce Sorry the pass was left in there. Change has been pushed.

@MJJoyce
Copy link
Member

MJJoyce commented Nov 16, 2020

Awesome, thanks @Futabay!

@MJJoyce MJJoyce merged commit 1e96dcb into master Nov 16, 2020
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

Successfully merging this pull request may close these issues.

2 participants