Skip to content

Commit

Permalink
remove config and format
Browse files Browse the repository at this point in the history
  • Loading branch information
tahsinature committed Jun 22, 2024
1 parent 0c146c8 commit 00b19f9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 74 deletions.
27 changes: 12 additions & 15 deletions hardbrake
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
#!/usr/bin/env python

import click
from src import app, VERSION, config
from src import app, VERSION


@click.command()
@click.option('--test', is_flag=True, help='Run testing function', default=False, )
@click.option('--version', '-v', is_flag=True, help='Check version', default=False, )
@click.option('--update', is_flag=True, help='Check for update', default=False, )
@click.option('--show-command', is_flag=True, help='Show Command', default=False, )
@click.argument('input', type=click.File('r'), default=None, required=False)
def exec(test: str, version: str, update: str, show_command: bool, input: click.File):
config.app["show-command"] = show_command

if test:
app.test()
elif version:
print(f'v: {VERSION}')
elif update:
app.update()
else:
name = input.name if input else None
files = [name] if name else []
app.main(files)
def exec(test: str, version: str, update: str, input: click.File):
if test:
app.test()
elif version:
print(f'v: {VERSION}')
elif update:
app.update()
else:
name = input.name if input else None
files = [name] if name else []
app.main(files)


exec()
3 changes: 0 additions & 3 deletions src/config.py

This file was deleted.

75 changes: 43 additions & 32 deletions src/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,63 @@
import os
import tempfile
import src.prompts as prompts
import src.loader as loader
import time

output_path = os.path.join(tempfile.gettempdir(), "OUTFILE")
cmd = f"ranger --choosefiles={output_path}"


def select_files() -> list[str]:
completed_process = subprocess.run(cmd, shell=True)
if completed_process.returncode != 0:
raise Exception("Something went wrong while selecting files")
completed_process = subprocess.run(cmd, shell=True)
if completed_process.returncode != 0:
raise Exception("Something went wrong while selecting files")

allowed_extensions = ["mp4", "mkv", "avi", "mov", "m4v", "flv", "wmv"]
allowed_extensions = ["mp4", "mkv", "avi", "mov", "m4v", "flv", "wmv"]

if not os.path.exists(output_path):
return []
if not os.path.exists(output_path):
return []

with open(output_path, "r") as f:
data = f.read()
filtered_data = map(lambda x: x.strip(), data.splitlines())
filtered_data = list(filter(lambda x: len(x) > 0, filtered_data))
filtered_data = list(filter(lambda x: x.split(
".")[-1].lower() in allowed_extensions, filtered_data))
with open(output_path, "r") as f:
data = f.read()
filtered_data = map(lambda x: x.strip(), data.splitlines())
filtered_data = list(filter(lambda x: len(x) > 0, filtered_data))
filtered_data = list(filter(lambda x: x.split(
".")[-1].lower() in allowed_extensions, filtered_data))

os.remove(output_path)
os.remove(output_path)

return filtered_data
return filtered_data


class _Manager:
files: list[str] = []
original_files: list[str] = []

def add_file(self, file_path: str) -> None:
"""Add a file to the list that has been interacted with"""
self.files.append(file_path)

def add_original_file(self, file_path: str) -> None:
"""Add original files to the list that has been interacted with"""
self.original_files.append(file_path)

def delete_file(self):
# """Delete files from the list that has been interacted with"""
delete_original_files = prompts.ask_boolean("Do you want to delete the original files?")
if delete_original_files:
for file_to_delete in self.original_files:
os.remove(file_to_delete)
print(f"Deleted {file_to_delete}")
files: list[str] = []
original_files: list[str] = []

def add_file(self, file_path: str) -> None:
"""Add a file to the list that has been interacted with"""
self.files.append(file_path)

def add_original_file(self, file_path: str) -> None:
"""Add original files to the list that has been interacted with"""
self.original_files.append(file_path)

def delete_file(self):
# """Delete files from the list that has been interacted with"""
delete_original_files = prompts.ask_boolean("Do you want to delete the original files?")
if delete_original_files:
loader.loader.start()
loader.loader.add_task("del_files", len(self.original_files))

for i, j in enumerate(self.original_files):
file_path = j
number = i + 1

os.remove(file_path)
loader.loader.update("del_files", number)
time.sleep(0.01)

loader.loader.stop()


manager = _Manager()
44 changes: 20 additions & 24 deletions src/manager.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
import src.event as event
import src.loader as loader
import src.utils as utils
import src.config as config
from rich import print
from rich.panel import Panel
from rich.syntax import Syntax
import time


def manage(cmds: list[str]):
loader.loader.start()
loader.loader.start()

def handle_progress(cmd: str, percent: int):
loader.loader.update(utils.hash(cmd), percent)
all_task_name = f"all ({len(cmds)})"

def get_process(cmd: str):
return event.ProcessWithEvent(cmd, progress_cb=handle_progress)
loader.loader.add_task(all_task_name, len(cmds))
loader.loader.add_task("current", 100)

pwe_list = list(map(get_process, cmds))
def handle_progress(cmd: str, percent: int):
loader.loader.update("current", percent)

for pwe in pwe_list:
loader.loader.add_task(utils.hash(pwe.cmd), 100)
for i in range(len(cmds)):
loader.loader.update("current", 0)
cmd = cmds[i]
time.sleep(0.01)
p = event.ProcessWithEvent(cmd, progress_cb=handle_progress)
p.start()

for pwe in pwe_list:
if config.app['show-command']:
syntax = Syntax(pwe.cmd, "bash", theme="monokai", word_wrap=True)
panel = Panel(syntax, title="Command", )
print(panel)
loader.loader.update(all_task_name, i + 1)

pwe.start()

loader.loader.stop()
loader.loader.stop()


def main():

cmd1 = "source /Users/tahsin/.commonrc && hb_test 10"
cmd2 = "source /Users/tahsin/.commonrc && hb_test 12"
cmd3 = "source /Users/tahsin/.commonrc && hb_test 5"
cmd4 = "ls"
cmds = []

cmds = [cmd1, cmd2, cmd3, cmd4]
for i in range(1000):
cmds.append("ls")

manage(cmds)
manage(cmds)


if __name__ == "__main__":
main()
main()

0 comments on commit 00b19f9

Please sign in to comment.