~ubuntu-branches/ubuntu/natty/quickly/natty

« back to all changes in this revision

Viewing changes to bin/quickly

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-03-29 19:00:48 UTC
  • mfrom: (8.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100329190048-olhobq492x3xnztz
Tags: 0.3.90-0ubuntu1
* New release:
  Quickly core:
  - check now that --template has one argument
  - -- enables to give options to templates (unknown options and arguments
    are still given to templates but -- specify explicity what to give to
    templates commands like -h, --version...)
  - check and enable recreation of the credential if user deletes it on
    Launchpad
  - Use realpath so that we can symlink to the binary in trunk.
    (Jonathan Lange)
  - project_path_not_found is raised when data_path_not_found should be
    (originated from Philip Peitsch's patch). (LP: #497688)
  - importing command in one template from another template is now possible
    support as well "all" keyword to import all commands from a template
    into another one (take care of overridden commands too)
    (LP: #452306, #487301)
  - add an apport hook to get installed templates (LP: #411127)
  - enable option completion for templates
  - handle now version upgrade, launching script for templates and handling
    versionning on them
  - change getstarted wording (LP: #486180) - Grant
  - Quickly ship now "version" tag instead of "format" tag
  - add some templatetools to check X display
  - if a commands exit with 4, do not show "ERROR:" (case of wrong command
    usage, for instance)
  - Rewrote importing module in both bin/quickly and ubuntu-project binary
  - Add get_camel_case_name() and get_sentence_name() to templatetools
  - Refactor some code in pre_create hook()
  - Now dashes and spaces support in project name! Dealing with python and
    packaging issues for you. (LP: #493130)
  - Provide Quickly API (LP: #426480)
  - Fix some issues in the man page
  ubuntu-application Template:
  - Enabling upload to team or user ppa, as well as any ppa.
    Use --ppa ppaname or --ppa team/ppaname
    .quickly file can be used as well with ppa = ppaname or
    ppa = team/ppaname (LP: #470192)
    ppa completion is also available
  - Change BSD header by full license
  - Add MIT license
  - Fixes an error when launchpad display name contains unicode character
    (Petar Vasić)
  - Fix typo in quickly help save (Petar Vasić)
  - Adds logo.png as logo property in about dialog (LP: #478389)
    (Petar Vasić)
  - Remove lp-project-change command and add configure command.
    configure lp-project [project_name] to set/reset lp project binded to
    your Quickly project
    ppa <ppa name> to set a default ppa with your project
  - Fix ~/.selected-editor being ignored (LP: #484730)
  - Fix wrong shell completion when in a template (it wrongly proposed
    all commands followed by templates)
  - Check if we have a X display available before running "run" or launching
    GUI in "create" command.
  - add -- support in quickly run to pass options like --help, --version so
    that Quickly core don't take them.
  - enable preferences save call being called multiple times (Philip Peitsch)
  - Use realpath so that we can symlink to the binary in trunk.
  - Fixed some errors in the tutorial (Brian) (LP: #499356)
  - Fix missing import sys in setup.py (Philip Peitsch) (LP: #499712)
  - rename ubuntu-project to ubuntu-application
  - enhance quickly license (no more Copyright file, only one AUTHORS file)
    personal license needs COPYING file now (and the header will be copied in
    every files). No more # needed in those files too. Some other little
    refactoring too (LP: #469330)
  - autolicence by default on first share/release (with LP info and on GPL-3)
  - change versionning support in ubuntu application: (LP: #476814)
   + quickly share just adds -publicX to current version where X is bumped
     at each "quicky share" execution
   + quickly release remove -publicX (if any) and release with current YY.MM.
     If there is already a release with that version, it will be YY.MM.1, 
     then YY.MM.2
  - add accelerators to menu items (jens persson)
  - set correctly title dialog (Philip Peitsch) (LP: #501999)
  - about dialog box is now fully automated: (LP: #478414)
   + update copyright, authors, license (when licensing)
   + version (when sharing and releasing)
   + homepage (when changing launchpad project: release and configure)
  - add an 'add' command. $ quickly dialog … is now $ quickly add dialog …
    (LP: #438320)
  - enable automatic release and milestone built in LP, releasing and pushing
    upstream tarball (LP: #470344)
  - automatic collect and publish changelog message from commits and save
    messages used during devlopment. (LP: #476572)
  - add i18n to boiler plate (LP: #423529)
  - enable adding manual depdencies to quickly project (LP: #474639)
  - enable configure its own bzr branch and resetting parent branch even once
    already configured (quickly configure bzr <branch-path>)
  - now recommends seahorse-plugins to have a graphical prompt for signing
    package
  - rename quickly glade to quickly design (LP: #528664)
  - create command is now more flexible and enable people to inherit from
    other template more easily
  - add translation domain to gtkbuilder and fix some items that shouldn't
    been translatable (Łukasz Jernaś)
  - add apport and launchpadintegration to new and existing project once
    bounded to LP (Philip Peitsch)
  - fix spelling mistake "connexion" (Łukasz Jernaś) (LP: #532667)
  - the ubuntu-application tutorial is now internationalized and use docbook
    format. Translators, it's yours! (Shane Fagan) (LP: #525168)
  - package/share/release are now more quiet and only print something on error
    warning as a summary as with unfound packages, and so on (LP: #482915)
  - new algorithm to select good email automatically. Try to get the preferred
    email and update the AUTHOR file with it.
  - test GPG key and create one automatically if none is available. The
    corresponding public key availabity in launchpad is also checked.
    (LP: #427730, #408993)
  - add devscripts as a dependency (bug #465833), will fix all the depends
    mess later
  - bump python-distutils-extra (>= 2.18bzr1)
  ubuntu-cli Template:
  - first release using import command feature (no command written into the
    template itself). This is a basic ubuntu CLI application
  ubuntu-pygame Template:
  - first release using import command feature. python-pygame added as a
    depends
* debian/control:
  - renamed and separate in multiple packages to get a -common used with
    Quickly widgets (LP: #519633)
  - suggests python-quickly-widgets

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
# -*- coding: utf-8 -*-
3
 
# Copyright 2009 Canonical Ltd.
4
 
# Author 2009 Didier Roche
 
3
# Copyright 2009 Didier Roche
5
4
#
6
5
# This file is part of Quickly
7
6
#
24
23
import gettext
25
24
from gettext import gettext as _
26
25
 
27
 
# add quickly root directory (especially for trunk execution)
28
 
quickly_root_directory = os.path.dirname(sys.argv[0])
29
 
quickly_root_directory = os.path.abspath(quickly_root_directory + '/..')
30
 
if os.path.exists(quickly_root_directory + '/quickly') and quickly_root_directory not in sys.path:
 
26
# add quickly root directory (enable symlink, and trunk execution)
 
27
quickly_bin_directory = os.path.dirname(os.path.realpath(sys.argv[0]))
 
28
quickly_root_directory_name = os.path.dirname(quickly_bin_directory)
 
29
quickly_root_directory = os.path.abspath(quickly_root_directory_name)
 
30
if os.path.exists(os.path.join(quickly_root_directory, 'quickly')) and quickly_root_directory not in sys.path:
31
31
    sys.path.insert(0, quickly_root_directory)
32
32
    os.putenv('PYTHONPATH', quickly_root_directory) # for subprocesses
33
33
 
34
 
from quickly import commands, configurationhandler, quicklyconfig, tools, version
 
34
from quickly import commands, configurationhandler, quicklyconfig, coreupgrade, tools, version
35
35
 
36
36
gettext.textdomain('quickly')
37
37
 
38
38
 
39
 
def usage():
40
 
    print _("""Usage:
41
 
    quickly [OPTIONS] command ...
42
 
 
43
 
Options:
44
 
    -t, --template <template>  Template to use if it differs from default
45
 
                               project one
46
 
                               one used to create the project)
47
 
    --staging                  Target launchpad staging server
48
 
    --verbose                  Verbose mode
49
 
    -h, --help                 Show help information
50
 
 
51
 
Commands:
52
 
    create <template> <project-name> (template is mandatory for this command)
53
 
    quickly <template_origin> <template_dest> to create a create derived template
54
 
    getstarted to get some starting hints
55
 
 
56
 
Examples:
57
 
    quickly create ubuntu-project foobar
58
 
    quickly push 'awesome new comment system'
59
 
    quickly -t cool-template push 'awesome new comment system'""")
60
 
 
61
 
def process_command_line(argv):
62
 
    """Entry point for command line processing
63
 
    use sys.argv by default if no args to parse
64
 
 
65
 
    :return: options
66
 
    """
67
 
 
68
 
    opt_command = []
69
 
    opt_template = None
70
 
    i = 0
71
 
 
72
 
    while i < len(argv):
73
 
        arg = argv[i]
74
 
 
75
 
        if arg.startswith('-'):
76
 
            if arg == '--template' or arg == '-t':
77
 
                opt_template = argv[i + 1]
78
 
                i += 1
79
 
            elif arg == '--staging':
80
 
                oldenv = ""
81
 
                if os.environ.has_key('QUICKLY'):
82
 
                    oldenv = os.environ['QUICKLY']
83
 
                os.environ['QUICKLY'] = "staging:" + oldenv
84
 
            elif arg == '--verbose':
85
 
                oldenv = ""
86
 
                if os.environ.has_key('QUICKLY'):
87
 
                    oldenv = os.environ['QUICKLY']
88
 
                os.environ['QUICKLY'] = "verbose:" + oldenv
89
 
            elif arg == '--version':
90
 
                version.show_version()
91
 
                sys.exit(0)
92
 
            elif arg == '--help' or arg == '-h':
93
 
                usage()
94
 
                sys.exit(1)
95
 
            else:
96
 
                opt_command.append(arg) # temporary solution, see commit.
97
 
        else:
98
 
            opt_command.append(arg)
99
 
        i += 1
100
 
 
101
 
    if len(opt_command) == 0:
102
 
        print _("ERROR: No command provided in command line")
103
 
        usage()
104
 
        sys.exit(1)
105
 
 
106
 
    return (opt_command, opt_template)
107
 
 
108
 
 
109
 
def get_commands():
110
 
    """seek for available commands for shell completion
111
 
 
112
 
    : return tuples with list of available commands and origin (default or template)
113
 
    """
114
 
 
115
 
    available_completion = []
116
 
 
117
 
    # option completion
118
 
    if sys.argv[-1].startswith("-"):
119
 
        options = ("-h", "--help", "-t", "--template", "--staging", "--verbose", "--version")
120
 
        available_completion = [option for option in options if option.startswith(sys.argv[-1])]
121
 
        print " ".join(available_completion)
122
 
        return(0)
123
 
 
124
 
    # get available templates after option if needed
125
 
    if sys.argv[-2] in ("-t", "--template"):
126
 
        available_completion.extend(commands.get_all_templates())
127
 
        print " ".join(available_completion)
128
 
        return(0)        
129
 
    
130
 
    # treat commands and try to get the template from the project directory if we are in a project (if not already provided by the -t option)
131
 
    (opt_command, opt_template) = process_command_line(sys.argv[3:])
132
 
    if not opt_template and configurationhandler.loadConfig(can_stop=False) == 0:
133
 
        try:
134
 
            opt_template = configurationhandler.project_config['template']
135
 
        except KeyError:
136
 
            pass
137
 
    # if no command, check for available command
138
 
    if len(opt_command) == 1:
139
 
        # list available command in template if suit context
140
 
        if opt_template:
141
 
            available_completion.extend([command.name for command in commands.get_command_by_criteria(template=opt_template) if command.is_right_context(os.getcwd(), verbose=False)])
142
 
        # add builtins command and commands that are followed by template
143
 
        available_completion.extend([command.name for command in commands.get_command_by_criteria(template="builtins") if command.is_right_context(os.getcwd(), verbose=False)])
144
 
        available_completion.extend([command.name for command in commands.get_command_by_criteria(followed_by_template=True) if command.is_right_context(os.getcwd(), verbose=False)])      
145
 
        
146
 
    else:
147
 
        # ask for the command what she needs (it automatically handle the case of command followed by template and command followed by command)
148
 
        available_completion.extend([command.shell_completion(opt_template, opt_command[1:]) for command in commands.get_command_by_criteria(name=opt_command[0])]) # as 1: is '' or the begining of a word
149
 
        
150
 
    print " ".join(elem for elem in available_completion if elem is not None)
151
 
    return(0)
152
 
 
153
39
def main():
154
40
    """Main ubuntu command line processor
155
41
 
156
42
    :return: exit code of quickly command.
157
43
    """
158
44
 
159
 
    (opt_command, opt_template) = process_command_line(sys.argv[1:])
 
45
    (opt_command, opt_template) = tools.process_command_line(sys.argv[1:])
160
46
    command_name = opt_command[0]
161
47
    
162
48
    # try to get the template from the project directory if we are in a project (if not already provided by the -t option)
173
59
 
174
60
        # with this search, we are sure that only one command: (name,template) is unique
175
61
        try:
176
 
            command = commands.get_command_by_criteria(name=command_name, template=opt_template)[0]
 
62
            command = commands.get_commands_by_criteria(name=command_name, template=opt_template)[0]
177
63
        except IndexError:
178
64
            # if not found, try for builtins command
179
65
            try:
180
 
                command = commands.get_command_by_criteria(name=command_name, template='builtins')[0]
 
66
                command = commands.get_commands_by_criteria(name=command_name, template='builtins')[0]
181
67
            except IndexError: 
182
68
                print _("ERROR: No %s command found in template %s.") % (command_name, opt_template)
183
69
                print _("Aborting.")
187
73
    else:
188
74
        # check for a builtin command (again, one solution only)
189
75
        try:
190
 
            command = commands.get_command_by_criteria(name=command_name, template='builtins')[0]    
 
76
            command = commands.get_commands_by_criteria(name=command_name, template='builtins')[0]    
191
77
            # if it's a builtin command which has to be followed by a template, check that everything is correct
192
78
            if command.followed_by_template:
193
79
                try:
204
90
        except IndexError:        
205
91
            # so, check for a template command followed by template
206
92
            try:
207
 
                command = commands.get_command_by_criteria(name=command_name, template=opt_command[1], followed_by_template=True)[0]
 
93
                command = commands.get_commands_by_criteria(name=command_name, template=opt_command[1], followed_by_template=True)[0]
208
94
                opt_template = opt_command[1]
209
95
                opt_command.remove(opt_command[1])
210
96
            except IndexError:
211
97
                # to help the user, we can search if this command_name corresponds to a command in a template
212
 
                list_possible_commands = commands.get_command_by_criteria(name=command_name, followed_by_template=True)
 
98
                list_possible_commands = commands.get_commands_by_criteria(name=command_name, followed_by_template=True)
213
99
                if list_possible_commands:
214
 
                   print _("ERROR: %s command must be followed by a template and no template was found on the command line." % command_name)
215
 
                   print _("Candidates template are: %s") % ", ".join([command.template for command in list_possible_commands])
 
100
                    proposed_templates = []
 
101
                    for template in commands.get_all_templates():
 
102
                        try:
 
103
                            commands.get_all_commands()[template][command_name]
 
104
                            proposed_templates.append(template)
 
105
                        except KeyError:
 
106
                            pass
 
107
                    print _("ERROR: %s command must be followed by a template and no template was found on the command line." % command_name)
 
108
                    print _("Candidates template are: %s") % ", ".join(proposed_templates)
216
109
                else:
217
 
                    list_possible_commands = commands.get_command_by_criteria(name=command_name, followed_by_template=False)
 
110
                    list_possible_commands = commands.get_commands_by_criteria(name=command_name, followed_by_template=False)
218
111
                    if list_possible_commands:
219
112
                       print _("No template were found on the command line for command %s." % command_name)
220
113
                       print _("Candidates template are: %s") % ", ".join([command.template for command in list_possible_commands])                        
230
123
if __name__ == '__main__':
231
124
 
232
125
    if len(sys.argv) == 1:
233
 
        usage()
 
126
        tools.usage()
234
127
        sys.exit(1)
 
128
    # core upgrade (very early in the process to upgrade even in shell completion)
 
129
    coreupgrade.upgrade()
235
130
    # process the command line to send the right instructions
236
131
    if sys.argv[1] == 'shell-completion':
237
 
        exit(get_commands())
 
132
        print(" ".join(tools.get_completion_in_context(sys.argv)))
 
133
        exit(0)
238
134
    else:
239
135
        exit(main())
240
136