Skip to content

Commit

Permalink
Remove data files and let owndcupdate download them if they don't exist.
Browse files Browse the repository at this point in the history
  • Loading branch information
javiquinte committed Dec 20, 2017
1 parent aa063df commit 3ddb52b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
40 changes: 37 additions & 3 deletions owndc/owndcupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import os
import argparse
import logging
import urllib2 as ul

try:
import cPickle as pickle
Expand Down Expand Up @@ -112,11 +113,44 @@ def main():
# parser.add_argument('-s', '--server',
# help='Arclink server address (address.domain:18001).')
cfgname = os.path.join(os.path.expanduser('~'), '.owndc', 'owndc.cfg')
parser.add_argument('-c', '--config',
help='Config file to use.',
default=cfgname)
master = os.path.join(os.path.expanduser('~'), '.owndc', 'data', 'masterTable.xml')
routes = os.path.join(os.path.expanduser('~'), '.owndc', 'data', 'owndc-routes.xml')
# parser.add_argument('-c', '--config',
# help='Config file to use.',
# default=cfgname)
parser.add_argument('--reset',
help='Remove all configuration files and routes.')
args = parser.parse_args()

if args.reset:
try:
os.remove(cfgname)
except:
pass
try:
os.remove(master)
except:
pass
try:
os.remove(routes)
except:
pass

url = "https://raw.githubusercontent.com/javiquinte/owndc/package/owndc.cfg.sample"
cfg = ul.urlopen(url)
with open(cfgname, "w") as fout:
fout.write(cfg.read())

url = "https://raw.githubusercontent.com/javiquinte/owndc/package/data/masterTable.xml"
mas = ul.urlopen(url)
with open(master, "w") as fout:
fout.write(mas.read())

url = "https://raw.githubusercontent.com/javiquinte/owndc/package/data/owndc-routes.xml"
rou = ul.urlopen(url)
with open(routes, "w") as fout:
fout.write(rou.read())

config = configparser.RawConfigParser()
# Command line parameter has priority
try:
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.9.1a1.dev19',
version='0.9.1a1.dev21',

description='owndc: An FDSN Virtual Datacentre for SeisComP3',
long_description=long_description,
Expand Down Expand Up @@ -101,10 +101,10 @@
# need to place data files outside of your packages. See:
# http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # noqa
# In this case, 'data_file' will be installed into '<sys.prefix>/my_data'
data_files=[(path.join('/', path.expanduser('~'), '.owndc'), ['owndc.cfg']),
(path.join('/', path.expanduser('~'), '.owndc', 'data'), ['data/owndc-routes.xml']),
(path.join('/', path.expanduser('~'), '.owndc', 'data'), ['data/masterTable.xml'])
],
# data_files=[(path.join('/', path.expanduser('~'), '.owndc'), ['owndc.cfg']),
# (path.join('/', path.expanduser('~'), '.owndc', 'data'), ['data/owndc-routes.xml']),
# (path.join('/', path.expanduser('~'), '.owndc', 'data'), ['data/masterTable.xml'])
# ],

# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
Expand Down

0 comments on commit 3ddb52b

Please sign in to comment.