зеркало из https://github.com/mozilla/ff-tool.git
fix: move configs dir to fftool module
This commit is contained in:
Родитель
1d915bcb89
Коммит
15c5a4fa41
18
README.rst
18
README.rst
|
@ -70,7 +70,7 @@ Installation
|
|||
**Windows: Installing Cygwin**
|
||||
|
||||
- Download and install: `Cygwin <https://cygwin.com/>`_
|
||||
- Right click on: c:\\cygwin64\\cygwin.bat
|
||||
- Right click on: c:\\\\cygwin64\\cygwin.bat
|
||||
- Run as administrator or you will suffer.
|
||||
- A number of dependencies must also be installed including: gcc, make,
|
||||
curl, pycrypto, python2, python-dev, etc.
|
||||
|
@ -186,19 +186,3 @@ new one with that name.
|
|||
|
||||
$ ff -c beta -p my_cool_profile1 -a loop-server -e stage -t e2e-test
|
||||
|
||||
Download all browsers, but don't create a profile or launch any browsers...
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
**NOTE:** This is useful for our daily refresh task where we make sure
|
||||
we have the latest browsers installed.
|
||||
|
||||
- version: all
|
||||
- profile\_name: none
|
||||
|
||||
::
|
||||
|
||||
$ ff -c ALL --install-only
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -10,15 +10,15 @@ __version__ = '0.0.1'
|
|||
CHANNELS = ['release',
|
||||
'beta',
|
||||
'aurora',
|
||||
'nightly',
|
||||
'ALL']
|
||||
'nightly']
|
||||
|
||||
DEFAULT_CHANNEL = 'nightly'
|
||||
|
||||
DIR_TEMP = '_temp'
|
||||
DIR_TEMP_BROWSERS = os.path.join(DIR_TEMP, 'browsers')
|
||||
DIR_CONFIGS = 'fftool/configs'
|
||||
OS_CONFIG = IniHandler()
|
||||
OS_CONFIG.load_os_config('configs')
|
||||
OS_CONFIG.load_os_config(DIR_CONFIGS)
|
||||
DIR_TEMP_PROFILES = os.path.join(DIR_TEMP, 'profiles')
|
||||
PATH_PREFS_ROOT = os.environ.get('PATH_PREFS_ROOT')
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from argparse import ArgumentParser
|
|||
from fftool import CHANNELS, DEFAULT_CHANNEL
|
||||
|
||||
|
||||
def ff_cli():
|
||||
def arg_parser():
|
||||
parser = ArgumentParser(prog='ff')
|
||||
|
||||
parser.add_argument(
|
|
@ -1,20 +1,24 @@
|
|||
"""
|
||||
Module to download OS-specific versions of Firefox:
|
||||
1. General Release (gr)
|
||||
2. Beta (beta)
|
||||
3. Developer Edition (aurora)
|
||||
4. Nightly (nightly)
|
||||
"""Module to download OS-specific versions of Firefox:
|
||||
1. Nightly (nightly)
|
||||
2. Developer Edition (aurora)
|
||||
3. Beta (beta)
|
||||
4. General Release (release)
|
||||
"""
|
||||
|
||||
import os
|
||||
import time
|
||||
import ConfigParser as configparser # Python 2 only!
|
||||
|
||||
from fftool import DIR_TEMP_BROWSERS as BASE_DIR, OS_CONFIG as env, Log
|
||||
from fftool import (
|
||||
DIR_TEMP_BROWSERS as BASE_DIR,
|
||||
OS_CONFIG as env,
|
||||
DIR_CONFIGS,
|
||||
Log
|
||||
)
|
||||
from firefox_install import install, get_firefox_version
|
||||
from mozdownload import FactoryScraper
|
||||
|
||||
CONFIG_CHANNELS = os.path.join('configs', 'channels.ini')
|
||||
CONFIG_CHANNELS = os.path.join(DIR_CONFIGS, 'channels.ini')
|
||||
SCRIPT_START_TIME = time.time()
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
|
@ -26,9 +30,8 @@ def modification_date(filename):
|
|||
|
||||
|
||||
def download(channel):
|
||||
if channel == 'ALL':
|
||||
download_all()
|
||||
return
|
||||
|
||||
Log.header('DOWNLOAD FIREFOX')
|
||||
|
||||
ch_type = config.get(channel, 'type')
|
||||
ch_version = config.get(channel, 'version')
|
||||
|
@ -65,7 +68,8 @@ def download(channel):
|
|||
firefox_version = get_firefox_version(channel)
|
||||
args = {"channel": channel, "version": firefox_version}
|
||||
msg = "You have the latest version of {channel} installed ({version})."
|
||||
Log.header(msg.format(**args))
|
||||
Log.header('BROWSER VERSION')
|
||||
print(msg.format(**args))
|
||||
|
||||
|
||||
def download_all():
|
||||
|
|
|
@ -4,7 +4,7 @@ import os
|
|||
import platform
|
||||
import re
|
||||
import sys
|
||||
import ConfigParser as configparser # Python 2
|
||||
import ConfigParser as configparser
|
||||
from outlawg import Outlawg
|
||||
|
||||
Log = Outlawg()
|
||||
|
@ -16,9 +16,7 @@ class FirefoxEnvHandler():
|
|||
|
||||
@staticmethod
|
||||
def get_os():
|
||||
"""
|
||||
Do our best to determine the user's current operating system.
|
||||
"""
|
||||
"""Determine OS"""
|
||||
system = platform.system().lower()
|
||||
system = re.split('[-_]', system, maxsplit=1).pop(0)
|
||||
|
||||
|
@ -29,38 +27,26 @@ class FirefoxEnvHandler():
|
|||
|
||||
@classmethod
|
||||
def is_linux(cls):
|
||||
"""
|
||||
Am I running on Linux?
|
||||
"""
|
||||
return cls.get_os() == "linux"
|
||||
|
||||
@classmethod
|
||||
def is_mac(cls):
|
||||
"""
|
||||
Am I running on Mac/Darwin?
|
||||
"""
|
||||
return cls.get_os() == "darwin"
|
||||
|
||||
@classmethod
|
||||
def is_other(cls):
|
||||
"""
|
||||
I 'literally' have no idea who you are.
|
||||
"""
|
||||
"""Unrecognized OS"""
|
||||
return not (cls.is_linux() or cls.is_mac() or cls.is_windows())
|
||||
|
||||
@classmethod
|
||||
def is_windows(cls):
|
||||
"""
|
||||
Am I running on Windows/Cygwin?
|
||||
"""
|
||||
return cls.get_os() == "windows"
|
||||
|
||||
|
||||
class IniHandler(FirefoxEnvHandler):
|
||||
def __init__(self, ini_path=None):
|
||||
"""
|
||||
Creates a new config parser object, and optionally loads a config file
|
||||
if `ini_path` was specified.
|
||||
"""Creates a new config parser object,
|
||||
also loads config file if `ini_path` specified.
|
||||
"""
|
||||
self.config = configparser.SafeConfigParser(os.environ)
|
||||
|
||||
|
@ -68,30 +54,24 @@ class IniHandler(FirefoxEnvHandler):
|
|||
self.load_config(ini_path)
|
||||
|
||||
def load_config(self, ini_path):
|
||||
"""Load an INI config based on the specified `ini_path`.
|
||||
"""
|
||||
Load an INI config based on the specified `ini_path`.
|
||||
"""
|
||||
Log.header('LOADING {0}'.format(ini_path))
|
||||
|
||||
# Make sure the specified config file exists, fail hard if missing.
|
||||
if not os.path.isfile(ini_path):
|
||||
sys.exit('Config file not found: {0}'.format(ini_path))
|
||||
|
||||
self.config.read(ini_path)
|
||||
|
||||
def load_os_config(self, config_path):
|
||||
"""
|
||||
Load an INI file based on the current operating system. This method
|
||||
will attempt to load a "darwin.ini", "cygwin.ini", or "linux-gnu.ini"
|
||||
file from the specified `config_path` based on the current OS.
|
||||
"""Loads INI file based on current OS:
|
||||
"darwin.ini", "cygwin.ini", "linux-gnu.ini", etc.
|
||||
"""
|
||||
os_config = os.path.join(config_path, IniHandler.get_os() + '.ini')
|
||||
self.load_config(os_config)
|
||||
|
||||
def create_env_file(self, out_file='.env'):
|
||||
"""
|
||||
Generate and save the output environment file so we can source it from
|
||||
something like .bashrc or .bashprofile.
|
||||
"""Generate and save an '.env' file so we can source it from
|
||||
in .bashrc or .profile.
|
||||
"""
|
||||
Log.header('CREATING ENV FILE ({0})'.format(out_file))
|
||||
|
||||
|
@ -117,36 +97,28 @@ class IniHandler(FirefoxEnvHandler):
|
|||
env_file.close()
|
||||
|
||||
def sections(self):
|
||||
"""
|
||||
Shortcut for getting a config's `sections()` array without needing to
|
||||
do the visually horrifying `self.config.config.sections()`.
|
||||
"""Shortcut for config's `sections()` array.
|
||||
"""
|
||||
return self.config.sections()
|
||||
|
||||
def get(self, section, option):
|
||||
"""
|
||||
Shortcut for calling a config's `get()` method without needing to
|
||||
do the visually horrifying `self.config.config.get()`.
|
||||
"""Shortcut for config's `get()` method.
|
||||
"""
|
||||
return self.config.get(section, option)
|
||||
|
||||
def set(self, section, option, value):
|
||||
"""
|
||||
Shortcut for calling a config's `set()` method without needing to
|
||||
do the visually horrifying `self.config.config.set()`.
|
||||
"""Shortcut for calling a config's `set()` method.
|
||||
"""
|
||||
return self.config.set(section, option, str(value))
|
||||
|
||||
def get_default(self, option):
|
||||
"""
|
||||
Shortcut to get a value from the "DEFAULTS" section of a ConfigParser
|
||||
INI file. Doesn't save much time, but reads a bit easier.
|
||||
"""Shortcut to get a value from the "DEFAULTS" section.
|
||||
"""
|
||||
return self.get('DEFAULT', option)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
i = IniHandler()
|
||||
i.load_os_config('configs')
|
||||
i.create_env_file()
|
||||
ini = IniHandler()
|
||||
ini.load_os_config('fftool/configs')
|
||||
ini.create_env_file()
|
||||
|
|
|
@ -4,7 +4,11 @@ import os
|
|||
import stat
|
||||
from fftool import local, Log
|
||||
from firefox_env_handler import IniHandler
|
||||
from fftool import DIR_TEMP_BROWSERS as BASE_DIR, OS_CONFIG as env
|
||||
from fftool import (
|
||||
DIR_TEMP_BROWSERS as BASE_DIR,
|
||||
OS_CONFIG as env,
|
||||
Log
|
||||
)
|
||||
|
||||
|
||||
def chmodx(path):
|
||||
|
@ -13,9 +17,8 @@ def chmodx(path):
|
|||
|
||||
|
||||
def install(channel):
|
||||
if channel == 'ALL':
|
||||
install_all()
|
||||
return
|
||||
|
||||
Log.header('INSTALL FIREFOX')
|
||||
|
||||
install_dir = env.get(channel, 'PATH_FIREFOX_APP')
|
||||
filename = env.get(channel, 'DOWNLOAD_FILENAME')
|
||||
|
@ -46,7 +49,7 @@ def install(channel):
|
|||
try:
|
||||
firefox_version = get_firefox_version(channel)
|
||||
except:
|
||||
print("YOU FAIL")
|
||||
print("ERROR: Install Failed - Aborting!")
|
||||
exit()
|
||||
|
||||
Log.header("FIREFOX VERSION")
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
"""
|
||||
This module uses Fabric API to generate a Firefox Profile by concatenating the
|
||||
"""This module creates a Firefox Profile by concatenating the
|
||||
following preferences files:
|
||||
- ./_utils/prefs.ini
|
||||
- ./<application>/prefs.ini
|
||||
- ./<application>/<test_type>/prefs.ini
|
||||
|
||||
The profile is then created using the specified name and saved to the ../_temp/
|
||||
directory.
|
||||
The profile is then created using the specified name and
|
||||
saved to the ../_temp/ directory.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
@ -14,7 +13,13 @@ import shutil
|
|||
from tempfile import mkdtemp
|
||||
from mozprofile import Profile, Preferences
|
||||
from firefox_env_handler import IniHandler
|
||||
from fftool import DIR_TEMP_PROFILES as BASE_PROFILE_DIR, PATH_PREFS_ROOT, Log
|
||||
from fftool import (
|
||||
DIR_TEMP_PROFILES as BASE_PROFILE_DIR,
|
||||
DIR_CONFIGS,
|
||||
PATH_PREFS_ROOT,
|
||||
Log
|
||||
)
|
||||
|
||||
import ConfigParser as configparser # Python 2
|
||||
|
||||
|
||||
|
@ -26,6 +31,7 @@ config = configparser.ConfigParser()
|
|||
|
||||
def prefs_paths(application, test_type, env='stage'):
|
||||
path_global = os.path.join(PATH_PREFS_GLOBAL, 'configs', FILE_PREFS)
|
||||
path_global = os.path.join(PATH_PREFS_GLOBAL, DIR_CONFIGS, FILE_PREFS)
|
||||
valid_paths = [path_global]
|
||||
|
||||
if application:
|
||||
|
@ -68,7 +74,8 @@ def clean_profiles():
|
|||
|
||||
|
||||
def create_mozprofile(profile_dir, application=None, test_type=None, env=None):
|
||||
# Ensure that the base `_temp/profiles/` directory exists before trying to
|
||||
|
||||
# Ensure base `_temp/profiles/` dir exists before trying to
|
||||
# create a nested directory.
|
||||
if not os.path.exists(BASE_PROFILE_DIR):
|
||||
os.mkdir(BASE_PROFILE_DIR)
|
||||
|
@ -92,15 +99,15 @@ def create_mozprofile(profile_dir, application=None, test_type=None, env=None):
|
|||
for path in prefs_paths(application, test_type, env):
|
||||
prefs.add_file(path)
|
||||
|
||||
# Add the `fftool.profile.name` pref so we can go to about:config and see
|
||||
# what our current profile is.
|
||||
# Add custom user pref: `fftool.profile.name`
|
||||
# so we can go to about:config and verify our current profile.
|
||||
prefs.add([("fftool.profile.name", full_profile_dir)])
|
||||
|
||||
profile = Profile(
|
||||
profile=full_profile_dir, restore=False, preferences=prefs())
|
||||
|
||||
Log.header("Launching browser with the following user configs:")
|
||||
Log.header("USER CONFIGS")
|
||||
print("Launching browser with the following user configs:")
|
||||
print(profile.summary())
|
||||
|
||||
# this is the path to the created profile
|
||||
return full_profile_dir
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
from fftool import (
|
||||
OS_CONFIG as env,
|
||||
Log,
|
||||
local
|
||||
)
|
||||
|
||||
|
||||
def launch_firefox(profile_path, channel):
|
||||
"""
|
||||
This function will rely on the other functions (download, install, profile)
|
||||
having successfully done their business.
|
||||
"""relies on the other functions (download, install, profile)
|
||||
having completed.
|
||||
"""
|
||||
|
||||
FIREFOX_APP_BIN = env.get(channel, 'PATH_FIREFOX_BIN_ENV')
|
||||
|
||||
Log.header('LAUNCH FIREFOX')
|
||||
print("Launching Firefox {0} with profile: {1}".format(
|
||||
channel,
|
||||
profile_path)
|
||||
|
|
|
@ -5,13 +5,12 @@ import shutil
|
|||
import sys
|
||||
|
||||
from firefox_env_handler import IniHandler
|
||||
from fftool import local
|
||||
from fftool import local, Log, DIR_CONFIGS
|
||||
|
||||
|
||||
def rimraf(path):
|
||||
"""
|
||||
Recursively delete the specified path.
|
||||
"""
|
||||
"""Recursively delete the specified path."""
|
||||
|
||||
if os.path.isdir(path):
|
||||
print(('Deleting {0}'.format(path)))
|
||||
shutil.rmtree(path)
|
||||
|
@ -22,12 +21,14 @@ def rimraf(path):
|
|||
|
||||
class FirefoxUninstall(object):
|
||||
def __init__(self, config, archive_dir="temp"):
|
||||
|
||||
Log.header('UNINSTALL FIREFOX')
|
||||
self.CACHE_FILE = "cache.ini"
|
||||
self.out_dir = archive_dir
|
||||
self.cache_path = os.path.join(self.out_dir, self.CACHE_FILE)
|
||||
self.cache = IniHandler(self.cache_path)
|
||||
|
||||
# Do some basic type checking on the `config` attribute.
|
||||
# Do some basic type checking on `config` attribute.
|
||||
if isinstance(config, IniHandler):
|
||||
self.config = config
|
||||
elif isinstance(config, str):
|
||||
|
@ -37,9 +38,10 @@ class FirefoxUninstall(object):
|
|||
sys.exit("FirefoxUninstall: Unexpected config data type")
|
||||
|
||||
def uninstall_all(self, force=False):
|
||||
"""
|
||||
Delete all the Firefox apps (nightly, aurora, beta, general release),
|
||||
and then delete the shared profiles directory.
|
||||
"""Cleanup function:
|
||||
|
||||
1. Delete all Firefox apps: nightly, aurora, beta, (general) release.
|
||||
2. delete the shared profiles directory.
|
||||
"""
|
||||
IniHandler.banner("UNINSTALLING FIREFOXES")
|
||||
|
||||
|
@ -69,9 +71,12 @@ class FirefoxUninstall(object):
|
|||
|
||||
|
||||
def main():
|
||||
config_path = "./configs/"
|
||||
|
||||
config_path = DIR_CONFIGS
|
||||
ff_uninstall = FirefoxUninstall(config_path)
|
||||
ff_uninstall.uninstall_all()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
main()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""
|
||||
NOTE: THIS IS AN OSX SPECIFIC FILE, SPECIFICALLY FOR MOUNTING DMG FILES.
|
||||
"""Module for OSX-specific utility.
|
||||
|
||||
Mounts DMG files.
|
||||
"""
|
||||
|
||||
|
||||
|
@ -39,8 +40,7 @@ def move_app(src, dest):
|
|||
|
||||
|
||||
def extract_dmg(dmg_path, app_src_filename, app_dest_filename, channel):
|
||||
"""
|
||||
Mount the *.dmg image, copy the *.app file, then unmount the *.dmg image.
|
||||
"""Mount *.dmg image, copy the *.app dir, then unmount *.dmg image.
|
||||
"""
|
||||
dmg_dirname = os.path.dirname(dmg_path)
|
||||
tmp_dirname = os.path.join(dmg_dirname, "_dmg_temp")
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from fftool import DEFAULT_CHANNEL, PATH_PREFS_ROOT, Log
|
||||
from ff_cli import ff_cli
|
||||
from fftool import PATH_PREFS_ROOT, Log
|
||||
from arg_parser import arg_parser
|
||||
from firefox_download import download
|
||||
from firefox_profile import create_mozprofile, clean_profiles
|
||||
from firefox_run import launch_firefox
|
||||
|
||||
|
||||
def main():
|
||||
options = ff_cli()
|
||||
Log.header('FF-TOOL: download, install & launch Firefox!', 'XL', '=')
|
||||
options = arg_parser()
|
||||
|
||||
# If the user is trying to create application specific configs but didn't
|
||||
# specify their `$PATH_PREFS_ROOT` environment variable, exit early.
|
||||
if options.app and not PATH_PREFS_ROOT:
|
||||
Log.header("ERROR")
|
||||
print("Missing path to $PATH_PREFS_ROOT directory.")
|
||||
|
@ -26,8 +25,8 @@ def main():
|
|||
# DOWNLOAD/INSTALL
|
||||
download(options.channel)
|
||||
|
||||
# If user specified `--install-only`, then just download/install specified
|
||||
# channel(s) and exit early.
|
||||
# If user specified `--install-only`, then
|
||||
# download/install specified channel(s) and exit early.
|
||||
if (options.install_only):
|
||||
return
|
||||
|
||||
|
@ -41,11 +40,6 @@ def main():
|
|||
)
|
||||
|
||||
# LAUNCH
|
||||
# If we downloaded "ALL" browsers/channels, override the specified channel
|
||||
# with the default channel so we only launch one browser.
|
||||
if options.channel.upper() == 'ALL':
|
||||
options.channel = DEFAULT_CHANNEL
|
||||
|
||||
if not options.no_launch:
|
||||
launch_firefox(profile_path, channel=options.channel)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче