Skip to content

Commit

Permalink
Merge pull request #58 from cc-nfi/revert-logfile-handling
Browse files Browse the repository at this point in the history
Reverted file and log path handling to original.
  • Loading branch information
Wineh authored Aug 20, 2024
2 parents 4742bd0 + 6e6401e commit 35e977d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
33 changes: 20 additions & 13 deletions bin/demeuk.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,27 @@
--check-regex <string> Drop lines that do not match the regex. Regex is a comma seperated list of
regexes. Example: [a-z]{1,8},[0-9]{1,8}
--check-min-digits <count> Require that entries contain at least <count> digits
(following the Python definition of a digit, see https://docs.python.org/3/library/stdtypes.html#str.isdigit)
(following the Python definition of a digit,
see https://docs.python.org/3/library/stdtypes.html#str.isdigit)
--check-max-digits <count> Require that entries contain at most <count> digits
(following the Python definition of a digit, see https://docs.python.org/3/library/stdtypes.html#str.isdigit)
(following the Python definition of a digit,
see https://docs.python.org/3/library/stdtypes.html#str.isdigit)
--check-min-uppercase <count> Require that entries contain at least <count> uppercase letters
(following the Python definition of uppercase, see https://docs.python.org/3/library/stdtypes.html#str.isupper)
(following the Python definition of uppercase,
see https://docs.python.org/3/library/stdtypes.html#str.isupper)
--check-max-uppercase <count> Require that entries contain at most <count> uppercase letters
(following the Python definition of uppercase, see https://docs.python.org/3/library/stdtypes.html#str.isupper)
(following the Python definition of uppercase,
see https://docs.python.org/3/library/stdtypes.html#str.isupper)
--check-min-specials <count> Require that entries contain at least <count> specials
(a special is defined as a non whitespace character which is not alphanumeric,
following the Python definitions of both, see https://docs.python.org/3/library/stdtypes.html#str.isspace and https://docs.python.org/3/library/stdtypes.html#str.isalnum)
following the Python definitions of both,
see https://docs.python.org/3/library/stdtypes.html#str.isspace
and https://docs.python.org/3/library/stdtypes.html#str.isalnum)
--check-max-specials <count> Require that entries contain at most <count> specials
(a special is defined as a non whitespace character which is not alphanumeric,
following the Python definitions of both, see https://docs.python.org/3/library/stdtypes.html#str.isspace and https://docs.python.org/3/library/stdtypes.html#str.isalnum)
following the Python definitions of both,
see https://docs.python.org/3/library/stdtypes.html#str.isspace
and https://docs.python.org/3/library/stdtypes.html#str.isalnum)
Modify modules (modify a line in place):
Expand Down Expand Up @@ -1157,7 +1165,8 @@ def clean_up(lines):

min_specials = config.get('check-min-specials')
if min_specials and not stop:
if not contains_at_least(line_decoded, min_specials, lambda char: not char.isalnum() and not char.isspace()):
if not contains_at_least(line_decoded, min_specials,
lambda char: not char.isalnum() and not char.isspace()):
log.append(f'Check_min_specials; dropped line because it contains less than '
f'{min_specials} special characters; {line_decoded}{linesep}')
stop = True
Expand Down Expand Up @@ -1580,16 +1589,14 @@ def main():
config['check-replacement-character'] = True
config['check-empty-line'] = True

output_file_path = path.realpath(output_file)
if output_file and not access(path.dirname(output_file_path), W_OK):
if output_file and not access(path.dirname(output_file), W_OK):
stderr_print(f"Cannot write output file to {output_file}")

# check if logfile exists, or that the directory of the log file is at least writable.
if log_file and not (access(log_file, F_OK) or access(path.dirname(path.realpath(log_file)), W_OK)):
if log_file and not (access(log_file, F_OK) or access(path.dirname(log_file), W_OK)):
stderr_print(f"Cannot write log file to {log_file}")

if input_file and not access(path.realpath(input_file), R_OK):
stderr_print(f"Cannot read input file from {input_file}")
if input_file and not access(input_file, R_OK):
stderr_print(f"Cannot read input file to {input_file}")

# Main worker
stderr_print(f'Main: running demeuk - {version}')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,8 @@ def test_check_special():
assert result == ['NoSpecialsHere']

result = _run_demeuk('input51', '--check-max-digits', '9999999').splitlines()
assert result == ['NoSpecialsHere', '!special', 'No?Here', 'evenSpecialer#', 'Richie£Rich', '%✓⏻', '8bytesemoji*4🙌🏽🙌🏽🙌🏽🙌🏽']
assert result == ['NoSpecialsHere', '!special', 'No?Here', 'evenSpecialer#', 'Richie£Rich', '%✓⏻',
'8bytesemoji*4🙌🏽🙌🏽🙌🏽🙌🏽']

result = _run_demeuk('input51', '--check-min-special', '1').splitlines()
assert result == ['!special', 'No?Here', 'evenSpecialer#', 'Richie£Rich', '%✓⏻', '8bytesemoji*4🙌🏽🙌🏽🙌🏽🙌🏽']
Expand All @@ -922,4 +923,3 @@ def test_check_special():

result = _run_demeuk('input51', '--check-min-special', '9999999').splitlines()
assert result == []

0 comments on commit 35e977d

Please sign in to comment.