Skip to content

Commit

Permalink
Merge commit 'eaf77770c8acead50b8536b8c4fc33a2db907ea9'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylwekqaz committed Mar 31, 2016
2 parents 83e560c + eaf7777 commit 0f455ff
Show file tree
Hide file tree
Showing 62 changed files with 1,724 additions and 173 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: python
python:
- '2.6'
- '2.7'
install:
- pip install pytest pep8 requests gi
script:
- pep8 --ignore=E402,E121,E123,E126,E226,E24,E704 client server
notifications:
email: false
35 changes: 35 additions & 0 deletions client/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
PYTHON=python2
DESTDIR=/
BUILDIR=$(CURDIR)/debian/dpcs
PROJECT=dpcs
VERSION=0.1.0

all:
@echo "make source - Create source package"
@echo "make install - Install on local system"
@echo "make buildrpm - Generate a rpm package"
@echo "make builddeb - Generate a deb package"
@echo "make clean - Get rid of scratch and byte files"

source:
$(PYTHON) setup.py sdist $(COMPILE)

install:
$(PYTHON) setup.py install --root $(DESTDIR) $(COMPILE)

buildrpm:
$(PYTHON) setup.py bdist_rpm --post-install=rpm/postinstall --pre-uninstall=rpm/preuninstall

builddeb:
# build the source package in the parent directory
# then rename it to project_version.orig.tar.gz
$(PYTHON) setup.py sdist $(COMPILE) --dist-dir=../
rename -f 's/$(PROJECT)-(.*)\.tar\.gz/$(PROJECT)_$$1\.orig\.tar\.gz/' ../*
# build the package
dpkg-buildpackage -i -I -rfakeroot

clean:
$(PYTHON) setup.py clean
$(MAKE) -f $(CURDIR)/debian/rules clean
rm -rf build/ MANIFEST
find . -name '*.pyc' -delete
File renamed without changes.
1 change: 1 addition & 0 deletions client/configure.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dnl autoconf stub
5 changes: 5 additions & 0 deletions client/debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dpcs (0.1) UNRELEASED; urgency=low

* Initial release.

-- Marek Bardoński <[email protected]> Mon, 14 Mar 2016 17:22:58 +0100
1 change: 1 addition & 0 deletions client/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
+7
17 changes: 17 additions & 0 deletions client/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Source: dpcs
Section: python
Priority: optional
Maintainer: Marek Bardoński, <[email protected]>
Build-Depends: debhelper (>= 7),
python (>= 2.6.6-3~),
python-requests (>= 2.2),
python-gi (>= 3.12)
Standards-Version: 3.9.2
X-Python-Version: >= 2.6

Package: dpcs
Architecture: all
Section: python
Depends: ${misc:Depends}, ${python:Depends}
Description: An application, that would help Ubuntu users in effortless problem solving.
An application for automatic problem solving in Ubuntu OS. In short, our application would first gather large amount of data concerning crashes of application that Ubuntu users have encountered during their work. Next we would analyze those errors and find solutions. Based on the resulting database, a user would be proposed a solution for an error that he encounters.
7 changes: 7 additions & 0 deletions client/debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: dpcs
Upstream-Contact: Marek Bardoński <[email protected]>

Files: *
Copyright: 2016, dpcs-team, <[email protected]>
License: LGPL-3
11 changes: 11 additions & 0 deletions client/debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/make -f
# -*- makefile -*-

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/python-autotools.mk

DEB_PYTHON2_MODULE_PACKAGES = dpcs

clean::
rm -rf build build-stamp configure-stamp build/ MANIFEST
dh_clean
Empty file added client/dpcs_client/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions client/dpcs_client/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Utilities for handling settings."""
import json
import os

# config file path
DEFAULT_SERVER_ADDRESS = "http://private-a6e53-dpcs.apiary-mock.com/"
FILE = os.path.expanduser('~/.dpcs/.dpcsconfig')


def read_settings():
with open(FILE, 'r') as f:
try:
settings = json.load(f)
if 'server_address' not in settings:
settings['server_address'] = DEFAULT_SERVER_ADDRESS
except ValueError:
settings = {'server_address': DEFAULT_SERVER_ADDRESS}
return settings
14 changes: 4 additions & 10 deletions systemcheck/systemcheck.py → client/dpcs_client/systemcheck.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#!/usr/bin/python

import platform
"""Utilities for checking system's information."""
import os
import platform
import re
import json


def systemcheck():
Expand All @@ -17,7 +15,8 @@ def systemcheck():
# get installed packages from dpkg
packages_raw_info = \
os.popen(
"dpkg-query -W -f='${binary:Package}\t${Version}\t${Status}\n' | grep \"install ok installed\""
"dpkg-query -W -f='${binary:Package}\t${Version}\t${Status}\n'" +
" | grep \"install ok installed\""
).read()
packages_raw_info = packages_raw_info.split("\n")

Expand All @@ -35,8 +34,3 @@ def systemcheck():
data["platform"] = platform_dict
data["packages"] = package_list
return data


if __name__ == "__main__":

print(json.dumps(systemcheck()))
16 changes: 9 additions & 7 deletions client/main/client.py → client/main/dpcs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#! /usr/bin/env python2
# -*- coding: utf-8 -*-
from __future__ import print_function
from os import mkdir
Expand All @@ -13,12 +14,11 @@
from requests import post
from requests import RequestException

from ...systemcheck.systemcheck import systemcheck
from dpcs_client.settings import read_settings
from dpcs_client.systemcheck import systemcheck

EXIT_OK = 0

SERVER_ADDRESS = "http://private-a6e53-dpcs.apiary-mock.com/"


def generate_report(exit_code, stderr_output):
"""Generate a report which will be sent to the DCPS server.
Expand Down Expand Up @@ -143,8 +143,10 @@ def save_script(script):
if __name__ == '__main__':

if len(sys.argv) != 2:
print("Usage python client.py '[command to check]'")
exit(1)
print("Usage dpcs '[command to check]'")
sys.exit(1)

server_address = read_settings()['server_address']

p = subprocess.Popen(sys.argv[1],
stderr=subprocess.PIPE,
Expand All @@ -156,7 +158,7 @@ def save_script(script):

if code != EXIT_OK:

api_description_url = SERVER_ADDRESS + "vd1/paths/"
api_description_url = server_address + "vd1/paths/"
try:
response = get(api_description_url)
except RequestException as e:
Expand All @@ -166,7 +168,7 @@ def save_script(script):
exit(2)

api_paths = response.json()
crash_report_url = SERVER_ADDRESS + api_paths["crash-reports"]
crash_report_url = server_address + api_paths["crash-reports"]
headers = {
'Content-Type': 'text/json'
}
Expand Down
153 changes: 153 additions & 0 deletions client/settings/dpcs-settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/usr/bin/env python2

import json
import pgi as gi
gi.install_as_gi()
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import os.path

from dpcs_client.settings import DEFAULT_SERVER_ADDRESS
from dpcs_client.settings import FILE
from dpcs_client.settings import read_settings

# the window title
PANELTITLE = "DPCS Settings"

# about DPCS - authors, basic info, licensing and such...
ABOUT_DPCS = """AI powered agent, running locally on your machine,
analyzing what's going on in the logs and overall on the system,
and advertizing what's wrong, then, hopefully,
offer an answer to help you fix it.
"""


# minimal window width and height
WIDTH = 600
HEIGHT = 200


def displaypanel():
""" displays the prefs dialog
"""
win = SettingsPanel()
win.show_all()
Gtk.main()


class SettingsPanel(Gtk.Window):
""" The preferences dialog for DPCS"""

def __init__(self):
Gtk.Window.__init__(self, title=PANELTITLE)
self.set_size_request(WIDTH, HEIGHT)

maincontainer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
spacing=0)
self.add(maincontainer)

notebook = Gtk.Notebook()
maincontainer.pack_start(notebook, True, True, 0)

buttonscontainer = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
maincontainer.pack_start(buttonscontainer, False, False, 0)

# settings tab

settingspage = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)

settings = read_settings()
settingspage.pack_start(self.addTextField('Server address',
settings['server_address']),
True, True, 0)

# end of setting boxes

notebook.append_page(settingspage, Gtk.Label('Settings'))

# about DPCS tab

aboutpage = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)

acontent = Gtk.Label()
acontent.set_text(ABOUT_DPCS)
acontent.set_justify(Gtk.Justification.LEFT)
aboutpage.pack_start(acontent, True, True, 0)

notebook.append_page(aboutpage, Gtk.Label('About DPCS'))

# ok, apply and cancel buttons

self.ok = Gtk.Button(label="Ok")
cancel = Gtk.Button(label="Cancel")
restore = Gtk.Button(label="Restore default")
applyb = Gtk.Button(label="Apply")

buttonscontainer.pack_end(self.ok, False, False, 0)
buttonscontainer.pack_end(applyb, False, False, 0)
buttonscontainer.pack_end(restore, False, False, 0)
buttonscontainer.pack_end(cancel, False, False, 0)

cancel.connect("clicked", Gtk.main_quit)
applyb.connect("clicked", self.applysettings)
restore.connect("clicked", self.restoresettings)
self.ok.connect("clicked", self.applysettings)

# loads current config
self.loadconfig()
self.connect("delete-event", Gtk.main_quit)

def addTextField(self, label, default_text):
self.entry = Gtk.Entry()
self.entry.set_text(default_text)
label_gtk = Gtk.Label(label)
table = Gtk.Table(1, 3, True)
table.attach(label_gtk, 0, 1, 0, 1)
table.attach(self.entry, 1, 3, 0, 1)
return table

def applysettings(self, widget):
""" writes settings to dpcs.config, exits
if ok has been pressed
"""
conf_directory = os.path.dirname(FILE)

if not os.path.exists(conf_directory):
os.makedirs(conf_directory)

f = open(FILE, 'w')

settings = {'server_address': self.entry.get_text()}
json.dump(settings, f, indent=2)
f.close()
if widget == self.ok:
Gtk.main_quit()

def restoresettings(self, widget):
"""Restore default settings."""
conf_directory = os.path.dirname(FILE)

if not os.path.exists(conf_directory):
os.makedirs(conf_directory)

f = open(FILE, 'w')

settings = {'server_address': DEFAULT_SERVER_ADDRESS}
json.dump(settings, f, indent=2)
f.close()

self.entry.set_text(DEFAULT_SERVER_ADDRESS)

def loadconfig(self):
""" loads current settings from dpcs.config
"""
with open(FILE, 'r') as f:
try:
settings = json.load(f)
if 'server_address' in settings:
self.entry.set_text(settings['server_address'])
except ValueError:
pass

if __name__ == "__main__":
displaypanel()
1 change: 0 additions & 1 deletion client/settings/dpcs-settingspanel/README.md

This file was deleted.

Loading

0 comments on commit 0f455ff

Please sign in to comment.