Skip to content

Commit

Permalink
6.18.13 - move
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridepad committed Nov 4, 2024
1 parent 94a96be commit 59540a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
13 changes: 13 additions & 0 deletions api_7z.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ def _to_parsed_lines(self):


class SevenZipArchive(SevenZipArchiveInfo):
_7z_pipe: subprocess.Popen = None

def extract(self, extract_to: Path=None, file_name_to_extract: str=None):
if extract_to is None:
extract_to = self.archive_path.parent
Expand All @@ -277,6 +279,17 @@ def create(self, file_path: Path, custom_mode: list[str]=None):
self.archive_path.unlink()
return self.append(file_path, custom_mode)

def read_file_into_stdout(self, file_line: SevenZipLine):
file_name = file_line.file_name
if "*" in file_name:
file_name = f'"{file_name}"'
cmd_list = [self.path, 'e', self.archive_path, "-so", "--", file_name]
self._7z_pipe = subprocess.Popen(cmd_list, stdout=subprocess.PIPE)
stdout = self._7z_pipe.stdout
line = stdout.readline(5000)
while line:
yield line
line = stdout.readline(5000)


def _test1():
Expand Down
20 changes: 3 additions & 17 deletions logs_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def __init__(
self.timestamp = get_now_timestamp()
self.directory = new_upload_folder(ip, self.timestamp)

class LogsArchiveStatus(api_7z.SevenZipArchiveInfo):
class LogsArchiveStatus(api_7z.SevenZipArchive):
def __init__(
self,
archive_path: PathExt,
Expand Down Expand Up @@ -589,21 +589,7 @@ def __init__(
self.has_error = False
self.finished = False
self.mod_time_delta = None

self._7z_pipe: subprocess.Popen = None

def pipe_gen(self, file_line: api_7z.SevenZipLine):
file_name = file_line.file_name
if "*" in file_name:
file_name = f'"{file_name}"'
cmd_list = [self.path, 'e', self.archive_path, "-so", "--", file_name]
self._7z_pipe = subprocess.Popen(cmd_list, stdout=subprocess.PIPE)
stdout = self._7z_pipe.stdout
line = stdout.readline(5000)
while line:
yield line
line = stdout.readline(5000)


def adjust_mod_time(self, file_line: api_7z.SevenZipLine, segment: LogsSlice):
_mod_time_delta = file_line.datetime - segment.get_last_line_dt()
if not self.mod_time_delta or self.mod_time_delta > _mod_time_delta:
Expand All @@ -619,7 +605,7 @@ def parse_txt_files(self):
self.current_segment_pc = perf_counter()
for file_line in all_text_files:
# print(file_line)
lines = self.pipe_gen(file_line)
lines = self.read_file_into_stdout(file_line)
separator = LogsSeparator(server=self.server, timestamp=file_line.timestamp)
for segment in separator.generate_segments(lines):
if not segment:
Expand Down

0 comments on commit 59540a2

Please sign in to comment.