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

Running without sudo returns TypeError #11

Open
guidorugo opened this issue Jul 23, 2019 · 5 comments
Open

Running without sudo returns TypeError #11

guidorugo opened this issue Jul 23, 2019 · 5 comments
Assignees

Comments

@guidorugo
Copy link

Fresh xubuntu 19.04. Installed thought apt repository.

[Errno 2] No translation file found for domain: 'cpu-g'
/opt/extras.ubuntu.com/cpu-g/share/cpu-g/distros/ubuntu.png
[Errno 2] No such file or directory: '/sys/class/power_supply/BAT0/charge_now'
[Errno 2] No such file or directory: '/sys/class/power_supply/BAT0/charge_now'
Traceback (most recent call last):
  File "./cpu-g", line 42, in <module>
    cpug = CPUG()
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 999, in __init__
    self.update_info()
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1318, in update_info
    self.start_battery_updater()
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1346, in start_battery_updater
    self.get_battery_duration()
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1079, in get_battery_duration
    inv.battery_info('charge-now')/1000000) + _(' Ah'))
TypeError: unsupported operand type(s) for /: 'str' and 'int'```
@Armag67
Copy link

Armag67 commented Sep 2, 2019

Hello,

It's not a sudo concern. CPU-G throws the same error at line 1079 in sudo mode. It's due to a switching from amperes to watts for power supply in the latest kernels updates.
I had to slightly modify the two files:

  1. /usr/share/cpu-g/src/cpug.py
  2. /usr/share/cpu-g/src/investigator.py

to make this application work properly on my Manjaro (18.0.4, Xfce stable, kernel 4.19.66-1) box with french locale (and displaying now Xorg version, accurate distro logo, battery charges: now, full, full design and power now with the good units).

Take a look at the two files in the attached tar.gz part and compare them with the original files of the 25478f0 commit with Diffuse Merge Tool for example.

Link to attachment: cpu-g-src.tar.gz

In your system the original files should be in:
/opt/extras.ubuntu.com/cpu-g/share/cpu-g

Edit: answer modified for more clarity

@BriFuture
Copy link

BriFuture commented Nov 12, 2019

Hi, I replaced the original cpug.py and investigator.py with your code, it still crashed:

[Errno 2] No translation file found for domain: 'cpu-g'
Traceback (most recent call last):
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1180, in on_core_changed
    self.update_info_for_core(coren)
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1393, in update_info_for_core
    self.l1data.set_text(inv.sysdevcpu(i, 1, 'Data'))
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/investigator.py", line 287, in sysdevcpu
    (self.cpuinfo('coresnum'), coresinsysdev))
TypeError: not all arguments converted during string formatting
Traceback (most recent call last):
  File "/opt/extras.ubuntu.com/cpu-g/bin/cpu-g", line 42, in <module>
    cpug = CPUG()
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1003, in __init__
    self.update_info()
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1191, in update_info
    self.update_info_for_core(0)
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1393, in update_info_for_core
    self.l1data.set_text(inv.sysdevcpu(i, 1, 'Data'))
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/investigator.py", line 287, in sysdevcpu
    (self.cpuinfo('coresnum'), coresinsysdev))
TypeError: not all arguments converted during string formatting

Environment Ubuntu 18.04 bonic

@Armag67
Copy link

Armag67 commented Dec 25, 2019

There is a subtle bug in the sysdevcpu function in investigator.py. This bug only occur if /proc/cpuinfo and /sys/devices/system/cpu/ don't return the same number of cores. Then sysdevcpu function try to print:

            print("Error: Cannot decide if the cores are %s or %s.\n" +
                  "Using the lowest value as the real cores number." %
                  (self.cpuinfo('coresnum'), coresinsysdev))

which is buggy.
Try to replace these three lines by:

            print("Error: Cannot decide if the cores are %s or %s.\n"
                  % (self.cpuinfo('coresnum'), coresinsysdev) +
                  "Using the lowest value as the real cores number.")

But do not forget to respect the indentations, especially the 12 spaces at the beginning of the first line.

Edited January, 9 for more clarity.

@wyphan
Copy link

wyphan commented Apr 22, 2020

I was able to reproduce the error in @BriFuture's comment on Ubuntu 18.04 by installing CPU-G from the PPA then running it in the terminal without sudo, even before applying @Armag67 's first fix.

[Errno 2] No translation file found for domain: 'cpu-g'
Traceback (most recent call last):
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1152, in on_core_changed
    self.update_info_for_core(coren)
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1366, in update_info_for_core
    self.l1data.set_text(inv.sysdevcpu(i, 1, 'Data'))
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/investigator.py", line 276, in sysdevcpu
    (self.cpuinfo('coresnum'), coresinsysdev))
TypeError: not all arguments converted during string formatting
Traceback (most recent call last):
  File "/opt/extras.ubuntu.com/cpu-g/bin/cpu-g", line 42, in <module>
    cpug = CPUG()
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 999, in __init__
    self.update_info()
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1163, in update_info
    self.update_info_for_core(0)
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1366, in update_info_for_core
    self.l1data.set_text(inv.sysdevcpu(i, 1, 'Data'))
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/investigator.py", line 276, in sysdevcpu
    (self.cpuinfo('coresnum'), coresinsysdev))
TypeError: not all arguments converted during string formatting

Applying the first fix only shifts the line number for me.

[Errno 2] No translation file found for domain: 'cpu-g'
Traceback (most recent call last):
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1152, in on_core_changed
    self.update_info_for_core(coren)
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1366, in update_info_for_core
    self.l1data.set_text(inv.sysdevcpu(i, 1, 'Data'))
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/investigator.py", line 287, in sysdevcpu
    (self.cpuinfo('coresnum'), coresinsysdev))
TypeError: not all arguments converted during string formatting
Traceback (most recent call last):
  File "/opt/extras.ubuntu.com/cpu-g/bin/cpu-g", line 42, in <module>
    cpug = CPUG()
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 999, in __init__
    self.update_info()
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1163, in update_info
    self.update_info_for_core(0)
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1366, in update_info_for_core
    self.l1data.set_text(inv.sysdevcpu(i, 1, 'Data'))
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/investigator.py", line 287, in sysdevcpu
    (self.cpuinfo('coresnum'), coresinsysdev))
TypeError: not all arguments converted during string formatting

Applying both the first fix and the second fix finally solves the problem -- now it runs but gives an interesting terminal output, both without and with sudo.

[Errno 2] No translation file found for domain: 'cpu-g'
Error: Cannot decide if the cores are 12 or 10.
Using the lowest value as the real cores number.
Error: Cannot decide if the cores are 12 or 10.
Using the lowest value as the real cores number.
Error: Cannot decide if the cores are 12 or 10.
Using the lowest value as the real cores number.
Error: Cannot decide if the cores are 12 or 10.
Using the lowest value as the real cores number.
Error: Cannot decide if the cores are 12 or 10.
Using the lowest value as the real cores number.
Error: Cannot decide if the cores are 12 or 10.
Using the lowest value as the real cores number.
Error: Cannot decide if the cores are 12 or 10.
Using the lowest value as the real cores number.
Error: Cannot decide if the cores are 12 or 10.
Using the lowest value as the real cores number.
/opt/extras.ubuntu.com/cpu-g/share/cpu-g/distros/ubuntu.png

Here's an interesting bit: when I only applied the second fix (but not the first), I can run it without sudo, but running under sudo crashes with a different error message:

[Errno 2] No translation file found for domain: 'cpu-g'
Traceback (most recent call last):
  File "/opt/extras.ubuntu.com/cpu-g/bin/cpu-g", line 42, in <module>
    cpug = CPUG()
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 999, in __init__
    self.update_info()
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/cpug.py", line 1174, in update_info
    self.desktop_environment.set_text(inv.desktop_environment())
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/investigator.py", line 110, in desktop_environment
    elif self.is_running("xfce-mcs-manage"):
  File "/opt/extras.ubuntu.com/cpu-g/share/cpu-g/investigator.py", line 133, in is_running
    if re.search(process, x):
  File "/usr/lib/python3.6/re.py", line 182, in search
    return _compile(pattern, flags).search(string)
TypeError: cannot use a string pattern on a bytes-like object

Finally, to remove the interesting output, commit 073e93. For other PPA users out there: change line 269 in /opt/extras.ubuntu.com/cpu-g/share/cpu-g/investigator.py (line 280 after the first fix) from

        coresinsysdev = str(
            len(re.findall("'cpu[0-9]'",
                           str(os.listdir("/sys/devices/system/cpu/")))))

to

        coresinsysdev = str(
            len(re.findall("'cpu[0-9]+'",
                           str(os.listdir("/sys/devices/system/cpu/")))))

@HonoluluHenk
Copy link

still relevant
@atareao care to integrate this?

@atareao atareao self-assigned this Apr 15, 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

No branches or pull requests

6 participants