-
Notifications
You must be signed in to change notification settings - Fork 188
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
Showing
8 changed files
with
98 additions
and
165 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 |
---|---|---|
@@ -1,15 +1,22 @@ | ||
import os | ||
import sys | ||
import subprocess | ||
from logfetch_base import log | ||
from termcolor import colored | ||
|
||
def cat_files(args, all_logs): | ||
if all_logs: | ||
all_logs.sort() | ||
for log in all_logs: | ||
if not args.silent: | ||
sys.stderr.write(colored(log, 'cyan') + '\n') | ||
command = 'cat {0}'.format(log) | ||
sys.stdout.write(os.popen(command).read() + '\n') | ||
else: | ||
if not args.silent: | ||
sys.stderr.write(colored('No log files found\n', 'magenta')) | ||
log('\n', args, False) | ||
if all_logs: | ||
all_logs.sort() | ||
for filename in all_logs: | ||
log('=> ' + colored(filename, 'cyan') + '\n', args, False) | ||
if filename.endswith('.gz'): | ||
cat = subprocess.Popen(['cat', filename], stdout=subprocess.PIPE) | ||
content = subprocess.Popen(['zcat'], stdin=cat.stdout) | ||
content.communicate() | ||
else: | ||
cat = subprocess.Popen(['cat', filename]) | ||
cat.communicate() | ||
sys.stdout.write('\n') | ||
else: | ||
log(colored('No log files found\n', 'magenta'), args, False) |
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 |
---|---|---|
@@ -1,31 +1,38 @@ | ||
import os | ||
import sys | ||
import subprocess | ||
from logfetch_base import log | ||
from termcolor import colored | ||
|
||
GREP_COMMAND_FORMAT = '{0} {1}' | ||
DEFAULT_GREP_COMMAND = 'grep --color=always \'{0}\'' | ||
|
||
def grep_files(args, all_logs): | ||
if not args.silent: | ||
sys.stderr.write('\n') | ||
log('\n', args, False) | ||
if args.grep: | ||
if all_logs: | ||
all_logs.sort() | ||
for log in all_logs: | ||
command = grep_command(args, log) | ||
output = os.popen(command).read() | ||
if output is not None and output != '': | ||
if not args.silent: | ||
sys.stderr.write(colored(log, 'cyan') + '\n') | ||
sys.stdout.write(output) | ||
|
||
if not args.silent: | ||
sys.stderr.write(colored('Finished grep, exiting', 'green') + '\n') | ||
grep_cmd = grep_command(args) | ||
log(colored('\nRunning grep command ({0})\n'.format(grep_cmd), 'cyan'), args, False) | ||
for filename in all_logs: | ||
log('=> ' + colored(filename, 'cyan') + '\n', args, True) | ||
content = subprocess.Popen(['cat', filename], stdout=subprocess.PIPE) | ||
if filename.endswith('.gz'): | ||
zcat = subprocess.Popen('zcat', stdin=content.stdout, stdout=subprocess.PIPE) | ||
grep = subprocess.Popen(grep_cmd, stdin=zcat.stdout, shell=True) | ||
else: | ||
grep = subprocess.Popen(grep_cmd, stdin=content.stdout, shell=True) | ||
grep.communicate() | ||
log(colored('Finished grep, exiting', 'green') + '\n', args, False) | ||
else: | ||
sys.stderr.write(colored('No logs found\n', 'magenta')) | ||
|
||
def grep_command(args, filename): | ||
def grep_command(args): | ||
if 'grep' in args.grep: | ||
return GREP_COMMAND_FORMAT.format(args.grep, filename) | ||
return args.grep | ||
else: | ||
return DEFAULT_GREP_COMMAND.format(args.grep) | ||
|
||
def cat_command(filename): | ||
if filename.endswith('.gz'): | ||
return 'zcat {0}'.format(filename) | ||
else: | ||
return GREP_COMMAND_FORMAT.format(DEFAULT_GREP_COMMAND.format(args.grep), filename) | ||
return 'cat {0}'.format(filename) |
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
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
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
Oops, something went wrong.