~ubuntu-branches/ubuntu/quantal/enigmail/quantal-security

« back to all changes in this revision

Viewing changes to mozilla/testing/mozbase/mozprofile/mozprofile/cli.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-u3g8nmwa0pdwagwc
Tags: 2:1.5.2-0ubuntu0.12.10.1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# This Source Code Form is subject to the terms of the Mozilla Public
 
4
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
 
5
# You can obtain one at http://mozilla.org/MPL/2.0/.
 
6
 
 
7
"""
 
8
Creates and/or modifies a Firefox profile.
 
9
The profile can be modified by passing in addons to install or preferences to set.
 
10
If no profile is specified, a new profile is created and the path of the resulting profile is printed.
 
11
"""
 
12
 
 
13
import sys
 
14
from addons import AddonManager
 
15
from optparse import OptionParser
 
16
from prefs import Preferences
 
17
from profile import Profile
 
18
 
 
19
__all__ = ['MozProfileCLI', 'cli']
 
20
 
 
21
class MozProfileCLI(object):
 
22
 
 
23
    module = 'mozprofile'
 
24
 
 
25
    def __init__(self, args=sys.argv[1:]):
 
26
        self.parser = OptionParser(description=__doc__)
 
27
        self.add_options(self.parser)
 
28
        (self.options, self.args) = self.parser.parse_args(args)
 
29
 
 
30
    def add_options(self, parser):
 
31
 
 
32
        parser.add_option("-p", "--profile", dest="profile",
 
33
                          help="The path to the profile to operate on. If none, creates a new profile in temp directory")
 
34
        parser.add_option("-a", "--addon", dest="addons",
 
35
                          action="append", default=[],
 
36
                          help="Addon paths to install. Can be a filepath, a directory containing addons, or a url")
 
37
        parser.add_option("--addon-manifests", dest="addon_manifests",
 
38
                          action="append",
 
39
                          help="An addon manifest to install")
 
40
        parser.add_option("--pref", dest="prefs",
 
41
                          action='append', default=[],
 
42
                          help="A preference to set. Must be a key-value pair separated by a ':'")
 
43
        parser.add_option("--preferences", dest="prefs_files",
 
44
                          action='append', default=[],
 
45
                          metavar="FILE",
 
46
                          help="read preferences from a JSON or INI file. For INI, use 'file.ini:section' to specify a particular section.")
 
47
 
 
48
    def profile_args(self):
 
49
        """arguments to instantiate the profile class"""
 
50
        return dict(profile=self.options.profile,
 
51
                    addons=self.options.addons,
 
52
                    addon_manifests=self.options.addon_manifests,
 
53
                    preferences=self.preferences())
 
54
 
 
55
    def preferences(self):
 
56
        """profile preferences"""
 
57
 
 
58
        # object to hold preferences
 
59
        prefs = Preferences()
 
60
 
 
61
        # add preferences files
 
62
        for prefs_file in self.options.prefs_files:
 
63
            prefs.add_file(prefs_file)
 
64
 
 
65
        # change CLI preferences into 2-tuples
 
66
        separator = ':'
 
67
        cli_prefs = []
 
68
        for pref in self.options.prefs:
 
69
            if separator not in pref:
 
70
                self.parser.error("Preference must be a key-value pair separated by a ':' (You gave: %s)" % pref)
 
71
            cli_prefs.append(pref.split(separator, 1))
 
72
 
 
73
        # string preferences
 
74
        prefs.add(cli_prefs, cast=True)
 
75
 
 
76
        return prefs()
 
77
 
 
78
 
 
79
def cli(args=sys.argv[1:]):
 
80
 
 
81
    # process the command line
 
82
    cli = MozProfileCLI(args)
 
83
 
 
84
    # create the profile
 
85
    kwargs = cli.profile_args()
 
86
    kwargs['restore'] = False
 
87
    profile = Profile(**kwargs)
 
88
 
 
89
    # if no profile was passed in print the newly created profile
 
90
    if not cli.options.profile:
 
91
        print profile.profile
 
92
 
 
93
if __name__ == '__main__':
 
94
    cli()