Skip to content
Permalink
Browse files

Ask for the root permission when it needs and support snap package.

  • Loading branch information...
fourdollars committed Sep 7, 2019
1 parent 6e9760f commit 35e888cca228fa040bbc21e689f69442b747f974
Showing with 102 additions and 9 deletions.
  1. +12 −0 README.md
  2. +5 −1 bin/energy-tools
  3. +7 −0 debian/changelog
  4. +2 −2 debian/control
  5. +17 −5 energy_tools/sysinfo.py
  6. +1 −1 energy_tools/version.py
  7. +58 −0 snapcraft.yaml
@@ -20,6 +20,18 @@ optional arguments:
-t TEST, --test TEST use test case
```

You need to execute this command with root permission so it can collect the hardware information.

```
$ sudo energy-tools
```

If you are using some valid profile, you don't need to execute this command with root permission.

```
$ energy-tools -p MySystem.profile
```

# Ubuntu PPA
https://launchpad.net/~fourdollars/+archive/ubuntu/energy-tools

@@ -2,6 +2,7 @@

import argparse
import logging
import os
from energy_tools import core
from energy_tools.version import __version__ as ver

@@ -26,4 +27,7 @@ if __name__ == '__main__':
level=logging.DEBUG)
else:
logging.basicConfig(format='<%(levelname)s> %(message)s')
core.process(description, args)
if args.test is None and args.profile is None and os.geteuid() != 0:
raise Exception("Please execute this command with root permission so it can collect the hardware information.")
else:
core.process(description, args)
@@ -1,3 +1,10 @@
energy-tools (1.6.5) bionic; urgency=medium

* Ask for the root permission when it needs.
* Support snap package.

-- Shih-Yuan Lee (FourDollars) <sylee@canonical.com> Sun, 08 Sep 2019 01:01:03 +0800

energy-tools (1.6.4) bionic; urgency=medium

* Fix the arguments error.
@@ -10,7 +10,7 @@ Standards-Version: 4.1.4

Package: energy-tools
Architecture: all
Depends: ${python3:Depends}, ${misc:Depends}, python3-energy-tools
Depends: ${python3:Depends}, ${misc:Depends}, python3-energy-tools, dmidecode, x11-xserver-utils
Suggests: energy-tools-doc
Description: Energy Tools for Energy Star and ErP Lot 3
This program is designed to collect the system profile and
@@ -28,7 +28,7 @@ Description: Design flow for Energy Tools

Package: python3-energy-tools
Architecture: all
Depends: ${python3:Depends}, ${misc:Depends}, dmidecode, python3-debian, python3-xlsxwriter, python3-gi, gir1.2-gtk-3.0
Depends: ${python3:Depends}, ${misc:Depends}, python3-debian, python3-xlsxwriter, python3-gi, gir1.2-gtk-3.0
Recommends: energy-tools
Description: Python3 library for Energy Tools
This program is designed to collect the system profile and
@@ -320,22 +320,33 @@ def get_cpu_core(self):
except subprocess.CalledProcessError:
self.cpu_core = 1
else:
self.cpu_core = int(subprocess.check_output('cat /proc/cpuinfo | grep "cpu cores" | sort -ru | head -n 1 | cut -d: -f2 | xargs', shell=True, encoding='utf8').strip())
self.cpu_core = self._int_cmd(
'cat /proc/cpuinfo | grep "cpu cores" | sort -ru | head -n 1 | cut -d: -f2 | xargs')

debug("CPU core: %s" % (self.cpu_core))
self.profile["CPU Cores"] = self.cpu_core
return self.cpu_core

def _float_cmd(self, command):
return float(subprocess.check_output(
command, shell=True, encoding='utf8').strip())

def _int_cmd(self, command):
return int(subprocess.check_output(
command, shell=True, encoding='utf8').strip())

def get_cpu_clock(self):
if "CPU Clock" in self.profile:
self.cpu_clock = self.profile["CPU Clock"]
return self.cpu_clock

cpu = self._get_cpu_vendor()
if cpu == 'intel':
self.cpu_clock = float(subprocess.check_output("cat /proc/cpuinfo | grep 'model name' | sort -u | cut -d: -f2 | cut -d@ -f2 | xargs | sed 's/GHz//'", shell=True, encoding='utf8').strip())
self.cpu_clock = self._float_cmd(
"grep 'model name' /proc/cpuinfo | sort -u | cut -d: -f2 | cut -d@ -f2 | xargs | sed 's/GHz//'")
elif cpu == 'amd':
self.cpu_clock = float(subprocess.check_output("sudo dmidecode -t processor | grep 'Current Speed' | cut -d: -f2 | xargs | sed 's/MHz//'", shell=True, encoding='utf8').strip()) / 1000
self.cpu_clock = self._float_cmd(
"dmidecode -t processor | grep 'Current Speed' | cut -d: -f2 | xargs | sed 's/MHz//'")
else:
raise Exception('Unknown CPU Vendor')

@@ -352,8 +363,9 @@ def get_mem_size(self):

self.mem_size = 0
self.mem_used_slots = 0
self.mem_total_slots = int(subprocess.check_output("sudo dmidecode -t 16 | grep ' Devices:' | awk -F':' '{print $2}'", shell=True, encoding='utf8'))
for size in subprocess.check_output("sudo dmidecode -t 17 | grep 'Size:.*MB' | awk '{print $2}'", shell=True, encoding='utf8').split('\n'):
self.mem_total_slots = self._int_cmd(
"dmidecode -t 16 | grep 'Devices:' | awk -F': ' '{print $2}'")
for size in subprocess.check_output("dmidecode -t 17 | grep 'Size:.*MB' | awk '{print $2}'", shell=True, encoding='utf8').split('\n'):
if size:
self.mem_size = self.mem_size + int(size)
self.mem_used_slots = self.mem_used_slots + 1
@@ -1 +1 @@
__version__ = '1.6.4'
__version__ = '1.6.5'
@@ -0,0 +1,58 @@
name: energy-tools
base: core18
version: '1.6.5'
summary: Energy Tools for Energy Star and ErP Lot 3
description: |
This program is designed to collect the system profile and calculate the
results of Energy Star (5.2 & 6.0 & 7.0 & 8.0) and ErP Lot 3 (Jul. 2014 &
Jan. 2016).
grade: stable
confinement: strict
license: GPL-3.0
architectures: [amd64, i386]

parts:
energy-tools:
source: .
plugin: python
stage-packages:
- dmidecode
- gir1.2-gtk-3.0
- python3-debian
- python3-gi
- python3-xlsxwriter
- x11-xserver-utils
after:
- desktop-gnome-platform
desktop-gnome-platform:
source: https://github.com/ubuntu/snapcraft-desktop-helpers.git
source-depth: 1
source-subdir: gtk
plugin: make
build-packages:
- build-essential
- libgtk-3-dev
override-build: |
snapcraftctl build
mkdir -pv $SNAPCRAFT_PART_INSTALL/gnome-platform
plugs:
gnome-3-28-1804:
interface: content
target: $SNAP/gnome-platform
default-provider: gnome-3-28-1804

apps:
energy-tools:
command: desktop-launch $SNAP/bin/energy-tools
plugs:
- desktop
- desktop-legacy
- hardware-observe
- home
- unity7
- wayland
- x11
bash:
command: desktop-launch bash

0 comments on commit 35e888c

Please sign in to comment.
You can’t perform that action at this time.