mirror of
https://github.com/Xevion/sharex-quickzoom.git
synced 2025-12-17 16:13:15 -06:00
jumps in form ability, about form ui, QGraphicsView clicking functionality, massive package restructuring
This commit is contained in:
60
package/utils/clean.py
Normal file
60
package/utils/clean.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import os, sys, send2trash
|
||||
|
||||
blacklist = [
|
||||
# files
|
||||
'clean.py',
|
||||
'main.py',
|
||||
'LICENSE.md',
|
||||
'screenshot.png',
|
||||
'README.md',
|
||||
'.git',
|
||||
# folders
|
||||
'.gitignore',
|
||||
'resources'
|
||||
]
|
||||
|
||||
def run(recycle=True, print_ignores=False):
|
||||
"""Main driver function for recycling unneeded files from the folder.
|
||||
|
||||
Keyword Arguments:
|
||||
recycle {bool} -- True to recycle and send to recycle bin instead of permanently delete a file. (default: {True})
|
||||
print_ignores {bool} -- True to print what files have been ignored (default: {False})
|
||||
"""
|
||||
|
||||
# ternary raise support function, shouldn't ever be raised normally
|
||||
def raiseMe(filePath):
|
||||
raise('Invalid file or folder ; \'{}\''.format(filePath))
|
||||
|
||||
# Constants
|
||||
basepath = sys.path[0]
|
||||
_logFiles = []
|
||||
_logFolders = []
|
||||
getName = lambda someList : 'folder' if someList is _logFolders else 'file' if someList is _logFiles else '???'
|
||||
|
||||
print('Deletion sequence started')
|
||||
for file in os.listdir(basepath):
|
||||
filepath = os.path.join(basepath, file)
|
||||
# Take action on the offending file
|
||||
if file not in blacklist:
|
||||
# Send to recycle bin vs straightup permanently delete
|
||||
curType = _logFiles if os.path.isfile(filepath) else _logFolders if os.path.isdir(filepath) else raiseMe(filepath)
|
||||
# We want to recycle the file
|
||||
if recycle:
|
||||
send2trash.send2trash(filepath)
|
||||
curType.append('Recycled {}: \'{}\''.format(getName(curType), filepath))
|
||||
# We want to permanently delete the file
|
||||
else:
|
||||
os.remove(filepath)
|
||||
curType.append('Deleted {}: \'{}\''.format(getName(curType), filepath))
|
||||
else:
|
||||
if print_ignores:
|
||||
curType.append('Ignored {}: \'{}\''.format(getName(curType), filepath))
|
||||
|
||||
# Clean up
|
||||
ending = '\n' if (_logFiles or _logFolders) else ''
|
||||
print('\n'.join(_logFiles), end=ending)
|
||||
print('\n'.join(_logFolders), end=ending)
|
||||
print(f'Finished deleting {len(_logFiles)} files and {len(_logFolders)} folders.')
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
35
package/utils/process.py
Normal file
35
package/utils/process.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import os, sys, argparse, subprocess
|
||||
|
||||
# Simple tester for testing whether a file exists.
|
||||
# StackOverflow https://stackoverflow.com/a/51212150/6912830
|
||||
def file_path(string):
|
||||
if os.path.isfile(string):
|
||||
return string
|
||||
else:
|
||||
raise NotADirectoryError(string)
|
||||
|
||||
# Argparser
|
||||
# parser = argparse.ArgumentParser()
|
||||
# parser.add_argument('path', metavar='PATH', type=file_path, help='the full path to the file in question')
|
||||
# args = parser.parse_args()
|
||||
|
||||
# print(args.path)
|
||||
|
||||
# Image Processing
|
||||
command_args = "5x0+90+450"
|
||||
|
||||
base_path = sys.path[0]
|
||||
blur_map = os.path.join(base_path, 'blur_map_polar.jpg')
|
||||
input_path = os.path.join(base_path, 'blur_radial.jpg')
|
||||
output_path = os.path.join(base_path, 'output.jpg')
|
||||
|
||||
for path in [base_path, blur_map, input_path, output_path]:
|
||||
if not os.path.exists(path):
|
||||
raise Exception('Invalid File Name')
|
||||
|
||||
|
||||
# command = ['magick convert', input_path, blur_map, '-compose blur', '-define', 'compose:args=' + command_args, '-composite ', output_path]
|
||||
command = 'magick convert {} {} -compose blur -define compose:args={} -composite {}'.format(input_path, blur_map, command_args, output_path)
|
||||
print(command)
|
||||
breakpoint
|
||||
subprocess.run(command.split(' '))
|
||||
Reference in New Issue
Block a user