1
0
Fork 0
mirror of https://github.com/snovvcrash/usbrip.git synced 2024-06-08 06:56:02 +02:00

Minor edits

This commit is contained in:
Sam Free5ide 2019-09-04 00:21:03 +03:00
parent eebd358b8a
commit acde18dd7b
2 changed files with 26 additions and 18 deletions

View File

@ -23,7 +23,6 @@ Table of Contents:
* [**Git Clone**](#git-clone)
* [**Dependencies**](#dependencies)
- [System Log Structure](#system-log-structure)
* [`journalctl`](#journalctl)
- [DEB Packages](#deb-packages)
- [PIP Packages](#pip-packages)
- [Portable](#portable)
@ -88,7 +87,7 @@ usbrip supports two types of format:
1. **Non-modified** — standard `syslog` structure for GNU/Linux ([`"%b %d %H:%M:%S"`](http://strftime.org/), ex. "Mar 18 13:56:07"). This type of timestamp does not provide the information about years.
2. **Modified** (recommended) — upgraded structure of system log files which provides high precision timestamps ([`"%Y-%m-%dT%H:%M:%S.%f%z"`](http://strftime.org/), ex. `"2019-08-09T06:15:49.655261-04:00"`).
The modified structure could be configured via `RSYSLOG_FileFormat` format if you are using rsyslog, for example.
If you use `journalctl` to manage your logs, then there's nothing to worry about (as it can convert timestamps on the fly). Otherwise, the modified structure could be configured via `RSYSLOG_FileFormat` format if you are using rsyslog, for example.
1. Comment out the following line in `/etc/rsyslog.conf`:
@ -114,10 +113,6 @@ $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
~$ sudo systemctl restart rsyslog
```
### `journalctl`
So far, I have provided slight compatibility with the `journald` demon out-of-the-box. You may want to take a look at this [blogpost](https://hackware.ru/?p=9703) (in Russian) where the author suggests some cool hints for converting various timestamps in order not to break usbrip when working on different distros.
## DEB Packages
* python3.6 (or newer) interpreter

View File

@ -81,21 +81,31 @@ class USBEvents:
@time_it_if_debug(cfg.DEBUG, time_it)
def __new__(cls, files=None):
try:
# child_env = os.environ.copy()
# child_env['LANG'] = 'en_US.utf-8'
# journalctl_out = check_output(['journalctl'], env=child_env).decode('utf-8')
journalctl_out = check_output(['journalctl', '-o', 'short-iso-precise']).decode('utf-8')
if '-- Logs begin at' in journalctl_out:
filtered_history = _read_log_file(None, log=StringIO(journalctl_out))
elif files:
if files:
filtered_history = []
for file in files:
filtered_history.extend(_read_log_file(file))
else:
filtered_history = _get_filtered_history()
# child_env = os.environ.copy()
# child_env['LANG'] = 'en_US.utf-8'
# journalctl_out = check_output(['journalctl'], env=child_env).decode('utf-8')
journalctl_out = check_output([
'journalctl',
'-o',
'short-iso-precise'
]).decode('utf-8')
if '-- Logs begin at' in journalctl_out:
filtered_history = _read_log_file(
None,
log=StringIO(journalctl_out),
total=journalctl_out.count('\n')+1
)
else:
filtered_history = _get_filtered_history()
except USBRipError as e:
print_critical(str(e), initial_error=e.errors['initial_error'])
@ -308,7 +318,7 @@ def _get_filtered_history():
return filtered_history
def _read_log_file(filename, log=None):
def _read_log_file(filename, log=None, total=None):
filtered = []
if log is None:
@ -333,6 +343,9 @@ def _read_log_file(filename, log=None):
log = codecs.open(abs_filename, 'r', encoding='utf-8', errors='ignore')
end_of_file = ''
total = sum(1 for line in log)
log.seek(0)
print_info(f'Reading "{abs_filename}"')
else:
@ -341,7 +354,7 @@ def _read_log_file(filename, log=None):
print_info(f'Reading journalctl output')
regex = re.compile(r'(?:]|:) usb (.*?): ')
for line in tqdm(iter(log.readline, end_of_file), unit='line'):
for line in tqdm(iter(log.readline, end_of_file), ncols=80, unit='line', total=total):
if isinstance(line, bytes):
line = line.decode('utf-8', errors='ignore')