-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John Pfuntner
committed
Jan 10, 2025
1 parent
70cf266
commit c9dc063
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import sys | ||
import signal | ||
import logging | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description='Rotate a file - lines become columns and viceversa') | ||
parser.add_argument('-v', '--verbose', action='count', help='Enable debugging') | ||
args = parser.parse_args() | ||
|
||
logging.basicConfig(format='%(asctime)s %(levelname)s %(pathname)s:%(lineno)d %(msg)s') | ||
log = logging.getLogger(sys.argv[0]) | ||
log.setLevel(logging.WARNING - (args.verbose or 0)*10) | ||
|
||
signal.signal(signal.SIGPIPE, lambda signum, stack_frame: exit(0)) | ||
|
||
if sys.stdin.isatty(): | ||
parser.error('stdin must be directed') | ||
|
||
lines = sys.stdin.read().splitlines() | ||
if lines: | ||
for col in range(max([len(line) for line in lines])): | ||
line = '' | ||
log.info(f'{col=}') | ||
for row in range(len(lines)): | ||
log.info(f'{row=} {col=}') | ||
if col < len(lines[row]): | ||
line += lines[row][col] | ||
else: | ||
line += ' ' | ||
log.info(f'{line=}') | ||
print(line.rstrip()) |