v19 "import subprocess" and "import os, sys" fails
#1
Exclamation 
Hello to people who are smarter than I am. I hope my question has a simple solution.
I have a bash script called "qresolution" that customizes the display on an old 61" projection tv that has only one HDMI port that prefers 1080i resolution and needs odd margins to display correctly.

The computer is a Raspberry Pi 4 running arm64 linux on 2 GB RAM that boots to a command line. I can issue the command 
Code:
startx
to reach a desktop environment and from there, run my bash script, which works correctly and makes the picture on the TV very clear. I have to use
Code:
xrandr
because the strange settings are not available in the GUI. I prefer to stream using Kodi because it is less demanding on CPU memory than LXDE desktop and Google Chrome or Firefox (only 2% instead of 75% or higher).

After adjusting display settings in LXDE, I log out of the desktop environment to return to the command line and from there, I issue the command 
Code:
kodi
and kodi runs with the custom display settings. All this requires use of a mouse and keyboard to start before I can use the Kore remote control app on my phone. My wife does not know that much about computers and does not know how to do all that start up.

My solution is to write my own addon for my wife to use that runs my "qresolution" script but I cannot get it to work in Kodi. When I try to 
Code:
import os, sys
into my addon python file, I get a strange error in "Log Viewer" 
Code:
Failed to read zip://[full path]/qresolution.zip/qresolution/addon.xml
I didn't include the full path in the error I just posted because it is long!
I modified the "Hello World" example which works correctly without modification but just adding the "import os, sys" or "import subprocess" to the python file breaks it.

Any attempt to run a shell script by importing one thing or another causes the same error pointing to the addon.xml which I won't change until I can get my script working (I don't want to introduce errors in the XML file and get even more confused).

Does anyone have a suggestion? I have searched for over 8 hours trying to find an answer on my own without success, so any help would be greatly appreciated. Also, why does the error keep indicating a problem with addon.xml when I leave it alone and only edit the python file?

Thank you for your assistance
Reply
#2
Importing any of these libraries should work (they do in my addon, nothing more than the standard import command). I think whatever you're pointing to is a red herring. I suggest you turn on debug logging to see the real error in the log.
Reply
#3
Don't know linux, but sounds like a problem with the system python installation.  Agree with viewing a debug log.

scott s.
.
Reply
#4
Thank you zachmorris for your prompt reply. Yep ... Red Herring! The file that could not be opened was the device file for the display. Under Xorg, the display is called "HDMI-1" and when I remote in via XRDP, I am only offered a display called rdp0. I have been able to show my id successfully with the following python file modified from our favorite "Hello World":
Code:

import subprocess as sp
import xbmcaddon
import xbmcgui
 
addon       = xbmcaddon.Addon()
addonname   = addon.getAddonInfo('name')

# Set a string variable to use
line1 = sp.getoutput("id")
# line1 = "Hello World!\nWe can write anything we want here using Python"
# Launch a dialog box in kodi showing the string variable 'line1' as the contents
xbmcgui.Dialog().ok(addonname, line1)
Now that I found the red herring, I still can't figure out the problem with my display. Originally I thought I would use chron on reboot change the settings for HDMI-1 then sleep 5 followed by the kodi executable to make changes and boot to the GUI, but HDMI-1 does not seem to exist in that environment. Kodi is a GUI but I can't find the display because even running xrandr without arguments results in "Can't open display" instead of showing the current settings including the name of the display. Very frustrating! What the -!?!?!- is the name of the primary display under Kodi and how do I get at it? Please see the python file that fails to query the name of the monitor:
Code:
import subprocess as sp
import xbmcaddon
import xbmcgui
 
addon       = xbmcaddon.Addon()
addonname   = addon.getAddonInfo('name')

# /home/webwarriortx/quickresolution should echo the following:
# echo "Custom Resolution Applied" and update line1 variable

line1 = sp.getoutput('xrandr')
xbmcgui.Dialog().ok(addonname, line1)

I have used Linux for decades, so I understand the concept of device files. What is the name of the device file for the display when running the kodi GUI? Any help is greatly appreciated.
Reply
#5
Thank you scott967 for your guidance. User zachmorris reminded me of red herring errors and it appears to be the case for me. I am an old and obsolete person! I remember how decades ago, I would see "invalid system disk" when booting a computer with fried RAM. If you see my reply to zachmorris, my python installation is good but what I was trying to do broke things down the line and I misunderstood the error.
I can run other commands using my add-on after all, surprise! Just not my custom bash file that includes commands that won't open my display.
I appreciate the time you took out your day to offer a useful suggestion because I belong to other forums related to other devices and get silence in reply; not cool!
So again, thanks for your help.
Reply
#6
Thanks to your assistance, I will now create a new thread explaining the true error and requesting assistance figuring it out.
Even in SSH, xrandr is unable to find my display even though it is plugged in and working correctly, such a showing a movie. Why can't xrandr seem to find the display in other environments?! I don't like "aliases" and want to know the real hardware name of my display so I can communicate with it.
 Here is what I get outside of startx
Code:
# /usr/bin/xrandr
Can't open display localhost:10.0
I have tried the following based on what kodi reported from hwinfo as being the correct name of the display:
Code:
/usr/bin/sudo xrandr --output "display0" --mode 1920x1080i \
--set "top margin" 50 \
--set "bottom margin" 45 \
--set "left margin" 100 \
--set "right margin" 90
Still "Can't open display"!
Reply

Logout Mark Read Team Forum Stats Members Help
"import subprocess" and "import os, sys" fails0