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

Commit e9642bb

Browse files
committed
Use pkg_resources to find the config file path,
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
1 parent f30063c commit e9642bb

5 files changed

Lines changed: 35 additions & 40 deletions

File tree

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include README LICENSE requirements.txt
1+
include README.rst requirements.txt bwscanner/data/config.ini

bwscanner/configutil.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os.path
2-
from shutil import copyfile
32
from ConfigParser import SafeConfigParser
3+
from pkg_resources import resource_string
44

55
from bwscanner.logger import log
66

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

2222

2323
def copy_config(cfg_path, cfg_default_path=None):
24+
# FIXME: obtain the path instead of the content
2425
if cfg_default_path is None:
25-
cfg_default_path = os.path.join(os.path.dirname(os.path.dirname(
26-
os.path.abspath(__file__))), 'data', 'config.ini')
26+
content = resource_string(__name__, 'data/config.ini')
27+
else:
28+
with open(cfg_default_path) as fp:
29+
content = cfg_default_path.read()
2730
log.debug("cfg_default_path %s" % cfg_default_path)
28-
copyfile(cfg_default_path, cfg_path)
31+
with open(cfg_path, 'w') as fp:
32+
fp.write(content)

bwscanner/data/config.ini

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[default]
2+
3+
data_dir = ~/.config/bwscanner
4+
measurement_dir = ~/.config/bwscanner/measurements
5+
tor_dir = ~/.config/bwscanner/tordata
6+
loglevel = info
7+
logfile = bwscanner.log
8+
baseurl = https://siv.sunet.se/bwauth/
9+
launch_tor = True
10+
circuit_build_timeout = 20
11+
partitions = 1
12+
current_partition = 1
13+
timeout = 120
14+
request_limit = 10
15+
int_keys = partitions current_partition timeout request_limit
16+
bool_keys = launch_tor
17+
18+
[bw_files]
19+
20+
64M = 6258de4f4d602be75a3458117b29d2c580c4bcb7ba5b9d2c4135c7603109f554
21+
32M = 5a5d66d7865f09498d776f20c9e9791b055a4fff357185f84fb4ecfca7da93f0
22+
16M = 6258de4f4d602be75a3458117b29d2c580c4bcb7ba5b9d2c4135c7603109f554
23+
8M = 738c5604295b9377f7636ce0c2c116f093bb50372f589a6c2332a3bb6bba096a
24+
4M = 4daaa42377d3c87577797d44a8fa569038e7a9d6a5d417a09d8ba41a69456164
25+
2M = 3e39b0bb92912cf1ad6c01fb7c9d592e814a691c61de1f649416f6bba2d15082

data/config.ini

Lines changed: 0 additions & 33 deletions
This file was deleted.

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
url=__url__,
2323
license=__license__,
2424
packages=find_packages(),
25-
# data_files = [('path', ['filename'])]
26-
data_files=[],
25+
include_package_data=True,
2726
entry_points={
2827
"console_scripts": [
2928
'bwscan = bwscanner.scanner:cli',

0 commit comments

Comments
 (0)