skilleter-thingy 0.0.39__py3-none-any.whl → 0.0.41__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.

Files changed (68) hide show
  1. skilleter_thingy/__init__.py +6 -0
  2. skilleter_thingy/addpath.py +107 -0
  3. skilleter_thingy/borger.py +269 -0
  4. skilleter_thingy/console_colours.py +63 -0
  5. skilleter_thingy/diskspacecheck.py +67 -0
  6. skilleter_thingy/docker_purge.py +113 -0
  7. skilleter_thingy/ffind.py +536 -0
  8. skilleter_thingy/ggit.py +90 -0
  9. skilleter_thingy/ggrep.py +154 -0
  10. skilleter_thingy/git_br.py +180 -0
  11. skilleter_thingy/git_ca.py +142 -0
  12. skilleter_thingy/git_cleanup.py +287 -0
  13. skilleter_thingy/git_co.py +220 -0
  14. skilleter_thingy/git_common.py +61 -0
  15. skilleter_thingy/git_hold.py +154 -0
  16. skilleter_thingy/git_mr.py +92 -0
  17. skilleter_thingy/git_parent.py +77 -0
  18. skilleter_thingy/git_review.py +1428 -0
  19. skilleter_thingy/git_update.py +385 -0
  20. skilleter_thingy/git_wt.py +96 -0
  21. skilleter_thingy/gitcmp_helper.py +322 -0
  22. skilleter_thingy/gitprompt.py +274 -0
  23. skilleter_thingy/gl.py +174 -0
  24. skilleter_thingy/gphotosync.py +610 -0
  25. skilleter_thingy/linecount.py +155 -0
  26. skilleter_thingy/moviemover.py +133 -0
  27. skilleter_thingy/photodupe.py +136 -0
  28. skilleter_thingy/phototidier.py +248 -0
  29. skilleter_thingy/py_audit.py +131 -0
  30. skilleter_thingy/readable.py +270 -0
  31. skilleter_thingy/remdir.py +126 -0
  32. skilleter_thingy/rmdupe.py +550 -0
  33. skilleter_thingy/rpylint.py +91 -0
  34. skilleter_thingy/splitpics.py +99 -0
  35. skilleter_thingy/strreplace.py +82 -0
  36. skilleter_thingy/sysmon.py +435 -0
  37. skilleter_thingy/tfm.py +920 -0
  38. skilleter_thingy/tfparse.py +101 -0
  39. skilleter_thingy/thingy/__init__.py +6 -0
  40. skilleter_thingy/thingy/colour.py +213 -0
  41. skilleter_thingy/thingy/dc_curses.py +278 -0
  42. skilleter_thingy/thingy/dc_defaults.py +221 -0
  43. skilleter_thingy/thingy/dc_util.py +50 -0
  44. skilleter_thingy/thingy/dircolors.py +308 -0
  45. skilleter_thingy/thingy/docker.py +95 -0
  46. skilleter_thingy/thingy/files.py +142 -0
  47. skilleter_thingy/thingy/git.py +1371 -0
  48. skilleter_thingy/thingy/git2.py +1307 -0
  49. skilleter_thingy/thingy/gitlab.py +193 -0
  50. skilleter_thingy/thingy/logger.py +112 -0
  51. skilleter_thingy/thingy/path.py +156 -0
  52. skilleter_thingy/thingy/popup.py +87 -0
  53. skilleter_thingy/thingy/process.py +112 -0
  54. skilleter_thingy/thingy/run.py +334 -0
  55. skilleter_thingy/thingy/tfm_pane.py +595 -0
  56. skilleter_thingy/thingy/tidy.py +160 -0
  57. skilleter_thingy/trimpath.py +84 -0
  58. skilleter_thingy/window_rename.py +92 -0
  59. skilleter_thingy/xchmod.py +125 -0
  60. skilleter_thingy/yamlcheck.py +89 -0
  61. {skilleter_thingy-0.0.39.dist-info → skilleter_thingy-0.0.41.dist-info}/METADATA +1 -1
  62. skilleter_thingy-0.0.41.dist-info/RECORD +66 -0
  63. skilleter_thingy-0.0.41.dist-info/top_level.txt +1 -0
  64. skilleter_thingy-0.0.39.dist-info/RECORD +0 -6
  65. skilleter_thingy-0.0.39.dist-info/top_level.txt +0 -1
  66. {skilleter_thingy-0.0.39.dist-info → skilleter_thingy-0.0.41.dist-info}/LICENSE +0 -0
  67. {skilleter_thingy-0.0.39.dist-info → skilleter_thingy-0.0.41.dist-info}/WHEEL +0 -0
  68. {skilleter_thingy-0.0.39.dist-info → skilleter_thingy-0.0.41.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,142 @@
1
+ #! /usr/bin/env python3
2
+
3
+ ################################################################################
4
+ """ Thingy file handling functions
5
+
6
+ Copyright (C) 2017-18 John Skilleter
7
+
8
+ High-level file access functions not provided by the Python libraries
9
+ """
10
+ ################################################################################
11
+
12
+ import os
13
+ import shutil
14
+
15
+ # TODO: Convert to use thingy.proc
16
+ import thingy.process as process
17
+
18
+ ################################################################################
19
+
20
+ def is_binary_file(filename):
21
+ """ Return True if there is a strong likelihood that the specified file
22
+ is binary. """
23
+
24
+ return file_type(filename, mime=True).endswith('binary')
25
+
26
+ ################################################################################
27
+
28
+ def file_type(filename, mime=False):
29
+ """ Return a textual description of the file type """
30
+
31
+ # The file utility does not return an error if the file does not exist or
32
+ # is not a file, so we have to do that.
33
+
34
+ if not os.path.isfile(filename) or not os.access(filename, os.R_OK):
35
+ raise IOError('Unable to access %s' % filename)
36
+
37
+ cmd = ['file', '--brief']
38
+
39
+ if mime:
40
+ cmd.append('--mime')
41
+
42
+ cmd.append(filename)
43
+
44
+ return process.run(cmd)[0]
45
+
46
+ ################################################################################
47
+
48
+ def format_size(size, always_suffix=False):
49
+ """ Convert a memory/disk size into appropriately-scaled units in bytes,
50
+ MiB, GiB, TiB as a string """
51
+
52
+ # Keep all the maths positive
53
+
54
+ if size < 0:
55
+ size = -size
56
+ sign = '-'
57
+ else:
58
+ sign = ''
59
+
60
+ # Default divisor and number of decimal places output
61
+
62
+ div = 1
63
+
64
+ # Step through the multipliers
65
+
66
+ for units in (' bytes' if always_suffix else '', ' KiB', ' MiB', ' GiB', ' TiB'):
67
+ # If we can't scale up to this multiplier quit the loop
68
+
69
+ if size // div < 1024:
70
+ break
71
+
72
+ # Increase the divisor and set the number of decimal places
73
+ # to 1 (set to 0 when we don't have a divisor).
74
+
75
+ div *= 1024
76
+
77
+ # Calculate the size in 10ths so the we get the first digit after
78
+ # the decimal point, doing all the work in the integer domain to
79
+ # avoid rounding errors.
80
+
81
+ size_x_10 = (size * 10) // div
82
+
83
+ # If the decimal part would be '.0' don't output it
84
+
85
+ if size_x_10 % 10 == 0:
86
+ return '%s%d%s' % (sign, size_x_10 // 10, units)
87
+
88
+ return '%s%d.%d%s' % (sign, size_x_10 // 10, size_x_10 % 10, units)
89
+
90
+ ################################################################################
91
+
92
+ def backup(filename, extension='bak', copyfile=True):
93
+ """ Create a backup of a file by copying or renaming it into a file with extension
94
+ .bak, deleting any existing file with that name """
95
+
96
+ # Do nothing if the file does not exist
97
+
98
+ if not os.path.isfile(filename):
99
+ return
100
+
101
+ # Split on the dot characters
102
+
103
+ filename_comp = filename.split('.')
104
+
105
+ # Replace the extension with the specified on (or 'bak' by
106
+ # default) or add it if the filename did not have an extension.
107
+
108
+ if len(filename_comp) > 1:
109
+ filename_comp[-1] = extension
110
+ else:
111
+ filename_comp.append(extension)
112
+
113
+ backupname = '.'.join(filename_comp)
114
+
115
+ # Remove any existing backup file
116
+
117
+ if os.path.isfile(backupname):
118
+ os.unlink(backupname)
119
+
120
+ # Create the backup by copying or renaming the file
121
+
122
+ if copyfile:
123
+ shutil.copyfile(filename, backupname)
124
+ else:
125
+ os.rename(filename, backupname)
126
+
127
+ ################################################################################
128
+ # Test code
129
+
130
+ if __name__ == "__main__":
131
+ print('Is /bin/sh binary: %s' % is_binary_file('/bin/sh'))
132
+ print('Is files.py binary: %s' % is_binary_file('thingy/files.py'))
133
+ print('')
134
+
135
+ for mimeflag in (False, True):
136
+ print('/bin/sh is: %s' % file_type('/bin/sh', mimeflag))
137
+ print('/bin/dash is: %s' % file_type('/bin/dash', mimeflag))
138
+ print('git-ca is: %s' % file_type('git-ca', mimeflag))
139
+ print('')
140
+
141
+ for sizevalue in (0, 1, 999, 1024, 1025, 1.3 * 1024, 2**32 - 1, 2**64 + 2**49):
142
+ print('%24d is %s' % (sizevalue, format_size(sizevalue)))