-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfun_shell.py
More file actions
518 lines (501 loc) · 15.4 KB
/
Copy pathfun_shell.py
File metadata and controls
518 lines (501 loc) · 15.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
from Services.DynamicPrograms import Dynamic
from Services.Things import Things
from Services.Funpiler import Funpiler
from Services.PDFer import PDFer
from Services.ImageProcessing import ImageController
from Services.Config import Configuration
from Services.Maths import CodeBook
import Services.History as History
import Services.Quotes as Quotes
import Services.WakeUp as WakeUp
import argparse
def dp_flags(sub):
dp = Dynamic()
dp_parser = sub.add_parser("dyno", help="Runs dynamic programming scripts.")
# Confilcting arguments are mutually exclusive
dp_tools = dp_parser.add_mutually_exclusive_group()
dp_tools.add_argument(
'-s',
'--sum-subset',
help=Dynamic.sum_subset.__doc__,
nargs=2,
metavar=('S="1,2,..."', 'N'),
default=False
)
dp_tools.add_argument(
'-f',
'--fib',
help=Dynamic.fibonacci.__doc__,
type=int,
metavar=('N'),
default=False
)
dp_tools.add_argument(
'-l',
'--lcs',
help=Dynamic.LCS.__doc__,
nargs=2,
metavar=('X', 'Y'),
default=False
)
dp_tools.add_argument(
'-e',
'--edit-distance',
help=Dynamic.minimum_edit_distance.__doc__,
nargs=2,
metavar=('X', 'Y'),
default=False
)
dp_tools.add_argument(
'-w',
'--word-image',
type=str,
help=Dynamic.similarity_seq_image.__doc__,
default=False
)
dp_parser.set_defaults(func=dp.start)
def things_flags(sub):
things = Things()
things_parser = sub.add_parser("things", help=Things.__doc__)
# Confilcting arguments are mutually exclusive
things_tools = things_parser.add_mutually_exclusive_group()
things_tools.add_argument(
'-g',
'--gauss-trick',
help=Things.gauss_trick.__doc__,
action='store_true',
default=False
)
things_tools.add_argument(
'-p',
'--pennys-game',
help=Things.pennys_game.__doc__,
action='store_true',
default=False
)
things_parser.add_argument(
'-s',
'--start',
type=int,
help='Number to start the sum from.',
default=1
)
things_parser.add_argument(
'-e',
'--end',
type=int,
help='Number to sum to.',
default=10
)
things_parser.set_defaults(func=things.start)
def funpiler_flags(sub):
funpiler = Funpiler()
funpiler_parser = sub.add_parser("funpiler", help=Funpiler.__doc__)
# Confilcting arguments are mutually exclusive
funpiler_tools = funpiler_parser.add_mutually_exclusive_group()
funpiler_tools.add_argument(
'-t',
'--tokenize',
help=Funpiler.scan.__doc__,
type=str,
metavar=('CODE/FILE'),
default=False
)
funpiler_tools.add_argument(
'-l',
'--logic',
help=Funpiler.logic.__doc__,
type=str,
metavar=('CODE/FILE'),
default=False
)
funpiler_parser.set_defaults(func=funpiler.start)
def pdfer_flags(sub):
pdfer = PDFer()
pdfer_parser = sub.add_parser("pdfer", help=PDFer.start.__doc__)
pdfer_parser.add_argument(
'-f',
'--file',
type=str,
help='PDF File location.',
default=False
)
pdfer_parser.add_argument(
'-b',
'--base',
action='store_true',
help='Test the pdf base.',
default=False
)
pdfer_parser.add_argument(
'-t',
'--tokens',
action='store_true',
help='Display the tokenized version of the object.',
default=False
)
pdfer_parser.add_argument(
'-r',
'--raw',
type=int,
help='Display the raw version of the object.',
metavar=('VERBOSE_LEVEL'),
default=False
)
pdfer_parser.add_argument(
'-p',
'--parsed',
action='store_true',
help='Display the parsed version of the object.',
default=False
)
pdfer_parser.add_argument(
'-o',
'--object-number',
type=int,
help='Get an object from the pdf using the cross-reference table.',
default=False
)
pdfer_parser.add_argument(
'-n',
'--fonts',
type=int,
help='Get as many fonts from the starting object number.',
default=False
)
pdfer_parser.add_argument(
'-u',
'--unicodes',
type=int,
help='Get unicode object for each font from the starting object number.',
default=False
)
pdfer_parser.add_argument(
'-T',
'--page-text',
type=int,
help='Get text from a page.',
default=False
)
pdfer_parser.add_argument(
'-i',
'--page-images',
type=int,
help='Get image objects from a page.',
default=False
)
pdfer_parser.add_argument(
'-I',
'--view-image',
nargs='+',
help='Display image from a page.(must provide page object number, you can add aditional image names)',
default=False
)
pdfer_parser.add_argument(
'-S',
'--save-image',
action='store_true',
help='Save displayed image from a page.',
default=False
)
pdfer_parser.add_argument(
'-a',
'--all',
action='store_true',
help='Display the both the raw and tokenized version of the object.',
default=False
)
pdfer_parser.add_argument(
'-s',
'--sect',
type=int,
nargs=2,
help='Get a section of the pdf file given the start and end in bytes.',
metavar=('START', 'END')
)
pdfer_parser.set_defaults(func=pdfer.start)
def impro_flags(sub):
impro = ImageController()
impro_parser = sub.add_parser("impro", help=ImageController.start.__doc__)
impro_tools = impro_parser.add_mutually_exclusive_group()
impro_parser.add_argument(
'-f',
'--file',
type=str,
help='Image File location.',
default=False
)
impro_parser.add_argument(
'-p',
'--operations',
nargs='+',
help='List of operation objects to preform on the image.',
default=False
)
impro_parser.add_argument(
'-d',
'--ocr-data',
action='store_true',
help='Print out the complete data from the ocr process.',
default=False
)
impro_tools.add_argument(
'-H',
'--histogram',
action='store_true',
help='Plot the histogram of the image.',
default=False
)
impro_tools.add_argument(
'-o',
'--ocr',
action='store_true',
help='OCR the image and print out the text.',
default=False
)
impro_tools.add_argument(
'-m',
'--method',
action='store_true',
help='Run the Harraj and Raissouni Pre-Processing method.',
default=False
)
impro_tools.add_argument(
'-r',
'--resize',
type=str,
help='Resize the image to be displayed.',
default=False
)
impro_parser.set_defaults(func=impro.start)
def config_flags(sub):
config = Configuration()
# Config application descriptor.
config_parser = sub.add_parser("config", help="Manages Configuration files for the user (case does not matter for section names only).")
# Display section from local.ini file.
config_parser.add_argument(
"-l",
"--list-section",
help="Print a section from the config file (case doesn't matter), if no arguement is given then the entire config file will be printed to console.",
nargs='?',
const=1,
default=False,
)
# Adds and updates sections and/or entries to local.ini.
config_parser.add_argument(
"--set",
help="If 1 argument is provided then it is added as a section. If 3 args are provided then the entry SECT KEY VALUE is added/updated.",
nargs='+'
)
# Deletes sections and/or entries from local.ini.
config_parser.add_argument(
"-D",
"--delete",
help="If 1 argument is provided then the section is deleted. If 2 args are provided then the entry SECT KEY VALUE is deleted.",
nargs='+'
)
# Returns the initial local fields established in the config.setup().
config_parser.add_argument(
"-m",
"--merge",
help="""Merges two config files (CURRENT into TARGET) and then ouputs them to a single file (OUTPUT).
If TARGET is Empty then the local config is used. If TARGET is Not a File and OUTPUT is not provided,
the config will attempt to write to the HOME directory labeled as 'fungrams.config.ini'.""",
nargs='+',
metavar=('DATA'),
default=False
)
# Returns the initial local fields established in the config.setup().
config_parser.add_argument(
"-d",
"--data",
help="""Dynamically adds json formatted data to the config file.
The data can be a string with json format like so '{"section": {"entry": "value"} }'.
You can also provide a json file that follows the same format.""",
type=str,
default=False
)
# Set the overwrite value when adding data
config_parser.add_argument(
"-f",
"--force",
help="""When setting/adding data to the config file this flag forces the added data to
overwrite any existing values in the config. This only applies to entry values, section names
and entry names cannot be overwritten.(Also everything is parsed in as a string)""",
action='store_true',
default=False
)
# Set the function to run for this application.
config_parser.set_defaults(func=config.start)
def history_flags(sub):
history_parser = sub.add_parser("history", help="Fetches historical passages from various history websites.")
history_parser.add_argument(
"-w",
"--website",
help="Which history website to pull passages from.(currently only 'history channel' is available)",
type=str,
default='history channel'
)
history_parser.add_argument(
"-t",
"--today",
help="Take at peak at some of the historical events that occurred today.(default True)",
action='store_true',
default=True
)
history_parser.add_argument(
"-f",
"--featured",
help="View the featured historical event that occurred today.(default False)",
action='store_true',
default=False
)
history_parser.add_argument(
"-e",
"--events",
help="View multiple historical events that occurred today.(default False)",
action='store_true',
default=False
)
# Set the function to run for this application.
history_parser.set_defaults(func=History.start)
def quotes_flags(sub):
quote_parser = sub.add_parser("quotes", help=Quotes.description)
quote_parser.add_argument(
'-s',
'--search',
help="Search and display quotes on the cmd.",
type=str,
default=False
)
quote_parser.add_argument(
'-l',
'--search-limit',
help="Set the search limit that will be displayed in the terminal.(default: %(default)s)",
type=int,
default=5
)
quote_parser.set_defaults(func=Quotes.start)
def wakeup_flags(sub):
wakeup_parser = sub.add_parser("wakeup", help=WakeUp.description)
# Confilcting arguments are mutually exclusive
wakeup_tools = wakeup_parser.add_mutually_exclusive_group()
wakeup_tools.add_argument(
'-a',
'--add',
help="Add a new command with '-c *command_name -a *command' or create a new command group with '-g *group_name -a *command_A *command_B ...etc'.",
nargs='+',
metavar='CMD',
default=[]
)
wakeup_tools.add_argument(
'-u',
'--update',
help="Update a command with '-c *command_name -u *command' or update/reorder a command group with '-g *group_name -u *command_B *command_A ...etc'.",
nargs='+',
metavar='CMD',
default=[]
)
wakeup_parser.add_argument(
'-c',
'--command',
help="Run, update(-u), or add(-a) a single command. If provided without update or add the default behavior is to run the command.",
type=str,
default=None
)
wakeup_parser.add_argument(
'-g',
'--group',
help="Run, update(-u), or add(-a) a group command. If provided without update or add the default behavior is to run the command.",
type=str,
default='default'
)
wakeup_parser.add_argument(
'-l',
'--list',
help="Show what commands and group commands are available.",
action='store_true',
default=False
)
wakeup_parser.add_argument(
'-t',
'--timeout',
help="Time in seconds to wait for a single command to finish.(range 60 - 360)(default: %(default)s)",
type=int,
choices=range(60, 361),
metavar="(60, ..., 360)",
default=60
)
wakeup_parser.set_defaults(func=WakeUp.start)
def code_book_flags(sub):
code_book_parser = sub.add_parser("codebook", help=CodeBook.__doc__)
# Confilcting arguments are mutually exclusive
code_book_tools = code_book_parser.add_mutually_exclusive_group()
code_book_tools.add_argument(
'-e',
'--encrypt',
help="Determines that the message will be encrypted.",
action='store_true',
default=True
)
code_book_tools.add_argument(
'-d',
'--decrypt',
help="Determines that the message will be decrypted.",
action='store_false',
default=True,
dest='encrypt'
)
code_book_parser.add_argument(
'-c',
'--cipher',
help="Which cipher to use.",
type=str,
choices=CodeBook.allowed_methods,
default=CodeBook.allowed_methods[0]
)
code_book_parser.add_argument(
'-m',
'--message',
help="Plain Text message to be encrypted or decrypted.",
type=str,
default='default'
)
code_book_parser.add_argument(
'-p',
'--params',
help='Input parameters that get passed to the cipher function.',
nargs='*',
metavar="KEY=VALUE",
default=[]
)
code_book_parser.add_argument(
'-v',
'--verbose',
action='count',
help='Print out the description of the cipher.',
default=0
)
code_book_parser.set_defaults(func=CodeBook.start)
def create_flags():
p = argparse.ArgumentParser(prog="FUN", description='Run rando funscripts with shell.')
# Create subparsers for applications.
sub = p.add_subparsers(help="choose an application to run")
dp_flags(sub)
things_flags(sub)
funpiler_flags(sub)
pdfer_flags(sub)
impro_flags(sub)
config_flags(sub)
history_flags(sub)
quotes_flags(sub)
wakeup_flags(sub)
code_book_flags(sub)
return p
if __name__ == '__main__':
# Create all of the flags.
parser = create_flags()
# Parse user input to match flags.
args = parser.parse_args()
# Run functions.
args.func(args)