skilleter-thingy 0.0.67__py3-none-any.whl → 0.0.69__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of skilleter-thingy might be problematic. Click here for more details.

@@ -10,6 +10,7 @@
10
10
 
11
11
  # TODO: Not sure it works properly as a pipe
12
12
  # TODO: Error handling in file I/O
13
+ # TODO: Ability to remove Terraform 'will be read during apply' blocks (remove from '^ <= .* \{' to ^ \}$')
13
14
 
14
15
  ################################################################################
15
16
 
@@ -63,24 +64,34 @@ TF_IGNORE_LIST = [
63
64
 
64
65
  ################################################################################
65
66
 
67
+ def error(msg):
68
+ """ Report an error and quit """
69
+
70
+ sys.stderr.write(f'{msg}\n')
71
+ sys.exit(1)
72
+
73
+ ################################################################################
74
+
66
75
  def parse_command_line():
67
76
  """ Parse, check and sanitise the command line arguments """
68
77
 
69
78
  parser = argparse.ArgumentParser(description='Read from standard input and write to standard output modifying ANSI colour codes en-route.')
70
79
 
71
- parser.add_argument('-l', '--light', action='store_true', help='Modify colours for a light background (the default)')
72
- parser.add_argument('-d', '--dark', action='store_true', help='Modify colours for a dark background')
73
- parser.add_argument('-n', '--none', action='store_true', help='Remove all colour codes')
74
- parser.add_argument('-t', '--tidy', action='store_true',
80
+ parser.add_argument('--light', '-l', action='store_true', help='Modify colours for a light background (the default)')
81
+ parser.add_argument('--dark', '-d', action='store_true', help='Modify colours for a dark background')
82
+ parser.add_argument('--none', '-n', action='store_true', help='Remove all colour codes')
83
+ parser.add_argument('--tidy', '-t', action='store_true',
75
84
  help='Remove colour codes and stuff that typically occurs in log files causing diffs, but is of no particular interest (e.g. SHA1 values, times, dates)')
76
- parser.add_argument('-s', '--strip-blank', action='store_true', help='Strip all blank lines')
77
- parser.add_argument('-D', '--debug', action='store_true', help='Replace colours with debug information')
78
- parser.add_argument('-o', '--out', action='store_true', help='Output to standard output rather than overwriting input files')
79
- parser.add_argument('-O', '--dir', action='store', default=None, help='Store output files in the specified directory (creating it if it doesn\'t exist)')
80
- parser.add_argument('-a', '--aws', action='store_true', help='Remove AWS resource IDs')
81
- parser.add_argument('-T', '--terraform', action='store_true', help='Clean Terraform plan/apply log files')
82
- parser.add_argument('-R', '--replace', action='append', default=None, help='Additional regex replacements in the form "REGEX=REPLACEMENT"')
83
- parser.add_argument('-v', '--verbose', action='store_true', help='Output verbose status')
85
+ parser.add_argument('--strip-blank', '-s', action='store_true', help='Strip all blank lines')
86
+ parser.add_argument('--debug', '-D', action='store_true', help='Replace colours with debug information')
87
+ parser.add_argument('--out', '-o', action='store_true', help='Output to standard output rather than overwriting input files')
88
+ parser.add_argument('--dir', '-O', action='store', default=None, help='Store output files in the specified directory (creating it if it doesn\'t exist)')
89
+ parser.add_argument('--aws', '-a', action='store_true', help='Remove AWS resource IDs')
90
+ parser.add_argument('--terraform', '-T', action='store_true', help='Clean Terraform plan/apply log files')
91
+ parser.add_argument('--replace', '-R', action='append', default=None, help='Additional regex replacements in the form "REGEX=REPLACEMENT"')
92
+ parser.add_argument('--verbose', '-v', action='store_true', help='Output verbose status')
93
+ parser.add_argument('--minimal', '-m', action='store_true', help='Remove unnecessary data from the file (e.g. Terraform progress updates (Refreshing..., Reading..., etc.))')
94
+ parser.add_argument('--non-minimal', '-M', action='store_true', help='Do not remove unnecessary data from the file (e.g. Terraform progress updates (Refreshing..., Reading..., etc.))')
84
95
  parser.add_argument('files', nargs='*', default=None, help='The files to convert (use stdin/stout if no input files are specified)')
85
96
 
86
97
  args = parser.parse_args()
@@ -94,23 +105,29 @@ def parse_command_line():
94
105
  # Can't do more than one transformation
95
106
 
96
107
  if args.light + args.dark + args.none + args.debug > 1:
97
- print('ERROR: Only one colour conversion option can be specified')
98
- sys.exit(1)
108
+ error('ERROR: Only one colour conversion option can be specified')
99
109
 
100
110
  if args.tidy and (args.light or args.dark or args.debug):
101
- print('ERROR: The tidy and colour conversion options cannot be specified together')
102
- sys.exit(1)
111
+ error('ERROR: The tidy and colour conversion options cannot be specified together')
103
112
 
104
- # Default to doing cleanup - removing colour codes, times & Terraform cleanup
113
+ if args.minimal and args.non_minimal:
114
+ error('ERROR: Cannot use minimal and non-minimal options together')
105
115
 
106
- if not args.light and not args.dark and not args.tidy and not args.strip_blank and not args.terraform:
107
- args.strip_blank = args.none = args.tidy = args.terraform = True
108
- logging.info('No options specified - defaulting to stripping blanks, removing colour codes, tidying and cleaning Terraform data')
116
+ # Default to doing cleanup - removing colour codes, times & Terraform & minimal cleanup
117
+
118
+ if not args.light and not args.dark and not args.tidy and not args.strip_blank and not args.terraform and not args.minimal and not args.non_minimal:
119
+ args.strip_blank = args.none = args.tidy = args.terraform = args.minimal = True
120
+ logging.info('No options specified - defaulting to stripping blanks, removing colour codes, tidying, cleaning Terraform data and removing unnecessary data')
109
121
 
110
122
  # Terraform option also removes ANSI, etc.
111
123
 
112
124
  if args.terraform:
113
- args.strip_blank = args.tidy = args.none = True
125
+ args.strip_blank = args.tidy = args.none = args.minimal = True
126
+
127
+ # Non-minimal overrides minimal
128
+
129
+ if args.non_minimal:
130
+ args.minimal = False
114
131
 
115
132
  # Create the output directory, if required
116
133
 
@@ -206,9 +223,16 @@ def cleanfile(args, infile, outfile):
206
223
  for entry in args.regex_replace:
207
224
  clean = entry['regex'].sub(entry['replace'], clean)
208
225
 
226
+ # Additional cleanup - remove 'noise' from the output (currently just TF-related).
227
+
228
+ if args.minimal:
229
+ if args.terraform:
230
+ if TF_REFRESHING_AND_READING.match(clean):
231
+ clean = None
232
+
209
233
  # Do things with Terraform log data
210
234
 
211
- if args.terraform:
235
+ if clean and args.terraform:
212
236
  clean = tidy.regex_replace(clean, TF_MISC_REGEX)
213
237
 
214
238
  for ignore in TF_IGNORE_LIST:
@@ -308,7 +332,7 @@ def main():
308
332
  if args.files:
309
333
  try:
310
334
  for filename in args.files:
311
- with open(filename, 'rt') as infile:
335
+ with open(filename, 'rt', encoding='utf8') as infile:
312
336
 
313
337
  # Either write to stdout or to a temporary file
314
338
 
@@ -332,12 +356,16 @@ def main():
332
356
  if args.dir:
333
357
  # Writing to a directory - just move the output file there unconditionally
334
358
 
359
+ logging.info('Writing %s to %s', outfile_name, args.dir)
360
+
335
361
  shutil.move(outfile_name, os.path.join(args.dir, os.path.basename(filename)))
336
362
 
337
363
  elif not filecmp.cmp(outfile_name, filename, shallow=False):
338
364
  # Only backup and write the source file if changes have been made (original is
339
365
  # left in place without a backup if nothing's changed)
340
366
 
367
+ logging.info('Backing up old file and writing new %s', outfile_name)
368
+
341
369
  files.backup(filename)
342
370
 
343
371
  shutil.move(outfile_name, filename)
@@ -345,6 +373,8 @@ def main():
345
373
  else:
346
374
  # Output file hasn't been used, so just delete it
347
375
 
376
+ logging.info('No changes made to %s', outfile_name)
377
+
348
378
  os.unlink(outfile_name)
349
379
 
350
380
  except FileNotFoundError as exc:
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: skilleter_thingy
3
- Version: 0.0.67
3
+ Version: 0.0.69
4
4
  Summary: A collection of useful utilities, mainly aimed at making Git more friendly
5
5
  Author-email: John Skilleter <john@skilleter.org.uk>
6
6
  Project-URL: Home, https://skilleter.org.uk
@@ -28,7 +28,7 @@ skilleter_thingy/moviemover.py,sha256=j_Xb9_jFdgpFBAXcF4tEqbnKH_FonlnUU39LiCK980
28
28
  skilleter_thingy/photodupe.py,sha256=l0hbzSLb2Vk2ceteg-x9fHXCEE1uUuFo84hz5rsZUPA,4184
29
29
  skilleter_thingy/phototidier.py,sha256=5gSjlINUxf3ZQl3NG0o7CsWwODvTbokIMIafLFvn8Hc,7818
30
30
  skilleter_thingy/py_audit.py,sha256=xJm5k5qyeA6ii8mODa4dOkmP8L1drv94UHuxR54RsIM,4384
31
- skilleter_thingy/readable.py,sha256=G-t6tINmi8qxYoD4qPc7LZbD4EjEjGJmWe2quzqaGB4,13945
31
+ skilleter_thingy/readable.py,sha256=HR68vsm5xki6UF_p_1c6Dqsy9Yi7kW4RI-Z7qsLKor8,15414
32
32
  skilleter_thingy/remdir.py,sha256=SkN9xEc1ckFGRP4zS2LUbx7Ihw697YMV0ybr_-afiyE,4653
33
33
  skilleter_thingy/rmdupe.py,sha256=tcX3w8XvliGwBMdSt9BUu07kuDtQEc0IiU8sCxmgzHA,17117
34
34
  skilleter_thingy/rpylint.py,sha256=TzZ5GvWrqgTKYKZwadTvzdbX-DJ8ll4WfVJqtN6IzO0,2635
@@ -60,9 +60,9 @@ skilleter_thingy/thingy/run.py,sha256=6SNKWF01fSxzB10GMU9ajraXYZqAL1w0PXkqjJdr1U
60
60
  skilleter_thingy/thingy/tfm_pane.py,sha256=oqy5zBzKwfbjbGqetbbhpKi4x5He7sl4qkmhUeqtdZc,19789
61
61
  skilleter_thingy/thingy/tidy.py,sha256=71DCyj0VJrj52RmjQyj1eOiQJIfy5EIPHuThOrS6ZTA,5876
62
62
  skilleter_thingy/thingy/venv_template.py,sha256=SsVNvSwojd8NnFeQaZPCRQYTNdwJRplpZpygbUEXRnY,1015
63
- skilleter_thingy-0.0.67.dist-info/LICENSE,sha256=ljOS4DjXvqEo5VzGfdaRwgRZPbNScGBmfwyC8PChvmQ,32422
64
- skilleter_thingy-0.0.67.dist-info/METADATA,sha256=QyAVcQ0li8sze2R7YS4ktG3J85dSOEVtVJHqir8Vkec,5313
65
- skilleter_thingy-0.0.67.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
66
- skilleter_thingy-0.0.67.dist-info/entry_points.txt,sha256=LxYRrQHkCGK-zjLXHqRdsUSUOoBbh7e8YUN1IVs5vIs,2072
67
- skilleter_thingy-0.0.67.dist-info/top_level.txt,sha256=8-JhgToBBiWURunmvfpSxEvNkDHQQ7r25-aBXtZv61g,17
68
- skilleter_thingy-0.0.67.dist-info/RECORD,,
63
+ skilleter_thingy-0.0.69.dist-info/LICENSE,sha256=ljOS4DjXvqEo5VzGfdaRwgRZPbNScGBmfwyC8PChvmQ,32422
64
+ skilleter_thingy-0.0.69.dist-info/METADATA,sha256=bkdkX-7xamc-FoQaF6jy_Oko0Xc5qSEOCaIE-6FDT3c,5313
65
+ skilleter_thingy-0.0.69.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
66
+ skilleter_thingy-0.0.69.dist-info/entry_points.txt,sha256=LxYRrQHkCGK-zjLXHqRdsUSUOoBbh7e8YUN1IVs5vIs,2072
67
+ skilleter_thingy-0.0.69.dist-info/top_level.txt,sha256=8-JhgToBBiWURunmvfpSxEvNkDHQQ7r25-aBXtZv61g,17
68
+ skilleter_thingy-0.0.69.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5