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

Re-factoring shell scripts in python for Phoniebox 2.x #1421

Closed
wants to merge 5 commits into from

Conversation

MiczFlor
Copy link
Owner

Refactoring the shell scripts in python for version 2.x

elif(args_main['command'] == "playout_position_save"):
playProcess.playout_position_save()

elif(args_main['command'] == "playout_resume_play"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, have you considered to make a module with functions and call them by their name? This might allow you to have this in separated files (or at least individual (testable) methods).

https://stackoverflow.com/questions/3061/calling-a-function-of-a-module-by-using-its-name-a-string

@arne123 does the same on future3/develop in the RPC Client

Copy link
Owner Author

Choose a reason for hiding this comment

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

@pabera : If I understand you correctly, your suggestion would shorten most the script into more or less one line like on future3/develop in the RPC Client

if (call_function is not None):  # better to check with is callable() ??

If I interpret the typo in the comment of this line correctly as "check which", then this is what I would like to do in the CLI file.
Check for valid commands.
And if no valid command is given, possibly give an explanation what is possible and what not.

I know it's extra work, but because I will need to change the scripts called from shell to python in so many places, I would like to have that abstracted error check. Does that make sense? Or did I understand you wrong?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right. at least the repetivie code like this would shrink into 1 line.

elif(args_main['command'] == "playout_position_save"):
    playProcess.playout_position_save()

Comment on lines +145 to +146
if('CMDSHUFFLE' in conf):
if(args_main['cardid'] == conf['CMDSHUFFLE']):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here and below.. how about writing it into a combined condition? And it seams that Python does not necessarily require ( ) around the condition statement

if 'CMDSHUFFLE' in conf and args_main['cardid'] == conf['CMDSHUFFLE']:

Copy link
Owner Author

Choose a reason for hiding this comment

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

I wanted to be really nice... because if I combine both, the second condition throws an error.

Copy link
Collaborator

@pabera pabera May 20, 2021

Choose a reason for hiding this comment

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

I might be mistaken, but Python should not do this.. if you have

if A and B and A = False, it shouldn't matter what B is. But I don't have much experience with Python, so someone else might speak about it.

@s-martin
Copy link
Collaborator

Hi @s-martin - I have a short question about the failed tests. The python module controlling alsa seems to require compiling. And it worked on my laptop (no surprise). But the test here says:

compilation terminated.
    error: command 'gcc' failed with exit status 1

Do you have any idea where that could come from? Thank you.

@MiczFlor
I think pyalsaaudio is just a wrapper.

Could you try to add
apt-get install libasound2-dev
to run in
https://github.com/MiczFlor/RPi-Jukebox-RFID/blob/develop/.github/workflows/pythonpackage.yml ?

Copy link
Collaborator

@pabera pabera left a comment

Choose a reason for hiding this comment

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

Let me know if you have questions about my comments

playProcess.sys_switches(args_func)
return

elif(args_main['command'] == "playout_position_save"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would still write if instead of elif

Copy link
Owner Author

Choose a reason for hiding this comment

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

Makes sense

Comment on lines +2 to +15
def read_config_bash(paths_all):

# paths_all must be a list like [a, b, c]
conf = {}
for path_config in paths_all:
# read config
with open(path_config) as myfile:
for line in myfile:
if not line.lstrip().startswith('#'):
name, var = line.partition("=")[::2]
conf[name.strip()] = var.strip()
# strip " off values in dictionary conf
conf = {k: v.strip('"') for (k, v) in conf.items()}
return conf
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would add a try / catch to catch issues in situations where the file does not exist

Copy link
Collaborator

@pabera pabera left a comment

Choose a reason for hiding this comment

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

My comments are not critical, but good practices ;-)

@MiczFlor MiczFlor mentioned this pull request Jun 1, 2021
@s-martin
Copy link
Collaborator

@MiczFlor, with future3 under dev is this still needed?

@s-martin
Copy link
Collaborator

Closing this now as future3 is an all Python implementation

@s-martin s-martin closed this Dec 21, 2023
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.

3 participants