Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

Commit

Permalink
Use pkg_resources to find the config file path,
Browse files Browse the repository at this point in the history
instead of using __file__ as it would fail when packed in a zip.
Include the config file in the package adding it to MANIFEST.in
  • Loading branch information
juga0 committed Mar 23, 2018
1 parent f30063c commit e9642bb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 40 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include README LICENSE requirements.txt
include README.rst requirements.txt bwscanner/data/config.ini
12 changes: 8 additions & 4 deletions bwscanner/configutil.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os.path
from shutil import copyfile
from ConfigParser import SafeConfigParser
from pkg_resources import resource_string

from bwscanner.logger import log

Expand All @@ -21,8 +21,12 @@ def config_exists(cfg_path):


def copy_config(cfg_path, cfg_default_path=None):
# FIXME: obtain the path instead of the content
if cfg_default_path is None:
cfg_default_path = os.path.join(os.path.dirname(os.path.dirname(
os.path.abspath(__file__))), 'data', 'config.ini')
content = resource_string(__name__, 'data/config.ini')
else:
with open(cfg_default_path) as fp:
content = cfg_default_path.read()
log.debug("cfg_default_path %s" % cfg_default_path)
copyfile(cfg_default_path, cfg_path)
with open(cfg_path, 'w') as fp:
fp.write(content)
25 changes: 25 additions & 0 deletions bwscanner/data/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[default]

data_dir = ~/.config/bwscanner
measurement_dir = ~/.config/bwscanner/measurements
tor_dir = ~/.config/bwscanner/tordata
loglevel = info
logfile = bwscanner.log
baseurl = https://siv.sunet.se/bwauth/
launch_tor = True
circuit_build_timeout = 20
partitions = 1
current_partition = 1
timeout = 120
request_limit = 10
int_keys = partitions current_partition timeout request_limit
bool_keys = launch_tor

[bw_files]

64M = 6258de4f4d602be75a3458117b29d2c580c4bcb7ba5b9d2c4135c7603109f554
32M = 5a5d66d7865f09498d776f20c9e9791b055a4fff357185f84fb4ecfca7da93f0
16M = 6258de4f4d602be75a3458117b29d2c580c4bcb7ba5b9d2c4135c7603109f554
8M = 738c5604295b9377f7636ce0c2c116f093bb50372f589a6c2332a3bb6bba096a
4M = 4daaa42377d3c87577797d44a8fa569038e7a9d6a5d417a09d8ba41a69456164
2M = 3e39b0bb92912cf1ad6c01fb7c9d592e814a691c61de1f649416f6bba2d15082
33 changes: 0 additions & 33 deletions data/config.ini

This file was deleted.

3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
url=__url__,
license=__license__,
packages=find_packages(),
# data_files = [('path', ['filename'])]
data_files=[],
include_package_data=True,
entry_points={
"console_scripts": [
'bwscan = bwscanner.scanner:cli',
Expand Down

0 comments on commit e9642bb

Please sign in to comment.