Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
avoid redundancy between --profile and --no-new-profile, https://bugz…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Hammel committed Jul 19, 2010
1 parent 9ffd3ad commit 48e4dcb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 35 deletions.
2 changes: 1 addition & 1 deletion jsbridge/jsbridge/__init__.py
Expand Up @@ -109,7 +109,7 @@ def get_profile(self, *args, **kwargs):
if self.options.debug:
kwargs.setdefault('preferences',
{}).update({'extensions.checkCompatibility':False})
profile = super(CLI, self).get_profile(*args, **kwargs)
profile = mozrunner.CLI.get_profile(self, *args, **kwargs)
profile.install_addon(extension_path)
if self.options.debug:
for addon in self.debug_addons:
Expand Down
61 changes: 27 additions & 34 deletions mozrunner/mozrunner/__init__.py
Expand Up @@ -143,12 +143,8 @@ def kill_process_by_name(name):
if len(get_pids(name)) is not 0:
logger.error('Could not kill process')

def NaN(str):
try: int(str); return False;
except: return True

def makedirs(name):
# from errno import EEXIST

head, tail = os.path.split(name)
if not tail:
head, tail = os.path.split(head)
Expand All @@ -167,24 +163,29 @@ def makedirs(name):
class Profile(object):
"""Handles all operations regarding profile. Created new profiles, installs extensions,
sets preferences and handles cleanup."""
def __init__(self, binary=None, profile=None, create_new=True, addons=[], preferences={}):
self.addons_installed = []
self.profile = profile

def __init__(self, binary=None, profile=None, addons=None,
preferences=None):

self.binary = binary
self.create_new = create_new
self.addons = addons
if not hasattr(self, 'preferences'):
self.preferences = preferences

self.create_new = not(bool(profile))
if profile:
self.profile = profile
else:
self.preferences = copy.copy(self.preferences)
self.preferences.update(preferences)

if profile is not None and create_new is True:
raise Exception('You cannot set the profie location if you want mozrunner to create a new one for you.')
if create_new is False and profile is None:
raise Exception('If you set create_new to False you must provide the location of the profile you would like to run')
if create_new is True:
self.profile = self.create_new_profile(self.binary)

self.addons_installed = []
self.addons = addons

### set preferences from class preferences
prefereneces = preferences or {}
if hasattr(self.__class__, 'preferences'):
self.preferences = self.__class__.preferences.copy()
else:
self.preferences = {}
self.preferences.update(preferences)

for addon in addons:
self.install_addon(addon)

Expand All @@ -193,10 +194,6 @@ def __init__(self, binary=None, profile=None, create_new=True, addons=[], prefer
def create_new_profile(self, binary):
"""Create a new clean profile in tmp which is a simple empty folder"""
profile = tempfile.mkdtemp(suffix='.mozrunner')
if os.path.exists(profile) is True:
rmtree(profile)
makedirs(profile)

return profile

def install_addon(self, addon):
Expand Down Expand Up @@ -456,14 +453,9 @@ class CLI(object):
metavar=None, default=None),
('-p', "--profile",): dict(dest="profile", help="Profile path.",
metavar=None, default=None),
('-a', "--addons",): dict(dest="addons",
('-a', "--addons",): dict(dest="addons",
help="Addons paths to install.",
metavar=None, default=None),
("-n", "--no-new-profile",): dict(dest="create_new",
action="store_false",
help="Do not create new profile.",
metavar="MOZRUNNER_NEW_PROFILE",
default=True ),
}

def __init__(self):
Expand All @@ -473,6 +465,7 @@ def __init__(self):
self.parser.add_option(*names, **opts)
(self.options, self.args) = self.parser.parse_args()

# XXX should use action='append' instead of rolling our own
try:
self.addons = self.options.addons.split(',')
except:
Expand All @@ -483,7 +476,6 @@ def create_runner(self):
runner = self.get_runner(binary=self.options.binary)
profile = self.get_profile(binary=runner.binary,
profile=self.options.profile,
create_new=self.options.create_new,
addons=self.addons)
runner.profile = profile
return runner
Expand All @@ -493,10 +485,11 @@ def get_runner(self, binary=None, profile=None):
the profile instance returned from self.get_profile()."""
return self.runner_class(binary, profile)

def get_profile(self, binary=None, profile=None, create_new=None, addons=[],
preferences={}):
def get_profile(self, binary=None, profile=None, addons=None, preferences=None):
"""Returns the profile instance for the given command line arguments."""
return self.profile_class(binary, profile, create_new, addons, preferences)
addons = addons or []
preferences = preferences or {}
return self.profile_class(binary, profile, addons, preferences)

def run(self):
runner = self.create_runner()
Expand Down

0 comments on commit 48e4dcb

Please sign in to comment.