forked from LibreSchool/libreschool-client
python3 migration (because of 20.04)
This commit is contained in:
parent
30941d369e
commit
78068d2ffa
@ -1,3 +1,3 @@
|
|||||||
*/5 * * * * root /usr/sbin/libreschool-client
|
*/5 * * * * root /usr/sbin/libreschool-client
|
||||||
* */1 * * * root /usr/sbin/libreschool-client --with-inventory
|
15 */2 * * * root /usr/sbin/libreschool-client --with-inventory
|
||||||
@reboot root /usr/sbin/libreschool-client
|
@reboot root /usr/sbin/libreschool-client
|
||||||
|
6
debian/changelog
vendored
6
debian/changelog
vendored
@ -1,3 +1,9 @@
|
|||||||
|
libreschool-client (1.0.2) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
|
* Migration to python3
|
||||||
|
|
||||||
|
-- paolo <paolo@asperti.com> Mon, 24 Apr 2020 22:00:00 +0200
|
||||||
|
|
||||||
libreschool-client (1.0.1) UNRELEASED; urgency=medium
|
libreschool-client (1.0.1) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
* Support for ubuntu 20.04
|
* Support for ubuntu 20.04
|
||||||
|
2
debian/control
vendored
2
debian/control
vendored
@ -8,6 +8,6 @@ Homepage: https://git.libreschool.org/LibreSchool/libreschool-client
|
|||||||
|
|
||||||
Package: libreschool-client
|
Package: libreschool-client
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Depends: python | python-is-python2, python-configparser, python-requests, openssh-server, ${shlibs:Depends}, ${misc:Depends}
|
Depends: python3, python-configparser, python3-requests, python3-psutil, openssh-server, ${shlibs:Depends}, ${misc:Depends}
|
||||||
Description: LibreSchool management client
|
Description: LibreSchool management client
|
||||||
Managed by a LibreSchool server.
|
Managed by a LibreSchool server.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
import uuid
|
import uuid
|
||||||
@ -10,7 +10,8 @@ import sys
|
|||||||
import socket
|
import socket
|
||||||
import fileinput
|
import fileinput
|
||||||
import json
|
import json
|
||||||
import commands
|
import lsb_release
|
||||||
|
import psutil
|
||||||
|
|
||||||
def get_default_gateway_linux():
|
def get_default_gateway_linux():
|
||||||
"""Read the default gateway directly from /proc."""
|
"""Read the default gateway directly from /proc."""
|
||||||
@ -23,7 +24,6 @@ def get_default_gateway_linux():
|
|||||||
return socket.inet_ntoa(struct.pack("<L", int(fields[2], 16)))
|
return socket.inet_ntoa(struct.pack("<L", int(fields[2], 16)))
|
||||||
|
|
||||||
def update_config_file(config):
|
def update_config_file(config):
|
||||||
# update config
|
|
||||||
with open('/etc/libreschool-client/libreschool-client.conf', 'w') as configfile:
|
with open('/etc/libreschool-client/libreschool-client.conf', 'w') as configfile:
|
||||||
config.write(configfile)
|
config.write(configfile)
|
||||||
|
|
||||||
@ -76,12 +76,16 @@ data = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if '--with-inventory' in sys.argv:
|
if '--with-inventory' in sys.argv:
|
||||||
_, cpu = commands.getstatusoutput('cat /proc/cpuinfo | grep \'^model\ name\' | head -n 1 | sed \'s/model\\ name\\s:\\s*\\(.*\\)/\\1/\'')
|
cpu = "Unknown"
|
||||||
_, ram = commands.getstatusoutput('vmstat -s | grep \'total memory$\' | awk \'{print $1}\'')
|
with open("/proc/cpuinfo") as fh:
|
||||||
_, distro = commands.getstatusoutput('lsb_release -d')
|
for line in fh:
|
||||||
|
fields = line.strip().split()
|
||||||
|
if "model name" in line:
|
||||||
|
cpu = re.sub( ".*model name.*:\s*", "", line, 1)
|
||||||
data['cpu'] = cpu
|
data['cpu'] = cpu
|
||||||
data['ram'] = ram
|
data['ram'] = int(psutil.virtual_memory().total / 1024)
|
||||||
data['distro'] = distro
|
distinfo = lsb_release.get_distro_information()
|
||||||
|
data['distro'] = distinfo.get('DESCRIPTION', 'n/a')
|
||||||
|
|
||||||
# if server uuid is set
|
# if server uuid is set
|
||||||
if 'uuid' in config['server']:
|
if 'uuid' in config['server']:
|
||||||
@ -98,13 +102,13 @@ headers = {
|
|||||||
try:
|
try:
|
||||||
r = requests.post(config['server']['ping_url'], data=json.dumps(data), headers=headers, timeout=5)
|
r = requests.post(config['server']['ping_url'], data=json.dumps(data), headers=headers, timeout=5)
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
print e
|
print(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
resp = r.json()
|
resp = r.json()
|
||||||
|
|
||||||
if 'error' in resp:
|
if 'error' in resp:
|
||||||
print resp['error']
|
print(resp['error'])
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not 'uuid' in config['server']:
|
if not 'uuid' in config['server']:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user