Skip to content

Commit

Permalink
minor changes to logging context handler
Browse files Browse the repository at this point in the history
  • Loading branch information
lots0logs committed Feb 1, 2016
1 parent 3489a66 commit ced7869
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
[2016-01-24 16:44:27 -0600] fix uncaught exception in logging_utils (cherry picked from commit .. Dustin Falgout {3489a66}
[2016-02-01 08:20:17 -0600] update precommit hook Dustin Falgout {a73314a}
2 changes: 1 addition & 1 deletion cnchi/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

""" Set some Cnchi global constants """

CNCHI_VERSION = "0.14.4"
CNCHI_VERSION = "0.14.5"
CNCHI_WEBSITE = "http://www.antergos.com"
CNCHI_RELEASE_STAGE = "development"

Expand Down
45 changes: 26 additions & 19 deletions cnchi/logging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,27 @@
from info import CNCHI_VERSION, CNCHI_RELEASE_STAGE


class Singleton(logging.Filter):
class Singleton(type):
_instance = None

def __new__(cls, *args, **kwargs):
def __call__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(Singleton, cls).__new__(cls, *args)
cls._instance.id = None
cls._instance.install = None
cls._instance.api_key = None
cls._instance.have_install_id = False
cls._instance.after_location_screen = False
cls._instance = super(Singleton, cls).__call__(*args, **kwargs)

return cls._instance

def __new__(cls, *args, **kwargs):
obj = super().__new__(cls, *args, **kwargs)
obj.ip = None
obj.install_id = None
obj.api_key = None
obj.have_install_id = False
obj.after_location_screen = False

return obj


class ContextFilter(Singleton):
class ContextFilter(logging.Filter, metaclass=Singleton):
def __init__(self):
super().__init__()

Expand All @@ -58,8 +64,8 @@ def __init__(self):
def filter(self, record):
uid = str(uuid.uuid1()).split("-")
record.uuid = uid[3] + "-" + uid[1] + "-" + uid[2] + "-" + uid[4]
record.id = self.id
record.install = self.install
record.ip = self.ip
record.install_id = self.install_id
return True

def get_and_save_install_id(self, is_location_screen=False):
Expand All @@ -70,8 +76,8 @@ def get_and_save_install_id(self, is_location_screen=False):
self.after_location_screen = True

if 'development' == CNCHI_RELEASE_STAGE:
self.install = 'development'
self.id = '0.0.0.0'
self.install_id = 'development'
self.ip = '0.0.0.0'
self.have_install_id = True
return

Expand All @@ -89,8 +95,8 @@ def get_and_save_install_id(self, is_location_screen=False):
return

try:
self.id = info['ip']
self.install = info['id']
self.ip = info['ip']
self.install_id = info['id']
self.have_install_id = True
except (TypeError, KeyError):
self.have_install_id = False
Expand Down Expand Up @@ -120,22 +126,23 @@ def bugsnag_before_notify_callback(self, notification=None):
self.get_and_save_install_id()

notification.user = {
"id": self.id,
"id": self.ip,
"name": "Antergos User",
"install_id": self.install}
"install_id": self.install_id}
return notification

def send_install_result(self, result):
try:
build_server = self.get_url_for_id_request()
if build_server:
url = "{0}&install_id={1}&result={2}"
url = url.format(build_server, self.install, result)
url = url.format(build_server, self.install_id, result)
headers = {'X-Cnchi-Installer': CNCHI_VERSION}
r = requests.get(url, headers=headers)
res = json.loads(r.json())
except Exception as ex:
logger = logging.getLogger()
template = "Can't send install result. An exception of type {0} occured. Arguments:\n{1!r}"
template = "Can't send install result. An exception of type {0} occured. "
template += "Arguments:\n{1!r}"
message = template.format(type(ex).__name__, ex.args)
logger.error(message)
2 changes: 2 additions & 0 deletions cnchi/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ def __init__(self, app, cmd_line):
# Hide progress bar
self.progressbar.hide()

self.set_focus(None)

misc.gtk_refresh()

def load_pages(self):
Expand Down
39 changes: 35 additions & 4 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,49 @@
# This script is a helper that the developers use to call Cnchi (testing purposes only)
# Please, do not use if your intention is to do a "normal" installation

sudo rm -R /usr/share/cnchi
cleanup() {
if [[ -h /usr/share/cnchi ]]; then
sudo unlink /usr/share/cnchi
sudo mv /usr/share/cnchi.tmp /usr/share/cnchi > /dev/null 2>&1
fi
sudo killall python3
}

trap cleanup EXIT


if [[ -d /usr/share/cnchi ]] && ! [[ -h /usr/share/cnchi ]]; then
sudo mv /usr/share/cnchi /usr/share/cnchi.tmp > /dev/null 2>&1
fi

cnchi_dir=`pwd`
sudo ln -s $cnchi_dir /usr/share/cnchi
sudo ln -sf $cnchi_dir /usr/share/cnchi

#clear_fcache='False'
#for file in ${cnchi_dir}/data/fonts/OpenSans**
#do
# file_name=$(basename ${file})
# if ! [[ -f /usr/share/fonts/TTF/${file_name} ]]; then
# sudo cp ${file} /usr/share/fonts/TTF
# clear_fcache='True'
# fi
#done
#
#if [[ "${clear_fcache}" = 'True' ]]; then
# fc-cache -s -f -v
#fi


_PYTHON="/usr/bin/python"
_PYTHON_OPTIONS="-Wall"
_XML="/usr/share/cnchi/data/packages.xml"
_CNCHI_OPTIONS="-d -v -s bugsnag"
_CNCHI_OPTIONS="-d -v --disable-rank-mirrors -s bugsnag"

if [ -f /usr/bin/python3 ]; then
_PYTHON="/usr/bin/python3"
fi

sudo $_PYTHON $_PYTHON_OPTIONS cnchi/cnchi.py $_CNCHI_OPTIONS -p $_XML $1 $2 $3 $4
sudo -E $_PYTHON $_PYTHON_OPTIONS cnchi/cnchi.py $_CNCHI_OPTIONS -p $_XML ${@} 2>&1

exit 0

2 changes: 1 addition & 1 deletion update.info
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"version":"0.14.4","files":[
{"version":"0.14.5","files":[
]}

0 comments on commit ced7869

Please sign in to comment.