barecat 0.3.2__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.
Files changed (60) hide show
  1. barecat/__init__.py +108 -0
  2. barecat/__main__.py +5 -0
  3. barecat/_api.py +143 -0
  4. barecat/_version.py +24 -0
  5. barecat/cli/__init__.py +0 -0
  6. barecat/cli/commands.py +540 -0
  7. barecat/cli/completions.py +27 -0
  8. barecat/cli/impl.py +609 -0
  9. barecat/cli/legacy.py +361 -0
  10. barecat/cli/main.py +1355 -0
  11. barecat/cli/shell.py +827 -0
  12. barecat/completions/__init__.py +1 -0
  13. barecat/completions/barecat.bash +246 -0
  14. barecat/completions/barecat.zsh +268 -0
  15. barecat/core/__init__.py +0 -0
  16. barecat/core/barecat.py +1209 -0
  17. barecat/core/index.py +1983 -0
  18. barecat/core/paths.py +61 -0
  19. barecat/core/sharder.py +328 -0
  20. barecat/core/types.py +340 -0
  21. barecat/exceptions.py +92 -0
  22. barecat/formats/__init__.py +0 -0
  23. barecat/formats/archive_formats.py +234 -0
  24. barecat/formats/from_tar_stream.py +53 -0
  25. barecat/formats/to_tar_stream.py +54 -0
  26. barecat/io/__init__.py +5 -0
  27. barecat/io/codecs.py +622 -0
  28. barecat/io/copyfile.py +550 -0
  29. barecat/io/fileobj.py +556 -0
  30. barecat/io/open.py +41 -0
  31. barecat/maintenance/__init__.py +0 -0
  32. barecat/maintenance/complete_database.py +79 -0
  33. barecat/maintenance/defrag.py +541 -0
  34. barecat/maintenance/merge.py +613 -0
  35. barecat/maintenance/reshard.py +153 -0
  36. barecat/maintenance/rsync.py +1282 -0
  37. barecat/maintenance/upgrade_database.py +200 -0
  38. barecat/maintenance/upgrade_database2.py +74 -0
  39. barecat/man/barecat.1 +284 -0
  40. barecat/sql/indexes.sql +6 -0
  41. barecat/sql/schema.sql +55 -0
  42. barecat/sql/triggers.sql +172 -0
  43. barecat/tui/__init__.py +0 -0
  44. barecat/tui/browse.py +448 -0
  45. barecat/tui/ncdu.py +318 -0
  46. barecat/util/__init__.py +0 -0
  47. barecat/util/consumed_threadpool.py +119 -0
  48. barecat/util/glob_helper.py +584 -0
  49. barecat/util/glob_to_regex.py +353 -0
  50. barecat/util/list_files.py +12 -0
  51. barecat/util/misc.py +174 -0
  52. barecat/util/physical_order.py +77 -0
  53. barecat/util/progbar.py +40 -0
  54. barecat/util/threading.py +59 -0
  55. barecat-0.3.2.dist-info/METADATA +276 -0
  56. barecat-0.3.2.dist-info/RECORD +60 -0
  57. barecat-0.3.2.dist-info/WHEEL +5 -0
  58. barecat-0.3.2.dist-info/entry_points.txt +15 -0
  59. barecat-0.3.2.dist-info/licenses/LICENSE +21 -0
  60. barecat-0.3.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1 @@
1
+ # Shell completion scripts for barecat CLI
@@ -0,0 +1,246 @@
1
+ # Bash completion for barecat
2
+ # Source this file or add to /etc/bash_completion.d/
3
+
4
+ _barecat() {
5
+ local cur prev words cword
6
+ _init_completion || return
7
+
8
+ local commands="create add extract list cat find shell browse du ncdu tree verify defrag reshard subset merge index-to-csv to-ncdu-json convert upgrade completion-script mount rsync"
9
+ local command_aliases="c a x ls l t"
10
+
11
+ # Find the subcommand
12
+ local cmd=""
13
+ for ((i=1; i < cword; i++)); do
14
+ case "${words[i]}" in
15
+ create|c|add|a|extract|x|list|ls|l|t|cat|find|shell|browse|du|ncdu|tree|verify|defrag|reshard|subset|merge|index-to-csv|to-ncdu-json|convert|upgrade|completion-script|mount|rsync)
16
+ cmd="${words[i]}"
17
+ break
18
+ ;;
19
+ esac
20
+ done
21
+
22
+ # Complete subcommands
23
+ if [[ -z "$cmd" ]]; then
24
+ COMPREPLY=($(compgen -W "$commands" -- "$cur"))
25
+ return
26
+ fi
27
+
28
+ # Complete options and arguments based on subcommand
29
+ case "$cmd" in
30
+ create|c)
31
+ case "$prev" in
32
+ -C|--directory)
33
+ _filedir -d
34
+ return
35
+ ;;
36
+ -T|--files-from|-s|--shard-size-limit)
37
+ _filedir
38
+ return
39
+ ;;
40
+ -j|--workers)
41
+ COMPREPLY=($(compgen -W "1 2 4 8 16" -- "$cur"))
42
+ return
43
+ ;;
44
+ esac
45
+ if [[ "$cur" == -* ]]; then
46
+ COMPREPLY=($(compgen -W "-C --directory -T --files-from -0 --null --exclude -i --include -j --workers -f --force -s --shard-size-limit --physical-order" -- "$cur"))
47
+ else
48
+ _filedir
49
+ fi
50
+ ;;
51
+ add|a)
52
+ case "$prev" in
53
+ -C|--directory)
54
+ _filedir -d
55
+ return
56
+ ;;
57
+ -T|--files-from|-s|--shard-size-limit)
58
+ _filedir
59
+ return
60
+ ;;
61
+ -j|--workers)
62
+ COMPREPLY=($(compgen -W "1 2 4 8 16" -- "$cur"))
63
+ return
64
+ ;;
65
+ esac
66
+ if [[ "$cur" == -* ]]; then
67
+ COMPREPLY=($(compgen -W "-C --directory -T --files-from -0 --null --exclude -i --include -j --workers -c --create -s --shard-size-limit --physical-order" -- "$cur"))
68
+ else
69
+ _filedir
70
+ fi
71
+ ;;
72
+ extract|x)
73
+ case "$prev" in
74
+ -C|--directory)
75
+ _filedir -d
76
+ return
77
+ ;;
78
+ esac
79
+ if [[ "$cur" == -* ]]; then
80
+ COMPREPLY=($(compgen -W "-C --directory --pattern -x --exclude -i --include" -- "$cur"))
81
+ else
82
+ _filedir
83
+ fi
84
+ ;;
85
+ list|ls|l|t)
86
+ if [[ "$cur" == -* ]]; then
87
+ COMPREPLY=($(compgen -W "-l --long -R --recursive --jsonl" -- "$cur"))
88
+ else
89
+ _filedir
90
+ fi
91
+ ;;
92
+ find)
93
+ case "$prev" in
94
+ -name|-path|-wholename)
95
+ return
96
+ ;;
97
+ -type)
98
+ COMPREPLY=($(compgen -W "f d" -- "$cur"))
99
+ return
100
+ ;;
101
+ -size|-maxdepth)
102
+ return
103
+ ;;
104
+ esac
105
+ if [[ "$cur" == -* ]]; then
106
+ COMPREPLY=($(compgen -W "-name -path -type -size -maxdepth -print0" -- "$cur"))
107
+ else
108
+ _filedir
109
+ fi
110
+ ;;
111
+ subset)
112
+ case "$prev" in
113
+ -o|--output)
114
+ _filedir
115
+ return
116
+ ;;
117
+ -s|--shard-size-limit)
118
+ COMPREPLY=($(compgen -W "100M 500M 1G 2G 4G" -- "$cur"))
119
+ return
120
+ ;;
121
+ esac
122
+ if [[ "$cur" == -* ]]; then
123
+ COMPREPLY=($(compgen -W "-o --output -s --shard-size-limit -f --force --pattern -i --include -x --exclude" -- "$cur"))
124
+ else
125
+ _filedir
126
+ fi
127
+ ;;
128
+ cat|shell|browse|du|ncdu|tree|verify|defrag|to-ncdu-json|index-to-csv|upgrade)
129
+ case "$cmd" in
130
+ shell)
131
+ if [[ "$cur" == -* ]]; then
132
+ COMPREPLY=($(compgen -W "-c --cmd -w --write" -- "$cur"))
133
+ return
134
+ fi
135
+ ;;
136
+ du)
137
+ if [[ "$cur" == -* ]]; then
138
+ COMPREPLY=($(compgen -W "-a --all -s --summarize -H --human-readable -d --max-depth" -- "$cur"))
139
+ return
140
+ fi
141
+ ;;
142
+ tree)
143
+ if [[ "$cur" == -* ]]; then
144
+ COMPREPLY=($(compgen -W "-L --level -d --dirs-only" -- "$cur"))
145
+ return
146
+ fi
147
+ ;;
148
+ verify)
149
+ if [[ "$cur" == -* ]]; then
150
+ COMPREPLY=($(compgen -W "--quick" -- "$cur"))
151
+ return
152
+ fi
153
+ ;;
154
+ defrag)
155
+ case "$prev" in
156
+ --max-seconds)
157
+ return
158
+ ;;
159
+ esac
160
+ if [[ "$cur" == -* ]]; then
161
+ COMPREPLY=($(compgen -W "--quick --max-seconds --smart -n --dry-run" -- "$cur"))
162
+ return
163
+ fi
164
+ ;;
165
+ upgrade)
166
+ if [[ "$cur" == -* ]]; then
167
+ COMPREPLY=($(compgen -W "-j --workers" -- "$cur"))
168
+ return
169
+ fi
170
+ ;;
171
+ esac
172
+ _filedir
173
+ ;;
174
+ reshard)
175
+ case "$prev" in
176
+ -s|--shard-size-limit)
177
+ COMPREPLY=($(compgen -W "100M 500M 1G 2G 4G" -- "$cur"))
178
+ return
179
+ ;;
180
+ esac
181
+ if [[ "$cur" == -* ]]; then
182
+ COMPREPLY=($(compgen -W "-s --shard-size-limit" -- "$cur"))
183
+ else
184
+ _filedir
185
+ fi
186
+ ;;
187
+ merge)
188
+ case "$prev" in
189
+ -o|--output)
190
+ _filedir
191
+ return
192
+ ;;
193
+ -s|--shard-size-limit)
194
+ COMPREPLY=($(compgen -W "100M 500M 1G 2G 4G" -- "$cur"))
195
+ return
196
+ ;;
197
+ esac
198
+ if [[ "$cur" == -* ]]; then
199
+ COMPREPLY=($(compgen -W "-o --output -s --shard-size-limit -f --force -a --append --symlink --ignore-duplicates --as-subdirs --prefix --pattern -i --include -x --exclude" -- "$cur"))
200
+ else
201
+ _filedir
202
+ fi
203
+ ;;
204
+ convert)
205
+ case "$prev" in
206
+ -s|--shard-size-limit)
207
+ COMPREPLY=($(compgen -W "100M 500M 1G 2G 4G" -- "$cur"))
208
+ return
209
+ ;;
210
+ --root-dir)
211
+ return
212
+ ;;
213
+ esac
214
+ if [[ "$cur" == -* ]]; then
215
+ COMPREPLY=($(compgen -W "-s --shard-size-limit -f --force --stdin --stdout --root-dir --wrap" -- "$cur"))
216
+ else
217
+ _filedir
218
+ fi
219
+ ;;
220
+ completion-script)
221
+ COMPREPLY=($(compgen -W "bash zsh" -- "$cur"))
222
+ ;;
223
+ mount)
224
+ case "$prev" in
225
+ -o|--options)
226
+ COMPREPLY=($(compgen -W "ro rw fg foreground mmap defrag overwrite append_only" -- "$cur"))
227
+ return
228
+ ;;
229
+ esac
230
+ if [[ "$cur" == -* ]]; then
231
+ COMPREPLY=($(compgen -W "-o --options" -- "$cur"))
232
+ else
233
+ _filedir
234
+ fi
235
+ ;;
236
+ rsync)
237
+ if [[ "$cur" == -* ]]; then
238
+ COMPREPLY=($(compgen -W "-n --dry-run -v --verbose --delete -c --checksum -u --update --exclude --include --progress" -- "$cur"))
239
+ else
240
+ _filedir
241
+ fi
242
+ ;;
243
+ esac
244
+ }
245
+
246
+ complete -F _barecat barecat
@@ -0,0 +1,268 @@
1
+ #compdef barecat
2
+
3
+ # Zsh completion for barecat
4
+
5
+ _barecat() {
6
+ local -a commands
7
+ commands=(
8
+ 'create:Create new archive'
9
+ 'c:Create new archive (alias)'
10
+ 'add:Add files to existing archive'
11
+ 'a:Add files (alias)'
12
+ 'extract:Extract files from archive'
13
+ 'x:Extract files (alias)'
14
+ 'list:List archive contents'
15
+ 'ls:List contents (alias)'
16
+ 'l:List contents (alias)'
17
+ 't:List contents (alias)'
18
+ 'cat:Print file contents to stdout'
19
+ 'find:Search for files in archive'
20
+ 'shell:Interactive shell'
21
+ 'browse:Ranger-like file browser'
22
+ 'du:Show disk usage'
23
+ 'ncdu:ncdu-like disk usage viewer (TUI)'
24
+ 'tree:Display directory tree'
25
+ 'verify:Verify archive integrity'
26
+ 'defrag:Defragment archive'
27
+ 'reshard:Reshard archive with new shard size'
28
+ 'subset:Create new archive with subset of files'
29
+ 'merge:Merge multiple archives into one'
30
+ 'index-to-csv:Dump index as CSV'
31
+ 'to-ncdu-json:Print as ncdu JSON'
32
+ 'convert:Convert between barecat and tar/zip'
33
+ 'upgrade:Upgrade index to new schema'
34
+ 'completion-script:Print shell completion script path'
35
+ 'mount:Mount archive as FUSE filesystem'
36
+ 'rsync:rsync-like sync between local and archive'
37
+ )
38
+
39
+ _arguments -C \
40
+ '1:command:->command' \
41
+ '*::arg:->args'
42
+
43
+ case "$state" in
44
+ command)
45
+ _describe -t commands 'barecat commands' commands
46
+ ;;
47
+ args)
48
+ case "$words[1]" in
49
+ create|c)
50
+ _arguments \
51
+ '-C[Change to directory before adding]:directory:_files -/' \
52
+ '--directory[Change to directory before adding]:directory:_files -/' \
53
+ '-T[Read paths from file (use - for stdin)]:file:_files' \
54
+ '--files-from[Read paths from file (use - for stdin)]:file:_files' \
55
+ '-0[Paths are null-separated]' \
56
+ '--null[Paths are null-separated]' \
57
+ '*--exclude[Exclude pattern]:pattern:' \
58
+ '*-i[Include pattern]:pattern:' \
59
+ '*--include[Include pattern]:pattern:' \
60
+ '-j[Worker threads]:workers:(1 2 4 8 16)' \
61
+ '--workers[Worker threads]:workers:(1 2 4 8 16)' \
62
+ '-f[Overwrite existing archive]' \
63
+ '--force[Overwrite existing archive]' \
64
+ '-s[Shard size limit]:size:(100M 500M 1G 2G 4G)' \
65
+ '--shard-size-limit[Shard size limit]:size:(100M 500M 1G 2G 4G)' \
66
+ '--physical-order[Add files in physical disk order]' \
67
+ '1:archive:_files' \
68
+ '*:paths:_files'
69
+ ;;
70
+ add|a)
71
+ _arguments \
72
+ '-C[Change to directory before adding]:directory:_files -/' \
73
+ '--directory[Change to directory before adding]:directory:_files -/' \
74
+ '-T[Read paths from file (use - for stdin)]:file:_files' \
75
+ '--files-from[Read paths from file (use - for stdin)]:file:_files' \
76
+ '-0[Paths are null-separated]' \
77
+ '--null[Paths are null-separated]' \
78
+ '*--exclude[Exclude pattern]:pattern:' \
79
+ '*-i[Include pattern]:pattern:' \
80
+ '*--include[Include pattern]:pattern:' \
81
+ '-j[Worker threads]:workers:(1 2 4 8 16)' \
82
+ '--workers[Worker threads]:workers:(1 2 4 8 16)' \
83
+ '-c[Create archive if not exists]' \
84
+ '--create[Create archive if not exists]' \
85
+ '-s[Shard size limit]:size:(100M 500M 1G 2G 4G)' \
86
+ '--shard-size-limit[Shard size limit]:size:(100M 500M 1G 2G 4G)' \
87
+ '--physical-order[Add files in physical disk order]' \
88
+ '1:archive:_files' \
89
+ '*:paths:_files'
90
+ ;;
91
+ extract|x)
92
+ _arguments \
93
+ '-C[Extract to directory]:directory:_files -/' \
94
+ '--directory[Extract to directory]:directory:_files -/' \
95
+ '--pattern[Glob pattern]:pattern:' \
96
+ '*-x[Exclude pattern]:pattern:' \
97
+ '*--exclude[Exclude pattern]:pattern:' \
98
+ '*-i[Include pattern]:pattern:' \
99
+ '*--include[Include pattern]:pattern:' \
100
+ '1:archive:_files' \
101
+ '*:paths:'
102
+ ;;
103
+ list|ls|l|t)
104
+ _arguments \
105
+ '-l[Long listing with sizes]' \
106
+ '--long[Long listing with sizes]' \
107
+ '-R[List recursively]' \
108
+ '--recursive[List recursively]' \
109
+ '--jsonl[Output as JSON lines]' \
110
+ '1:archive:_files' \
111
+ '*:paths:'
112
+ ;;
113
+ find)
114
+ _arguments \
115
+ '-name[Match basename]:pattern:' \
116
+ '-path[Match full path]:pattern:' \
117
+ '-type[File type]:type:(f d)' \
118
+ '-size[Size filter]:size:' \
119
+ '-maxdepth[Maximum depth]:depth:' \
120
+ '-print0[Null-separated output]' \
121
+ '1:archive:_files' \
122
+ '2:path:'
123
+ ;;
124
+ subset)
125
+ _arguments \
126
+ '-o[Output archive]:output:_files' \
127
+ '--output[Output archive]:output:_files' \
128
+ '-s[Shard size limit]:size:(100M 500M 1G 2G 4G)' \
129
+ '--shard-size-limit[Shard size limit]:size:(100M 500M 1G 2G 4G)' \
130
+ '-f[Overwrite if exists]' \
131
+ '--force[Overwrite if exists]' \
132
+ '--pattern[Glob pattern]:pattern:' \
133
+ '*-i[Include pattern]:pattern:' \
134
+ '*--include[Include pattern]:pattern:' \
135
+ '*-x[Exclude pattern]:pattern:' \
136
+ '*--exclude[Exclude pattern]:pattern:' \
137
+ '1:archive:_files'
138
+ ;;
139
+ cat)
140
+ _arguments \
141
+ '1:archive:_files' \
142
+ '2:path:'
143
+ ;;
144
+ shell)
145
+ _arguments \
146
+ '-c[Execute command]:command:' \
147
+ '--cmd[Execute command]:command:' \
148
+ '-w[Open in write mode]' \
149
+ '--write[Open in write mode]' \
150
+ '1:archive:_files'
151
+ ;;
152
+ browse|ncdu|to-ncdu-json|index-to-csv)
153
+ _arguments '1:archive:_files'
154
+ ;;
155
+ du)
156
+ _arguments \
157
+ '-a[Show all files]' \
158
+ '--all[Show all files]' \
159
+ '-s[Show only total]' \
160
+ '--summarize[Show only total]' \
161
+ '-H[Human readable sizes]' \
162
+ '--human-readable[Human readable sizes]' \
163
+ '-d[Max depth]:depth:' \
164
+ '--max-depth[Max depth]:depth:' \
165
+ '1:archive:_files' \
166
+ '2:path:'
167
+ ;;
168
+ tree)
169
+ _arguments \
170
+ '-L[Limit depth]:level:' \
171
+ '--level[Limit depth]:level:' \
172
+ '-d[Directories only]' \
173
+ '--dirs-only[Directories only]' \
174
+ '1:archive:_files' \
175
+ '2:path:'
176
+ ;;
177
+ verify)
178
+ _arguments \
179
+ '--quick[Quick check]' \
180
+ '1:archive:_files'
181
+ ;;
182
+ defrag)
183
+ _arguments \
184
+ '--quick[Quick defrag (time-limited)]' \
185
+ '--max-seconds[Time limit for --quick]:seconds:' \
186
+ '--smart[Smart defrag (copy contiguous chunks)]' \
187
+ '-n[Dry run - show stats only]' \
188
+ '--dry-run[Dry run - show stats only]' \
189
+ '1:archive:_files'
190
+ ;;
191
+ reshard)
192
+ _arguments \
193
+ '-s[New shard size]:size:(100M 500M 1G 2G 4G)' \
194
+ '--shard-size-limit[New shard size]:size:(100M 500M 1G 2G 4G)' \
195
+ '1:archive:_files'
196
+ ;;
197
+ merge)
198
+ _arguments \
199
+ '-o[Output archive]:output:_files' \
200
+ '--output[Output archive]:output:_files' \
201
+ '-s[Shard size limit]:size:(100M 500M 1G 2G 4G)' \
202
+ '--shard-size-limit[Shard size limit]:size:(100M 500M 1G 2G 4G)' \
203
+ '-f[Overwrite existing]' \
204
+ '--force[Overwrite existing]' \
205
+ '-a[Append to existing output]' \
206
+ '--append[Append to existing output]' \
207
+ '--symlink[Create symlinks instead of copying]' \
208
+ '--ignore-duplicates[Ignore duplicate files]' \
209
+ '--as-subdirs[Merge each archive into its own subdirectory]' \
210
+ '--prefix[Prefix for merged paths]:prefix:' \
211
+ '--pattern[Glob pattern to filter files]:pattern:' \
212
+ '-i[Include pattern]:pattern:' \
213
+ '--include[Include pattern]:pattern:' \
214
+ '-x[Exclude pattern]:pattern:' \
215
+ '--exclude[Exclude pattern]:pattern:' \
216
+ '*:archives:_files'
217
+ ;;
218
+ convert)
219
+ _arguments \
220
+ '-s[Shard size limit]:size:(100M 500M 1G 2G 4G)' \
221
+ '--shard-size-limit[Shard size limit]:size:(100M 500M 1G 2G 4G)' \
222
+ '-f[Overwrite existing]' \
223
+ '--force[Overwrite existing]' \
224
+ '--stdin[Read tar from stdin]' \
225
+ '--stdout[Write tar to stdout]' \
226
+ '--root-dir[Wrap files in root directory]:name:' \
227
+ '--wrap[Zero-copy index over existing tar/zip]' \
228
+ '1:input:_files' \
229
+ '2:output:_files'
230
+ ;;
231
+ upgrade)
232
+ _arguments \
233
+ '-j[Worker threads]:workers:(1 2 4 8 16)' \
234
+ '--workers[Worker threads]:workers:(1 2 4 8 16)' \
235
+ '1:archive:_files'
236
+ ;;
237
+ completion-script)
238
+ _arguments '1:shell:(bash zsh)'
239
+ ;;
240
+ mount)
241
+ _arguments \
242
+ '-o[Mount options]:options:' \
243
+ '--options[Mount options]:options:' \
244
+ '1:archive:_files' \
245
+ '2:mountpoint:_files -/'
246
+ ;;
247
+ rsync)
248
+ _arguments \
249
+ '-n[Dry run]' \
250
+ '--dry-run[Dry run]' \
251
+ '-v[Verbose output]' \
252
+ '--verbose[Verbose output]' \
253
+ '--progress[Show progress]' \
254
+ '--delete[Delete extraneous files from dest]' \
255
+ '-c[Compare by checksum]' \
256
+ '--checksum[Compare by checksum]' \
257
+ '-u[Skip newer files on dest]' \
258
+ '--update[Skip newer files on dest]' \
259
+ '*--include[Include pattern]:pattern:' \
260
+ '*--exclude[Exclude pattern]:pattern:' \
261
+ '*:paths:_files'
262
+ ;;
263
+ esac
264
+ ;;
265
+ esac
266
+ }
267
+
268
+ _barecat "$@"
File without changes