Skip to content

Commit

Permalink
Merge pull request OmegaK2#94 from Project-Path-of-Exile-Wiki/patches
Browse files Browse the repository at this point in the history
Merge Patches into Dev before deleting patches as a branch.
  • Loading branch information
pm5k authored Dec 9, 2022
2 parents 2ce6c3c + 48f4cc3 commit 419d630
Show file tree
Hide file tree
Showing 22 changed files with 2,202 additions and 1,185 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ __pycache__
/build
/docs/build
/docs/source/_autosummary
/docs/source/autosummary.rst
/docs/source/autosummary.rst
.vscode/launch.json
Binary file added PyPoE/_data/hardcoded_descriptions.txt
Binary file not shown.
104 changes: 86 additions & 18 deletions PyPoE/cli/exporter/wiki/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
# =============================================================================

# Python
from difflib import unified_diff
import os
import sys
import time
import re
from collections.abc import Iterable
Expand Down Expand Up @@ -192,7 +194,13 @@ def handle_page(self, *a, row):
return

if self.cmdargs.dry_run:
console(text)
if self.cmdargs.wiki_diff:
wiki_lines = page.text().splitlines(keepends=True)
new_lines = text.splitlines(keepends=True)
u_diff = unified_diff(wiki_lines, new_lines, "Wiki", "Export")
sys.stdout.writelines(u_diff)
else:
console(text)
else:
response = page.save(
text=text,
Expand All @@ -216,6 +224,7 @@ def handle_page(self, *a, row):

def handle(self, *a, mwclient, result, cmdargs, parser):
# First row is handled separately to prompt the user for his password

url = WIKIS.get(config.get_option('language'))
if url is None:
console(
Expand Down Expand Up @@ -347,24 +356,29 @@ def add_default_subparser_filters(self, sub_parser, cls, *args, **kwargs):
"""
# By id
a_id = sub_parser.add_parser(
'id',
help='Extract via a list of internal ids.'
)
self.add_default_parsers(
parser=a_id,
cls=cls,
func=cls.by_id,
*args,
**kwargs
)
a_id.add_argument(
'id',
help='Internal id. Can be specified multiple times.',
nargs='+',
)
self.add_id_subparser_filters(sub_parser, cls, *args, **kwargs)

# by name
self.add_name_subparser_filters(sub_parser, cls, *args, **kwargs)

# by row ID
self.add_rowid_subparser_filters(sub_parser, cls, *args, **kwargs)

def add_name_subparser_filters(self, sub_parser, cls, *args, **kwargs):
"""
Adds default sub parsers for id, name and rowid.
Parameters
----------
sub_parser
cls: object
Expected to have the methods:
by_name - handling for name based searching
Returns
-------
"""
a_name = sub_parser.add_parser(
'name',
help='Extract via a list of names.'
Expand All @@ -383,7 +397,21 @@ def add_default_subparser_filters(self, sub_parser, cls, *args, **kwargs):
nargs='+',
)

# by row ID
def add_rowid_subparser_filters(self, sub_parser, cls, *args, **kwargs):
"""
Adds default sub parsers for id, name and rowid.
Parameters
----------
sub_parser
cls: object
Expected to have the methods:
by_rowid - handling for rowid based searching
Returns
-------
"""
a_rid = sub_parser.add_parser(
'rowid',
help='Extract via rowid in the primary dat file.'
Expand All @@ -408,6 +436,39 @@ def add_default_subparser_filters(self, sub_parser, cls, *args, **kwargs):
help='Ending index',
type=int,
)

def add_id_subparser_filters(self, sub_parser, cls, *args, **kwargs):
"""
Adds default sub parsers for id, name and rowid.
Parameters
----------
sub_parser
cls: object
Expected to have the methods:
by_id - handling for id based searching
Returns
-------
"""
a_id = sub_parser.add_parser(
'id',
help='Extract via a list of internal ids.'
)
self.add_default_parsers(
parser=a_id,
cls=cls,
func=cls.by_id,
*args,
**kwargs
)
a_id.add_argument(
'id',
help='Internal id. Can be specified multiple times.',
nargs='+',
)


def add_default_parsers(self, parser, cls, func=None, handler=None,
wiki=True, wiki_handler=None):
Expand Down Expand Up @@ -517,6 +578,13 @@ def add_parser_arguments(parser):
action='store_true',
)

parser.add_argument(
'-w-d', '--wiki-diff',
dest='wiki_diff',
help='For use with --wiki-dry-run. Instead of printing the new page, print a diff against the existing page.',
action='store_true',
)

parser.add_argument(
'-w-msg', '--wiki-message', '--wiki-edit-message',
dest='wiki_message',
Expand Down
26 changes: 21 additions & 5 deletions PyPoE/cli/exporter/wiki/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
TranslationFileCache,
MissingIdentifierWarning,
get_custom_translation_file,
get_hardcoded_translation_file,
install_data_dependant_quantifiers,
)
from PyPoE.poe.file.file_system import FileSystem
Expand Down Expand Up @@ -1484,6 +1485,7 @@ def __init__(self, base_path, parsed_args):
)

self.custom = get_custom_translation_file()
self.hardcoded = get_hardcoded_translation_file()

self._img_path = None
self.lang = config.get_option('language')
Expand Down Expand Up @@ -1534,7 +1536,7 @@ def _format_detailed(self, custom, ingame):
)

def _write_dds(self, data, out_path, parsed_args):
out_path = fix_path(out_path)
out_path = fix_path(out_path.replace('"', "'", 2))
with open(out_path, 'wb') as f:
f.write(self.file_system.extract_dds(data))

Expand Down Expand Up @@ -1654,20 +1656,34 @@ def _get_stats(self, stats=None, values=None, mod=None,
out = [make_inter_wiki_links(line) for line in result.lines]

if result.missing_ids:
custom_result = self.custom.get_translation(
# Check for a hardcoded result first, using result's missing values.
hardcoded_result = self.hardcoded.get_translation(
result.missing_ids,
result.missing_values,
full_result=True,
lang=self.lang,
)

# Then check for a custom result, using missing values from the hardcoded results.
custom_result = self.custom.get_translation(
hardcoded_result.missing_ids,
hardcoded_result.missing_values,
full_result=True,
lang=self.lang,
)

if custom_result.missing_ids:
warnings.warn(
'Missing translation for ids %s and values %s' % (
custom_result.missing_ids, custom_result.missing_values),
f'Mod {mod["Id"] if mod is not None else "??" }: Missing translations for ids {custom_result.missing_ids} and values {custom_result.missing_values}',
MissingIdentifierWarning,
)

# Save hardcoded stat lines normally
for line in hardcoded_result.lines:
if line:
out.append(make_inter_wiki_links(line))

# Save custom stat lines with "(hidden)" appended
for line in custom_result.lines:
if line:
out.append(self._HIDDEN_FORMAT[self.lang] % line)
Expand Down Expand Up @@ -2004,7 +2020,7 @@ def f(scanner, result, tid):
bracket_count == 0:
pre_equal = True
for i in range(0, 2):
template_argument[i] = template_argument[i].strip(' \n')
template_argument[i] = template_argument[i].strip(' \n\t')

if template_argument[1]:
kw_arguments[template_argument[0]] = \
Expand Down
10 changes: 3 additions & 7 deletions PyPoE/cli/exporter/wiki/parsers/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,9 @@ def export(self, parsed_args, areas):
area)
if map:
map = map[0]
if str(map['MapSeriesKey'])[0] == 'MapWorlds':
data['main_page'] = map['BaseItemTypesKey']['Name']
else:
data['main_page'] = '%s (%s)' % (
map['BaseItemTypesKey']['Name'],
str(map['MapSeriesKey'])[0]
)
# Just set the main page to the landing page for the overall map.
# Don't try to parse out map series when the column may not even match map series.
data['main_page'] = map['BaseItemTypesKey']['Name']
elif data.get('tags') and 'map' in data['tags']:
map_version = None
for row in self.rr['MapSeries.dat']:
Expand Down
Loading

0 comments on commit 419d630

Please sign in to comment.