summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2015-10-27 12:54:09 +0100
committeremkael <emkael@tlen.pl>2015-10-27 12:54:09 +0100
commitbb5ef4af39208028e852eaba9830b608c9a636c7 (patch)
tree3bd8f8be21d945296f3ca3ca1fedc0f373872b33
parent8f36d662c1a9afdd204e9549ce665c13d1df3ea0 (diff)
* PEP257 compliance for docstrings
-rw-r--r--src/virtual_table.py70
1 files changed, 31 insertions, 39 deletions
diff --git a/src/virtual_table.py b/src/virtual_table.py
index 3c213c2..15efe65 100644
--- a/src/virtual_table.py
+++ b/src/virtual_table.py
@@ -1,4 +1,6 @@
-""" Virtual tables for JFR Pary result pages.
+"""
+Virtual tables for JFR Pary result pages.
+
Utility to clean up pages generated by JFR Pary from data on virtual tables.
"""
@@ -16,10 +18,11 @@ __version__ = '1.0.1'
def bs4_fix_file(worker_method):
- """ Decorator for manipulating files with BeautifulSoup4
- """
+ """Decorator for manipulating files with BeautifulSoup4."""
def file_wrapper(self, file_path, encoding='utf-8'):
- """ Wrapper for DOM manipulation.
+ """
+ Wrapper for DOM manipulation.
+
Wraps the inner function into BS4 invokation and file overwrite.
"""
with file(file_path, 'r+') as content_file:
@@ -33,8 +36,7 @@ def bs4_fix_file(worker_method):
def fill_pair_list_table(cells, row_cell_count=20):
- """ Formats cell list into well-formed rows, aligned by column count.
- """
+ """Format cell list into well-formed rows, aligned by column count."""
content = bs4('<table />', 'lxml')
content.append(content.new_tag('table'))
# first filler cell of each new row
@@ -72,12 +74,10 @@ def fill_pair_list_table(cells, row_cell_count=20):
class JFRVirtualTable(object):
- """ Virtual tables formatter (for JFR Pary pages)
- """
+ """Virtual tables formatter (for JFR Pary pages)."""
def __parse_filepaths(self, prefix):
- """ Detects all filepaths for results pages.
- """
+ """Detect all filepaths for results pages."""
file_path = path.realpath(prefix)
log.getLogger('paths').debug('realpath = %s', file_path)
tournament_path = path.dirname(file_path)
@@ -93,7 +93,9 @@ class JFRVirtualTable(object):
traveller_files_match.pattern)
def get_path(relative_path):
- """ Compiles full path for tournament file from base name.
+ """
+ Compile full path for tournament file from base name.
+
Converts {prefix}{anything}.{ext} filename to full path.
"""
return path.join(tournament_path, relative_path)
@@ -145,8 +147,7 @@ class JFRVirtualTable(object):
self.__single_files['collected_scores'])
def __detect_virtual_pairs(self):
- """ Auto-detect virtual pairs by their record file header.
- """
+ """Auto-detect virtual pairs by their record file header."""
virtual_pairs = []
# RegEx for matching pair number and names in pair record header
pair_header_match = re.compile('([0-9]{1,}): (.*) - (.*), .*')
@@ -184,8 +185,7 @@ class JFRVirtualTable(object):
@bs4_fix_file
def __fix_results(self, content):
- """ Fixes simple results list by removing virtual pair rows.
- """
+ """Fix simple results list by removing virtual pair rows."""
rows = content.select('tr')
for row in rows:
cells = row.select('td')
@@ -207,8 +207,7 @@ class JFRVirtualTable(object):
@bs4_fix_file
def __fix_full_results(self, content):
- """ Fixes full results file by removing virtual pair rows.
- """
+ """Fix full results file by removing virtual pair rows."""
rows = content.select('tr')
for row in rows:
# select rows by cells containing pair records links
@@ -229,8 +228,7 @@ class JFRVirtualTable(object):
@bs4_fix_file
def __fix_records_list(self, content):
- """ Fixes the page with pair records links list.
- """
+ """Fix the page with pair records links list."""
# read the original column count
row_cell_count = int(content.table.select('tr td.o')[0]['colspan'])
log.getLogger('rec_list').debug('found %d cells in column',
@@ -281,8 +279,7 @@ class JFRVirtualTable(object):
@bs4_fix_file
def __fix_collected(self, content):
- """ Fixes collected scores tables by removing virtual pair rows.
- """
+ """Fix collected scores tables by removing virtual pair rows."""
rows = content.select('tr')
for row in rows:
cells = row.select('td')
@@ -310,8 +307,10 @@ class JFRVirtualTable(object):
@bs4_fix_file
def __fix_traveller(self, content):
- """ Fixes board travellers, removing virtual tables and leaving one,
- annotated.
+ """
+ Fix board travellers.
+
+ Removes virtual tables and leaving one, annotated.
"""
# This should only happen if the traveller wasn't already processed
# as it's the only operaton that may yield any results on second run
@@ -389,6 +388,7 @@ class JFRVirtualTable(object):
__header_text = '' # text for traveller header row
def __init__(self, path_prefix, virtual_pairs=None, header_text=''):
+ """Construct main parser object."""
log.getLogger('init').debug('parsing filepaths, prefix = %s',
path_prefix)
self.__parse_filepaths(path_prefix)
@@ -401,18 +401,15 @@ class JFRVirtualTable(object):
self.__header_text = header_text
def fix_results(self):
- """ Fixes results for specific detected tournament files.
- """
+ """Fix results for specific detected tournament files."""
self.__fix_results(self.__single_files['results'])
def fix_full_results(self):
- """ Fixes full results for specific detected tournament files.
- """
+ """Fix full results for specific detected tournament files."""
self.__fix_full_results(self.__single_files['full_results'])
def fix_collected_scores(self):
- """ Fixes collected scores for specific detected tournament files.
- """
+ """Fix collected scores for specific detected tournament files."""
if path.isfile(self.__single_files['collected_scores']):
self.__fix_collected(self.__single_files['collected_scores'])
else:
@@ -421,13 +418,11 @@ class JFRVirtualTable(object):
self.__single_files['collected_scores'])
def fix_records_list(self):
- """ Fixes pair records list for specific detected tournament files.
- """
+ """Fix pair records list for specific detected tournament files."""
self.__fix_records_list(self.__single_files['pair_records_list'])
def fix_travellers(self):
- """ Fixes board travellers for specific detected tournament files.
- """
+ """Fix board travellers for specific detected tournament files."""
for traveller_file in self.__traveller_files:
log.getLogger('traveller').info('fixing traveller: %s',
traveller_file)
@@ -439,16 +434,14 @@ class JFRVirtualTable(object):
def main():
- """ Program entry point, invoked when __name__ is __main__
- """
+ """Program entry point, invoked when __name__ is __main__."""
import argparse
argument_parser = argparse.ArgumentParser(
description='Fix display for virtual tables in JFR Pary result pages')
def file_path(filepath):
- """ Sanitizes and validates file paths from input parameters.
- """
+ """Sanitize and validate file paths from input parameters."""
filepath = unicode(filepath, sys.getfilesystemencoding())
if path.isfile(filepath):
return filepath
@@ -456,8 +449,7 @@ def main():
argument_parser.error('File %s does not exist' % filepath)
def decoded_text(text):
- """ Sanitizes and normalizes command line input for parameters.
- """
+ """Sanitize and normalize command line input for parameters."""
return unicode(text, sys.getfilesystemencoding())
argument_parser.add_argument('-V', '--version', action='version',