forked from SemperPeritus/httrack-deamon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
httrack.py
39 lines (35 loc) · 1.36 KB
/
httrack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
# !/usr/bin/env python3
from subprocess import call
from os import makedirs
from shutil import rmtree
import config
def download(url, remove, archive_format):
if url.find("//"):
url = url[url.find("//")+2:]
if url[-1:] == '/':
url = url[:-1]
site = config.sites_directory + '/' + url
print("Downloading ", url, " started.")
makedirs(config.sites_directory, mode=0o755, exist_ok=True)
call(["httrack", url], cwd=config.sites_directory)
print("Downloading is complete")
if archive_format:
if archive_format == "gz":
call(["tar", "-czf", config.sites_directory + '/' + url + ".tar.gz",
"-C", config.sites_directory, url], cwd=config.sites_directory)
elif archive_format == "bz2":
call(["tar", "-cjf", config.sites_directory + '/' + url + ".tar.bz2",
"-C", config.sites_directory, url], cwd=config.sites_directory)
elif archive_format == "tar":
call(["tar", "-cf", config.sites_directory + '/' + url + ".tar",
"-C", config.sites_directory, url], cwd=config.sites_directory)
else:
print("Archive format is wrong")
else:
print("The site is not packed")
if remove:
rmtree(site)
print("Removing is complete")
else:
print("Removing is canceled")