forked from mozilla/ff-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firefox_download.py
91 lines (71 loc) · 2.59 KB
/
firefox_download.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Module to download OS-specific versions of Firefox:
1. Nightly (nightly)
2. Beta (beta)
3. General Release (release)
"""
import os
import time
from requests.exceptions import ConnectionError
import ConfigParser as configparser # Python 2 only!
from outlawg import Outlawg
from fftool import (
DIR_TEMP_BROWSERS as BASE_DIR,
DIR_CONFIGS,
)
from firefox_install import install, get_firefox_version
from ini_handler import IniHandler
from mozdownload import FactoryScraper
env = IniHandler()
env.load_os_config(DIR_CONFIGS)
CONFIG_CHANNELS = os.path.join(DIR_CONFIGS, 'channels.ini')
SCRIPT_START_TIME = time.time()
config = configparser.ConfigParser()
config.read(CONFIG_CHANNELS)
Log = Outlawg()
def modification_date(filename):
try:
mtime = os.path.getmtime(filename)
except OSError as e:
Log.header('ERROR!')
print(e)
exit()
return mtime
def download(channel):
Log.header('DOWNLOAD FIREFOX')
ch_type = config.get(channel, 'type')
ch_version = config.get(channel, 'version')
ch_branch = config.get(channel, 'branch')
# PLATFORM is uppercased here since the platform comes from the OS-specific
# config files, whereas the other flags generically come from channels.ini.
ch_platform = env.get(channel, 'PLATFORM')
download_filename = env.get(channel, 'DOWNLOAD_FILENAME')
download_path = os.path.join(BASE_DIR, download_filename)
args = {"channel": channel, "download_path": download_path}
print("Downloading {channel} to {download_path}".format(**args))
try:
scraper = FactoryScraper(
ch_type,
version=ch_version,
branch=ch_branch,
destination=download_path,
platform=ch_platform
)
scraper.download()
except ConnectionError:
Log.header('WARNING!')
print('HTTPS connection unavailable.\nLooking for cached browser...')
is_recent_file = modification_date(download_path) > SCRIPT_START_TIME
firefox_bin = env.get(channel, 'PATH_FIREFOX_BIN_ENV')
# If the *.dmg file was downloaded recently, or we don't have the *.app
# file installed, install current Firefox channel.
if is_recent_file or not os.path.exists(firefox_bin):
install(channel)
else:
firefox_version = get_firefox_version(channel)
args = {"channel": channel, "version": firefox_version}
msg = "You have the latest version of {channel} installed ({version})."
Log.header('BROWSER VERSION')
print(msg.format(**args))
def download_all():
for channel in config.sections():
download(channel)