Skip to content

Commit

Permalink
Change default output name and wording for text
Browse files Browse the repository at this point in the history
archmap_users.txt -> archmap.txt

This doesn't change anything externally, only the defaults.
  • Loading branch information
guyfawcus committed Dec 4, 2017
1 parent 783578b commit 23a2258
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 51 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ build/
dist/
docs/_build/

tests/output-archmap_users.txt
tests/output-archmap_pretty_users.txt
tests/output-archmap.txt
tests/output-archmap_pretty.txt
tests/output-archmap.csv
tests/output-archmap.geojson
tests/output-archmap.kml

tests/interactive_output-archmap_users.txt
tests/interactive_output-archmap_pretty_users.txt
tests/interactive_output-archmap.txt
tests/interactive_output-archmap_pretty.txt
tests/interactive_output-archmap.csv
tests/interactive_output-archmap.geojson
tests/interactive_output-archmap.kml
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Synopsis
--------

By default, running ``archmap`` will output four files to /tmp;
``archmap_users.txt``, ``archmap.geojson``, ``archmap.kml`` and ``archmap.csv``.
``archmap.txt``, ``archmap.geojson``, ``archmap.kml`` and ``archmap.csv``.
This can be overridden by either using the config file or by the command line switches.

The config file should be placed in ``/etc/archmap.conf``, this can be overridden by using ``--config <path-to-config-file>``
Expand Down Expand Up @@ -72,6 +72,6 @@ License

Everything in the `ArchMap repo <https://github.com/guyfawcus/ArchMap>`_ is `unlicensed <http://unlicense.org/>`_.

All of the files that this script can generate (``archmap_users.txt``, ``archmap.geojson``, ``archmap.kml``, and ``archmap.csv``)
All of the files that this script can generate (``archmap.txt``, ``archmap.geojson``, ``archmap.kml``, and ``archmap.csv``)
will contain text from the `ArchWiki <https://wiki.archlinux.org/index.php/ArchMap/List>`_
which puts them under the `GNU Free Documentation License 1.3 or later <http://www.gnu.org/copyleft/fdl.html>`_.
2 changes: 1 addition & 1 deletion archmap.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ file =
# The location to save the list of users and the GIS files,
# use 'no' or leave blank to disable output,
# use '-' to print to stdout.
users = /tmp/archmap_users.txt
users = /tmp/archmap.txt
geojson = /tmp/archmap.geojson
kml = /tmp/archmap.kml
csv = /tmp/archmap.csv
Expand Down
43 changes: 22 additions & 21 deletions archmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
default_url = 'https://wiki.archlinux.org/index.php/ArchMap/List'
default_file = ''

# If set to True, the columns in the raw user list text will be aligned
# If set to True, the columns in the raw-text list will be aligned
default_pretty = False

# Set the output locations for users, GeoJSON, KML and CSV.
# Set the output locations for the raw-text, GeoJSON, KML and CSV files.
# Setting any of the following to 'no' or leaving it blank will disable the output,
# use '-' to print the generated text to stdout.
# These settings are overridden by the config file, if it exists.
default_users = '/tmp/archmap_users.txt'
default_text = '/tmp/archmap.txt'
default_geojson = '/tmp/archmap.geojson'
default_kml = '/tmp/archmap.kml'
default_csv = '/tmp/archmap.csv'
Expand All @@ -71,7 +71,7 @@ def get_users(url='https://wiki.archlinux.org/index.php/ArchMap/List', local='')
local (str): Path to a local copy of the ArchWiki ArchMap source
Returns:
str or None: The extracted raw text list of users or None if not avaliable
str or None: The extracted raw-text list of users or None if not avaliable
"""
if local == '':
# Open and decode the page from the URL containing the list of users.
Expand All @@ -97,10 +97,11 @@ def get_users(url='https://wiki.archlinux.org/index.php/ArchMap/List', local='')


def parse_users(users):
"""This function parses the wiki text from ``users`` into it's components.
"""This function parses the raw-text list (``users``) that has been extracted from the wiki page
and splits it into a list of namedtuples containing the latitude, longitude, name and comment.
Args:
users (str): Raw user data from the ArchWiki
users (str): raw-text list from the ArchWiki
Returns:
:obj:`list` of :obj:`collections.namedtuple` \
Expand Down Expand Up @@ -130,7 +131,7 @@ def parse_users(users):
# 8. Comment
re_whole = re.compile(str(re_coord + r'\s*,\s*' + re_coord + r'[^a-zA-Z]*' + re_name + r'\s*#*\s*' + re_comment))

log.info('Parsing ArchWiki text')
log.info('Parsing ArchWiki list')
for line_number, line in enumerate(users, start=1):
# Retun None unless the line fully matches the RE
re_whole_result = re_whole.fullmatch(line)
Expand All @@ -150,8 +151,8 @@ def parse_users(users):


def make_users(parsed_users, output_file='', pretty=False):
"""This function reads the user data supplied by ``parsed_users``, it then generates
a list according to the formatting specifications on the wiki and writes it to ``output_file``.
"""This function reads the user data supplied by ``parsed_users``, it then generates a raw-text list
according to the formatting specifications on the wiki and writes it to ``output_file``.
Args:
parsed_users (:obj:`list` of :obj:`collections.namedtuple` \
Expand All @@ -171,7 +172,7 @@ def make_users(parsed_users, output_file='', pretty=False):
longest_comment = 1

if pretty:
log.debug('Finding longest strings for prettying the raw user list')
log.debug('Finding longest strings for prettifying the raw-text')
# Go through all of the elements in each list and track the length of the longest string
for user in parsed_users:
if longest_latitude < len(str(user.latitude)):
Expand All @@ -183,7 +184,7 @@ def make_users(parsed_users, output_file='', pretty=False):
if longest_comment < len(str(user.comment)):
longest_comment = len(str(user.comment))

log.debug('Making raw users')
log.debug('Making raw-text')
for user in parsed_users:
# This follows the formatting defined here:
# https://wiki.archlinux.org/index.php/ArchMap/List#Adding_yourself_to_the_list
Expand All @@ -203,7 +204,7 @@ def make_users(parsed_users, output_file='', pretty=False):
print(users)

elif output_file != '':
log.info('Writing raw user list to ' + output_file)
log.info('Writing raw-text to ' + output_file)
with open(output_file, 'w') as output:
output.write(users)

Expand Down Expand Up @@ -336,9 +337,9 @@ def main():
parser.add_argument('--file', metavar='FILE',
help='Use a file to parse the wiki list from')
parser.add_argument('--pretty', action='store_true',
help='Prettify the text user list. Only works if user output is enabled')
help='Prettify the raw-text. Only works if user output is enabled')
parser.add_argument('--users', metavar='FILE',
help="Output the user list to FILE, use 'no' to disable output or '-' to print to stdout")
help="Output the raw-text to FILE, use 'no' to disable output or '-' to print to stdout")
parser.add_argument('--geojson', metavar='FILE',
help="Output the GeoJSON to FILE, use 'no' to disable output or '-' to print to stdout")
parser.add_argument('--kml', metavar='FILE',
Expand All @@ -360,7 +361,7 @@ def main():
pretty = config.getboolean('extras', 'pretty', fallback=default_pretty)
input_url = config.get('files', 'url', fallback=default_url)
input_file = config.get('files', 'file', fallback=default_file)
output_file_users = config.get('files', 'users', fallback=default_users)
output_file_text = config.get('files', 'users', fallback=default_text)
output_file_geojson = config.get('files', 'geojson', fallback=default_geojson)
output_file_kml = config.get('files', 'kml', fallback=default_kml)
output_file_csv = config.get('files', 'csv', fallback=default_csv)
Expand Down Expand Up @@ -389,7 +390,7 @@ def main():
input_file = args.file

if args.users is not None:
output_file_users = args.users
output_file_text = args.users

if args.geojson is not None:
output_file_geojson = args.geojson
Expand All @@ -402,15 +403,15 @@ def main():

# Do what's needed.
dont_run = ['', 'no']
if output_file_users in dont_run and \
if output_file_text in dont_run and \
output_file_geojson in dont_run and \
output_file_kml in dont_run and \
output_file_csv in dont_run:
log.warning('There is nothing to do')
else:
pipe_claims = []
if output_file_users == '-':
pipe_claims.append('Users')
if output_file_text == '-':
pipe_claims.append('Text')
if output_file_geojson == '-':
pipe_claims.append('GeoJSON')
if output_file_kml == '-':
Expand All @@ -426,8 +427,8 @@ def main():
return None
parsed_users = parse_users(users)

if output_file_users not in dont_run:
make_users(parsed_users, output_file_users, pretty=pretty)
if output_file_text not in dont_run:
make_users(parsed_users, output_file_text, pretty=pretty)
if output_file_geojson not in dont_run:
make_geojson(parsed_users, output_file_geojson)
if output_file_kml not in dont_run:
Expand Down
4 changes: 2 additions & 2 deletions docs/usage/basic_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The **--help** flag will output a help message with all of the available options
Basic use
---------
By default, running **archmap** will output three files to /tmp, **archmap_users.txt**, **archmap.geojson** and **archmap.kml**,
By default, running **archmap** will output three files to /tmp, **archmap.txt**, **archmap.geojson** and **archmap.kml**,
this can be overridden by either using the config file or by the following command line switches.

Using the **--verbose** flag will print information on what the script is doing:
Expand All @@ -29,7 +29,7 @@ You can specify the output location for the user list text, GeoJSON, KML and CSV

.. code-block:: bash
archmap --users /tmp/archmap_users.txt --geojson /tmp/archmap.geojson --kml /tmp/archmap.kml --csv /tmp/archmap.csv
archmap --users /tmp/archmap.txt --geojson /tmp/archmap.geojson --kml /tmp/archmap.kml --csv /tmp/archmap.csv
If you would like to parse an alternate copy of the wiki list, simply pass either the --url or --file flags::
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 21 additions & 21 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class WikiParserTestCase(unittest.TestCase):
# including the tags needed for parsing and some test data
wiki_html = 'tests/ArchMap_List-stripped.html'

# 'raw_users.txt' contains the extracted list from 'ArchMap_List-stripped.html'
# 'sample-raw.txt' contains the extracted list from 'ArchMap_List-stripped.html'
# The trailing newline needs to be stripped to match the output from 'get_users'
with open('tests/raw_users.txt', 'r') as raw_users:
with open('tests/sample-raw.txt', 'r') as raw_users:
raw_users = raw_users.read().rstrip('\n')

def setUp(self):
Expand Down Expand Up @@ -70,16 +70,16 @@ class ListParserTestCase(unittest.TestCase):
"""These tests test that the list parser is working correctly
"""

# 'raw_users.txt' contains an unformatted 'raw' sample list
with open('tests/raw_users.txt', 'r') as raw_users_file:
# 'sample-raw.txt' contains an unformatted 'raw' sample list
with open('tests/sample-raw.txt', 'r') as raw_users_file:
raw_users = raw_users_file.read()

# 'sample_users.txt' contains a formatted sample list equivilent to the raw version above
with open('tests/sample-archmap_users.txt', 'r') as sample_users_file:
with open('tests/sample-archmap.txt', 'r') as sample_users_file:
sample_users = sample_users_file.read()

# 'sample-parsed_users.pickle' is a pickled list that was generated with a known good list
# ('parse_users()' was run on 'sample-archmap_users.txt' and the output was pickled)
# 'sample_parsed_users.pickle' is a pickled list that was generated with a known good list
# ('parse_users()' was run on 'sample-archmap.txt' and the output was pickled)
with open('tests/sample-parsed_users.pickle', 'rb') as pickled_input:
sample_parsed_users = pickle.load(pickled_input)

Expand All @@ -102,16 +102,16 @@ class OutputTestCase(unittest.TestCase):
generated by running ``archmap.py`` on the stripped-down/handmade ``ArchMap_List-stripped.html'``.
"""

# 'sample-parsed_users.pickle' is a pickled list that was generated with a known good list
# ('parse_users()' was run on 'sample-archmap_users.txt' and the output was pickled)
# 'sample_parsed_users.pickle' is a pickled list that was generated with a known good list
# ('parse_users()' was run on 'sample-archmap.txt' and the output was pickled)
with open('tests/sample-parsed_users.pickle', 'rb') as pickled_input:
parsed_users = pickle.load(pickled_input)

def setUp(self):
self.sample_users = 'tests/sample-archmap_users.txt'
self.output_users = 'tests/output-archmap_users.txt'
self.sample_pretty_users = 'tests/sample-archmap_pretty_users.txt'
self.output_pretty_users = 'tests/output-archmap_pretty_users.txt'
self.sample_users = 'tests/sample-archmap.txt'
self.output_users = 'tests/output-archmap.txt'
self.sample_pretty_users = 'tests/sample-archmap_pretty.txt'
self.output_pretty_users = 'tests/output-archmap_pretty.txt'
self.sample_geojson = 'tests/sample-archmap.geojson'
self.output_geojson = 'tests/output-archmap.geojson'
self.sample_kml = 'tests/sample-archmap.kml'
Expand Down Expand Up @@ -189,14 +189,14 @@ class ReturnedTestCase(unittest.TestCase):
generated by running ``archmap.py`` on the stripped-down/handmade ``ArchMap_List-stripped.html'``.
"""

# 'sample-parsed_users.pickle' is a pickled list that was generated with a known good list
# ('parse_users()' was run on 'sample-archmap_users.txt' and the output was pickled)
# 'sample_parsed_users.pickle' is a pickled list that was generated with a known good list
# ('parse_users()' was run on 'sample-archmap.txt' and the output was pickled)
with open('tests/sample-parsed_users.pickle', 'rb') as pickled_input:
parsed_users = pickle.load(pickled_input)

def setUp(self):
self.sample_users = 'tests/sample-archmap_users.txt'
self.sample_pretty_users = 'tests/sample-archmap_pretty_users.txt'
self.sample_users = 'tests/sample-archmap.txt'
self.sample_pretty_users = 'tests/sample-archmap_pretty.txt'
self.sample_geojson = 'tests/sample-archmap.geojson'
self.sample_kml = 'tests/sample-archmap.kml'
self.sample_csv = 'tests/sample-archmap.csv'
Expand Down Expand Up @@ -245,10 +245,10 @@ class InteractiveTestCase(unittest.TestCase):
"""

def setUp(self):
self.sample_users = 'tests/sample-archmap_users.txt'
self.output_users = 'tests/interactive_output-archmap_users.txt'
self.sample_pretty_users = 'tests/sample-archmap_pretty_users.txt'
self.output_pretty_users = 'tests/interactive_output-archmap_pretty_users.txt'
self.sample_users = 'tests/sample-archmap.txt'
self.output_users = 'tests/interactive_output-archmap.txt'
self.sample_pretty_users = 'tests/sample-archmap_pretty.txt'
self.output_pretty_users = 'tests/interactive_output-archmap_pretty.txt'
self.sample_geojson = 'tests/sample-archmap.geojson'
self.output_geojson = 'tests/interactive_output-archmap.geojson'
self.sample_kml = 'tests/sample-archmap.kml'
Expand Down

0 comments on commit 23a2258

Please sign in to comment.