Skip to content

Commit

Permalink
fix HTTP error detection
Browse files Browse the repository at this point in the history
fix flake8 tests
  • Loading branch information
LyzardKing committed Jun 11, 2018
1 parent ae7ce59 commit 4ca80fb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 24 deletions.
2 changes: 1 addition & 1 deletion grive_indicator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from datetime import datetime
from grive_indicator.UI import settings, configure, InfoDialog
from grive_indicator.tools import ind, Config, config_file,\
is_connected, runConfigure, show_notify, Singleton
is_connected, runConfigure, show_notify

logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
logger = logging.getLogger(__name__)
Expand Down
23 changes: 7 additions & 16 deletions grive_indicator/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,16 @@ def setValue(self, key, value):
notification.show()


class Singleton(type):

_instances = {}

def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]


def is_connected(url='https://drive.google.com/', timeout=10):
try:
r = requests.get(url=url, timeout=timeout)
if r.status_code != 200:
raise Exception
except:
logger.error('No internet connection available. Skipping sync.')
return False
return True
r.raise_for_status()
return True
except requests.HTTPError as e:
logger.error("HTTP error {0}.".format(e.response.status_code))
except requests.ConnectionError:
logger.error("No internet connection available.")
return False


def runConfigure(folder, selective=None):
Expand Down
5 changes: 1 addition & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python3

import os
import pep8
# from flake8.api import legacy as flake8
from flake8.api import legacy as flake8
import unittest

config_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
Expand All @@ -26,7 +24,6 @@ def test_flake8(self):
Note that we have a .flake8 config file for maximum line length tweak,
excluding E402 and tmp files."""
return
style_guide = flake8.get_style_guide()

# we want to use either local or system grive_indicator, but always local tests files
Expand Down
3 changes: 0 additions & 3 deletions tests/tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#! /usr/bin/env python3
# -*- coding: UTF-8 -*-

import os
from contextlib import suppress
import signal
Expand Down

0 comments on commit 4ca80fb

Please sign in to comment.