summaryrefslogtreecommitdiff
path: root/src/leap/services/eip/eipbootstrapper.py
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-03-13 09:43:13 -0300
committerTomás Touceda <chiiph@leap.se>2013-03-13 09:43:13 -0300
commit70c402fe170ca4e01159b03739b7cacda7b0dfd0 (patch)
treef4e552d59a2e8b651ae754e80c308c4c12984857 /src/leap/services/eip/eipbootstrapper.py
parenta3d01f3285c7432675649e26aa95e31a64b73cbf (diff)
Add mtime check for existing json definitions before download
Also, wait for threads to finish when quitting
Diffstat (limited to 'src/leap/services/eip/eipbootstrapper.py')
-rw-r--r--src/leap/services/eip/eipbootstrapper.py44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/leap/services/eip/eipbootstrapper.py b/src/leap/services/eip/eipbootstrapper.py
index 6fbb98b9..fdf54bbb 100644
--- a/src/leap/services/eip/eipbootstrapper.py
+++ b/src/leap/services/eip/eipbootstrapper.py
@@ -31,7 +31,7 @@ from leap.config.providerconfig import ProviderConfig
from leap.services.eip.eipconfig import EIPConfig
from leap.util.check import leap_assert, leap_assert_type
from leap.util.checkerthread import CheckerThread
-from leap.util.files import check_and_fix_urw_only
+from leap.util.files import check_and_fix_urw_only, get_mtime
logger = logging.getLogger(__name__)
@@ -88,33 +88,39 @@ class EIPBootstrapper(QtCore.QObject):
self._eip_config = EIPConfig()
- if self._download_if_needed and \
- os.path.exists(os.path.join(self._eip_config.get_path_prefix(),
- "leap",
- "providers",
- self._provider_config.get_domain(),
- "eip-service.json")):
- download_config_data[self.PASSED_KEY] = True
- self.download_config.emit(download_config_data)
- return True
-
try:
+ headers = {}
+ mtime = get_mtime(os.path.join(self._eip_config
+ .get_path_prefix(),
+ "leap",
+ "providers",
+ self._provider_config.get_domain(),
+ "eip-service.json"))
+
+ if self._download_if_needed and mtime:
+ headers['if-modified-since'] = mtime
+
res = self._session.get("%s/%s/%s/%s" %
(self._provider_config.get_api_uri(),
self._provider_config.get_api_version(),
"config",
"eip-service.json"),
verify=self._provider_config
- .get_ca_cert_path())
+ .get_ca_cert_path(),
+ headers=headers)
res.raise_for_status()
- eip_definition = res.content
-
- self._eip_config.load(data=eip_definition)
- self._eip_config.save(["leap",
- "providers",
- self._provider_config.get_domain(),
- "eip-service.json"])
+ # Not modified
+ if res.status_code == 304:
+ logger.debug("EIP definition has not been modified")
+ else:
+ eip_definition = res.content
+
+ self._eip_config.load(data=eip_definition)
+ self._eip_config.save(["leap",
+ "providers",
+ self._provider_config.get_domain(),
+ "eip-service.json"])
download_config_data[self.PASSED_KEY] = True
except Exception as e: