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

Add some features #86

Merged
merged 9 commits into from
Dec 7, 2017
Merged

Add some features #86

merged 9 commits into from
Dec 7, 2017

Conversation

csphoenix1
Copy link
Contributor

No description provided.

csphoenix1 added 6 commits November 24, 2017 00:56
…'" error

Changing the working directory to the app's directory to avoid the "ImportError: No module named 'server'" error be begginner in Python.
…'" error

Changing the working directory to the app's directory to avoid the "ImportError: No module named 'server'" error be begginner in Python.
Adding feature to customize the listening interface via the configuration file in order to allow the access only via localhost (or 127.0.0.1), via a specific interface (ie : 192.168.1.25) or, all interface (0.0.0.0).
Add feature to allow the possibility to use variables in the path of the output files which has been updated by the arguments specified before launching the script.
@csphoenix1 csphoenix1 changed the title Adding feature to customize the listening interface via the conf. file Add some features Nov 27, 2017
@bugy
Copy link
Owner

bugy commented Nov 28, 2017

Hi @csphoenix1 , thanks for the features, they look useful. I have some comments on replacing variables, please check my code review comments. If you want, I can do all requested review changes myself.

By the way, do you use output files feature? I added it just in case and don't use it myself.

if argument in arguments:
value = arguments[argument]
output_file = output_file.replace("$$" + argument, value)
output_files[i] = output_file
Copy link
Owner

Choose a reason for hiding this comment

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

Could we return modified array? Instead of changing internal state of the config?
Also I would suggest to move the function to features/file_download_feature.py and call it directly inside prepare_downloadable_files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes good idead, I will modified it.

src/server.py Outdated
@@ -470,6 +470,8 @@ def post(self):
respond_error(self, 400, 'Received invalid parameters')
return

model_helper.update_output_files_with_vars(config.output_files, execution_info.param_values)
Copy link
Owner

Choose a reason for hiding this comment

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

Please read my comment regarding moving the call to FinishListener and file_download_feature

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes no problem ;)

@@ -27,6 +28,18 @@ def is_empty(value):
return (not value) and (value != 0) and (value != False)


def update_output_files_with_vars(output_files, arguments):
for i, output_file in enumerate(output_files):
regex = "\$\$([a-zA-Z0-9-_]+)" # Syntaxe is : $$my_variable (with two '$')
Copy link
Owner

Choose a reason for hiding this comment

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

I would suggest to change internal loop a bit: we can iterate over all arguments and build regex based on it:
e.g.

for i, output_file in enumerate(output_files):
  for argument in arguments:
    output_file = re.sub('\$\$' + argument, arguments[argument], output_file)

Also secure arguments should be excluded

One more thing/question. $$ syntax is already used for environment variables in couple of places. What do you think, won't reusing the syntax cause any confusion? As for me, it shouldn't be a problem

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 about the loop.

About the syntaxe, i didn't know it was used for environment variables.
To avoid bad surprise, it would be better if we use 2 differents syntaxes. So, since the "$$" syntaxe is already used, we could use "$$$" or "$"? What do you think about? "$$$" is not use in contrary to "$" which is used by PHP.

Unknown added 2 commits November 28, 2017 22:45
Patch1 branch before bugy's validation
Taking in count bugy comment's
@csphoenix1
Copy link
Contributor Author

csphoenix1 commented Nov 28, 2017

Also, you will have to update the Wiki :)

/**
* Required: no
* Description: custom interface for running the web server
* Type: string
* Default: "0.0.0.0" ("127.0.0.1" or "localhost" to listen only on loopback/local or "0.0.0.0" to listen on all interfaces)
*/
"interface": "0.0.0.0",

src/server.py Outdated
@@ -361,6 +361,14 @@ def finished(self):

output_logger.close()

# What's the diffrence between "get_config()" and "config" ?
Copy link
Owner

Choose a reason for hiding this comment

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

There is no difference.
I've created a getter method because I was used to it in Java. However in python it's not needed and you can safely access class fields directly. So, please use "config.output_files"

src/server.py Outdated
# process_wrapper.get_config().output_files = file_download_feature.update_output_files_vars_with_args(
# process_wrapper.get_config().output_files,
# process_wrapper.execution_info.param_values)#
process_wrapper.config.output_files = file_download_feature.update_output_files_vars_with_args(
Copy link
Owner

Choose a reason for hiding this comment

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

could you move this call inside prepare_downloadable_files? So something like:

def prepare_downloadable_files(...):
    output_files = config.output_files

    if not output_files:
        return []
    
    output_files = update_output_files_vars_with_args(...)

@bugy
Copy link
Owner

bugy commented Nov 28, 2017

Regarding wiki update - thanks, I'll do it after merging your changes (both for output files and address). However I'm a bit confused - in your proposed wiki statement you used "interface" name, however according to the code it should be "address". Do I miss something?
I'm fine with any of the names

Moving "update_output_files_vars_with_args" call inside "prepare_downloadable_files".
@csphoenix1 csphoenix1 closed this Dec 6, 2017
@csphoenix1 csphoenix1 reopened this Dec 6, 2017
@csphoenix1
Copy link
Contributor Author

Hi @bugy !
About interface vs address, we can finaly use "address" (according to the SSH Server Config File in Linux: they use the word "address" so we can do the same :) ).
Also, I moved the call as asked, so I hope it's that you wan't.

PS : I've created some issue about involves that it could be cool :)

@bugy bugy merged commit a2627d9 into bugy:master Dec 7, 2017
@bugy
Copy link
Owner

bugy commented Dec 7, 2017

Hi @csphoenix1 , thank you for the changes and for new feature requests! :)

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