Skip to content

Commit f81afba

Browse files
committed
Merge branch 'r/1.3.0'
1 parent f0966d0 commit f81afba

11 files changed

+158
-68
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Internet-archive is a nice source for several OSINT-information. This tool is a
1111

1212
This tool allows you to download content from the Wayback Machine (archive.org). You can use it to download either the latest version or all versions of web page snapshots within a specified range.
1313

14+
## Info
15+
16+
Linux recommended: On windows machines, the path length is limited. It can only be overcome by editing the registry. Files which exceed the path length will not be downloaded.
17+
1418
## Installation
1519

1620
### Pip
@@ -82,6 +86,10 @@ Path defaults to output-dir. Saves the result of CDX query as a file. Useful for
8286
- **`--cdxinject`** `<filepath>`:<br>
8387
Injects a CDX query file to download snapshots. Ensure the query matches the previous `--url` for correct folder structure.
8488

89+
**Auto:**
90+
- **`--auto`**:<br>
91+
If set, csv, skip and cdxbackup/cdxinject are handled automatically. Keep the files and folders as they are. Otherwise they will not be recognized when restarting a download.
92+
8593
### Debug
8694

8795
- `--debug`: If set, full traceback will be printed in case of an error. The full exception will be written into `waybackup_error.log`.

dev/venv_create.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fi
1111

1212
# update pip
1313
"$TARGET_PATH/.venv/bin/python" -m pip install --upgrade pip
14-
"$TARGET_PATH/.venv/bin/python" -m pip install twine wheel
14+
"$TARGET_PATH/.venv/bin/python" -m pip install twine wheel setuptools
1515

1616
# install requirements
1717
"$TARGET_PATH/.venv/bin/python" -m pip install -r "$TARGET_PATH/requirements.txt"

pywaybackup/Exception.py

+45-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import linecache
66
import traceback
77

8+
import re
9+
10+
from pywaybackup.__version__ import __version__
11+
812
class Exception:
913

1014
new_debug = True
@@ -22,19 +26,20 @@ def init(cls, debug=False, output=None, command=None):
2226
@classmethod
2327
def exception(cls, message: str, e: Exception, tb=None):
2428
custom_tb = sys.exc_info()[-1] if tb is None else tb
25-
original_tb = "".join(traceback.format_exception(type(e), e, e.__traceback__))
29+
original_tb = cls.relativate_path("".join(traceback.format_exception(type(e), e, e.__traceback__)))
2630
exception_message = (
2731
"-------------------------\n"
2832
f"!-- Exception: {message}\n"
2933
)
3034
if custom_tb is not None:
31-
while custom_tb.tb_next: # loop to last traceback frame
32-
custom_tb = custom_tb.tb_next
35+
while custom_tb.tb_next: # loop to last traceback frame
36+
custom_tb = custom_tb.tb_next
3337
tb_frame = custom_tb.tb_frame
3438
tb_line = custom_tb.tb_lineno
3539
func_name = tb_frame.f_code.co_name
36-
filename = tb_frame.f_code.co_filename
40+
filename = cls.relativate_path(tb_frame.f_code.co_filename)
3741
codeline = linecache.getline(filename, tb_line).strip()
42+
local_vars = tb_frame.f_locals
3843
exception_message += (
3944
f"!-- File: {filename}\n"
4045
f"!-- Function: {func_name}\n"
@@ -45,24 +50,57 @@ def exception(cls, message: str, e: Exception, tb=None):
4550
exception_message += "!-- Traceback is None\n"
4651
exception_message += (
4752
f"!-- Description: {e}\n"
48-
"-------------------------")
53+
"-------------------------"
54+
)
4955
print(exception_message)
5056
if cls.debug:
5157
debug_file = os.path.join(cls.output, "waybackup_error.log")
5258
print(f"Exception log: {debug_file}")
5359
print("-------------------------")
5460
print(f"Full traceback:\n{original_tb}")
55-
if cls.new_debug: # new run, overwrite file
61+
if cls.new_debug: # new run, overwrite file
5662
cls.new_debug = False
5763
f = open(debug_file, "w")
5864
f.write("-------------------------\n")
65+
f.write(f"Version: {__version__}\n")
66+
f.write("-------------------------\n")
5967
f.write(f"Command: {cls.command}\n")
6068
f.write("-------------------------\n\n")
61-
else: # current run, append to file
69+
else: # current run, append to file
6270
f = open(debug_file, "a")
6371
f.write(datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n")
6472
f.write(exception_message + "\n")
73+
f.write("!-- Local Variables:\n")
74+
for var_name, value in local_vars.items():
75+
if var_name in ["status_message", "headers"]:
76+
continue
77+
value = cls.relativate_path(str(value))
78+
value = value[:666] + " ... " if len(value) > 666 else value
79+
f.write(f" -- {var_name} = {value}\n")
80+
f.write("-------------------------\n")
6581
f.write(original_tb + "\n")
82+
f.close()
83+
84+
@classmethod
85+
def relativate_path(cls, input: str) -> str:
86+
try:
87+
path_pattern = re.compile(r'File "([^"]+)"')
88+
if os.path.isfile(input): # case single path
89+
return os.path.relpath(input, os.getcwd())
90+
input_modified = ""
91+
input_lines = input.split('\n')
92+
if len(input_lines) == 1: # case single line
93+
return input
94+
for line in input.split('\n'): # case multiple lines
95+
match = path_pattern.search(line)
96+
if match:
97+
original_path = match.group(1)
98+
relative_path = os.path.relpath(original_path, os.getcwd())
99+
line = line.replace(original_path, relative_path)
100+
input_modified += line + "\n"
101+
return input_modified
102+
except ValueError:
103+
return input
66104

67105
@staticmethod
68106
def exception_handler(exception_type, exception, traceback):

pywaybackup/SnapshotCollection.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ def create_list(cls, cdxResult, mode):
3131

3232

3333
@classmethod
34-
def count_list(cls):
34+
def count(cls, collection=False, success=False, fail=False):
35+
if collection:
36+
return len(cls.SNAPSHOT_COLLECTION)
37+
if success:
38+
return len([entry for entry in cls.SNAPSHOT_COLLECTION if entry["file"]])
39+
if fail:
40+
return len([entry for entry in cls.SNAPSHOT_COLLECTION if not entry["file"]])
3541
return len(cls.SNAPSHOT_COLLECTION)
3642

3743

pywaybackup/Verbosity.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def fini(cls):
3838
def write(cls, message: str = None, progress: int = None):
3939
if cls.mode == "progress":
4040
if cls.pbar is None and progress == 0:
41-
maxval = sc.count_list()
41+
maxval = sc.count(collection=True)
4242
cls.pbar = tqdm.tqdm(total=maxval, desc="Downloading", unit=" snapshot", ascii="░▒█")
4343
if cls.pbar is not None and progress is not None and progress > 0 :
4444
cls.pbar.update(progress)

pywaybackup/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.2.0"
1+
__version__ = "1.3.0"

0 commit comments

Comments
 (0)