Skip to content

Commit

Permalink
No table view run is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
jasursadikov committed Sep 10, 2024
1 parent 024ffd8 commit 5ecd2ca
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ All entries are stored in `.mudconfig` in TSV format. After making your first en

### Arguments
- `-l=<label>` or `--label=<label>` - filters out repositories with provided label.
- `-nl=<label>` or `--not-label=<label>` - filters out repositories excluding provided label.
- `-nl=<label>` or `--not-label=<label>` - filters out repositories excluding provided label. You should include some repos with `--label` first.
- `-b=<branch>` or `--branch=<branch>` - filters out repositories by current branch name.
- `-m` or `--modified` - filters out modified repositories.
- `-d` or `--diverged` - filters repositories with diverged branches.
Expand Down
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _create_parser() -> ArgumentParser:

parser.add_argument(*TABLE_ATTR, metavar='TABLE', nargs='?', default='', type=str, help=f'Switches table view, runs in table view it is disabled in {BOLD}.mudsettings{RESET}.')
parser.add_argument(*LABEL_PREFIX, metavar='LABEL', nargs='?', default='', type=str, help='Selects repositories with provided label.')
parser.add_argument(*NOT_LABEL_PREFIX, metavar='NOT_LABEL', nargs='?', default='', type=str, help='Selects repositories without provided label.')
parser.add_argument(*NOT_LABEL_PREFIX, metavar='NOT_LABEL', nargs='?', default='', type=str, help=f'Selects repositories without provided label from filtered with {LABEL_PREFIX}.')
parser.add_argument(*BRANCH_PREFIX, metavar='BRANCH', nargs='?', default='', type=str, help='Filter repositories by provided branch.')
parser.add_argument(*MODIFIED_ATTR, action='store_true', help='Filters modified repositories.')
parser.add_argument(*DIVERGED_ATTR, action='store_true', help='Filters repositories with diverged branches.')
Expand Down
51 changes: 29 additions & 22 deletions runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ def tags(self, repos: Dict[str, List[str]]):
def run_ordered(self, repos: List[str], command: [str]) -> None:
command_str = ' '.join(command)
for path in repos:
result = subprocess.run(command_str, shell=True, cwd=path, capture_output=True, text=True)
print(f'{self._get_formatted_path(path)}{RESET} {utils.GLYPHS["terminal"]} {BOLD}{command_str}{RESET} {RED + utils.GLYPHS["failed"] if result.stderr else GREEN + utils.GLYPHS["finished"]} {f"{RESET}|{RED} Code: {BOLD}{result.returncode}{RESET}" if result.stderr else ""} {RESET}')
if result.stdout and not result.stdout.strip().isspace():
print(result.stdout.strip())
if result.stderr and not result.stderr.strip().isspace():
print(f'{RED}{result.stderr.strip()}{RESET}')
process = subprocess.run(command_str, shell=True, cwd=path, capture_output=True, text=True)
self._print_process_header(path, ' '.join(command), process.returncode != 0, process.returncode)
if process.stdout and not process.stdout.isspace():
print(process.stdout)
if process.stderr and not process.stderr.isspace():
print(process.stderr)

# `mud <COMMAND>` when run_async = 1 and run_table = 0
async def run_async(self, repos: List[str], command: List[str]) -> None:
Expand All @@ -178,7 +178,7 @@ async def run_process(path: str) -> None:
async with sem:
process = await asyncio.create_subprocess_exec(*command, cwd=path, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = await process.communicate()
print(f'{self._get_formatted_path(path)}{GRAY}>{RESET} {YELLOW}{" ".join(command)}{RESET}')
self._print_process_header(path, ' '.join(command), process.returncode != 0, process.returncode)
if stderr:
print(stderr.decode())
if stdout and not stdout.isspace():
Expand Down Expand Up @@ -289,21 +289,6 @@ def _table_to_str(table: PrettyTable) -> str:
def _get_table() -> PrettyTable:
return PrettyTable(border=False, header=False, style=PLAIN_COLUMNS, align='l')

@staticmethod
def _get_formatted_path(path: str) -> str:
simplify_branches = utils.settings.config['mud'].getboolean('simplify_branches')
if os.path.isabs(path):
home = os.path.expanduser('~')
if path.startswith(home):
path = path.replace(home, '~', 1)
if path.startswith('/'):
path = path[1:]
parts = path.split('/')
return DIM + WHITE + ('/'.join([p[0] for p in parts[:-1]] + [RESET + DIM + parts[-1]]) if simplify_branches else '/'.join(
[p for p in parts[:-1]] + [(parts[-1][:10] + '..' if len(parts[-1]) > 10 else parts[-1])])) + RESET

return f'{DIM}{path}{RESET}'

@staticmethod
def _get_branch_status(path: str) -> str:
branch_cmd = subprocess.run('git rev-parse --abbrev-ref HEAD', shell=True, text=True, cwd=path, capture_output=True)
Expand Down Expand Up @@ -334,6 +319,28 @@ def _get_branch_status(path: str) -> str:
else:
return f'{CYAN}{utils.GLYPHS["branch"]}{RESET}{utils.GLYPHS["space"]}{branch_stdout}'

@staticmethod
def _print_process_header(path: str, command: str, failed: bool, code: int):
path = f'{Runner._get_formatted_path(path)}{RESET}'
command = f'{BKG_WHITE}{BLACK} {utils.GLYPHS["terminal"]} {BOLD}{command} {RESET}{WHITE}{utils.GLYPHS[")"]}{RESET}'
code = f'{RED + utils.GLYPHS["failed"] if failed else GREEN + utils.GLYPHS["finished"]}{RESET} {f"{RESET}{RED}Code: {BOLD}{code}{RESET}" if failed else ""} {RESET}'
print(f'{path} {command} {code}')

@staticmethod
def _get_formatted_path(path: str) -> str:
simplify_branches = utils.settings.config['mud'].getboolean('simplify_branches')
if os.path.isabs(path):
home = os.path.expanduser('~')
if path.startswith(home):
path = path.replace(home, '~', 1)
if path.startswith('/'):
path = path[1:]
parts = path.split('/')
return DIM + WHITE + ('/'.join([p[0] for p in parts[:-1]] + [RESET + DIM + parts[-1]]) if simplify_branches else '/'.join(
[p for p in parts[:-1]] + [(parts[-1][:10] + '..' if len(parts[-1]) > 10 else parts[-1])])) + RESET

return f'{DIM}{path}{RESET}'

@staticmethod
def _get_authors_name(path: str) -> str:
cmd = subprocess.run('git log -1 --pretty=format:%an', shell=True, text=True, cwd=path, capture_output=True)
Expand Down
4 changes: 2 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
'label': '\uf435',
'tag': '\uf02b',
'terminal': '\ue795',
'(': '\ue0b6',
')': '\ue0b4',
'(': '\uE0B2',
')': '\uE0B0',
'space': ' ',
}
TEXT_GLYPHS = {
Expand Down

0 comments on commit 5ecd2ca

Please sign in to comment.