Merge ~golpaw1/dpcs:systemcheck into dpcs:master

Proposed by Paweł Goliński
Status: Superseded
Proposed branch: ~golpaw1/dpcs:systemcheck
Merge into: dpcs:master
Diff against target: 50 lines (+38/-0)
2 files modified
systemcheck/readme.md (+2/-0)
systemcheck/systemcheck.py (+36/-0)
Reviewer Review Type Date Requested Status
Marek Bardoński static Approve
Review via email: mp+288202@code.launchpad.net

This proposal has been superseded by a proposal from 2016-03-05.

Description of the change

Implemented ticket #7. (System and package fetch script)

To post a comment you must log in.
Revision history for this message
Marek Bardoński (bdfhjk) wrote :

I would add a small comment to the regexp. Overall look smart! Good job! :)

Let's wait for a team leader's review before merging.

review: Approve (static)
~golpaw1/dpcs:systemcheck updated
bc00883... by Paweł Goliński

Add comment to regex grabbing dpkg output

Unmerged commits

bc00883... by Paweł Goliński

Add comment to regex grabbing dpkg output

68bbf1f... by Paweł Goliński

Ticket #7 - System check module

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/systemcheck/readme.md b/systemcheck/readme.md
2new file mode 100644
3index 0000000..72d8079
4--- /dev/null
5+++ b/systemcheck/readme.md
6@@ -0,0 +1,2 @@
7+Small Python2 script that returns system data (kernel, architecture,
8+installed packages) in JSON.
9diff --git a/systemcheck/systemcheck.py b/systemcheck/systemcheck.py
10new file mode 100755
11index 0000000..b7e4d8c
12--- /dev/null
13+++ b/systemcheck/systemcheck.py
14@@ -0,0 +1,36 @@
15+#!/usr/bin/python
16+
17+import platform
18+import os
19+import re
20+import json
21+
22+if __name__ == "__main__":
23+ uname = platform.uname()
24+ platform_dict = {
25+ "system_name": uname[1],
26+ "kernel": uname[2],
27+ "architecture": uname[4]
28+ }
29+ package_list = []
30+ # get installed packages from dpkg
31+ packages_raw_info = \
32+ os.popen(
33+ "dpkg-query -W -f='${binary:Package}\t${Version}\t${Status}\n' | grep \"install ok installed\""
34+ ).read()
35+ packages_raw_info = packages_raw_info.split("\n")
36+ for line in packages_raw_info:
37+ if line:
38+ # regex catches {binary:Package} and {Version} from dpkg output
39+ package_re = re.compile(r"(.+)\t(.+)\t.*")
40+ package_info = package_re.match(line)
41+ package_dict = {
42+ "name": package_info.group(1),
43+ "version": package_info.group(2)
44+ }
45+ package_list.append(package_dict)
46+ data = {}
47+ data["platform"] = platform_dict
48+ data["packages"] = package_list
49+ json_data = json.dumps(data)
50+ print json_data

Subscribers

People subscribed via source and target branches