25
24
from gettext import gettext as _
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
34
from quickly import commands, configurationhandler, quicklyconfig, tools, version
34
from quickly import commands, configurationhandler, quicklyconfig, coreupgrade, tools, version
36
36
gettext.textdomain('quickly')
41
quickly [OPTIONS] command ...
44
-t, --template <template> Template to use if it differs from default
46
one used to create the project)
47
--staging Target launchpad staging server
48
--verbose Verbose mode
49
-h, --help Show help information
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
57
quickly create ubuntu-project foobar
58
quickly push 'awesome new comment system'
59
quickly -t cool-template push 'awesome new comment system'""")
61
def process_command_line(argv):
62
"""Entry point for command line processing
63
use sys.argv by default if no args to parse
75
if arg.startswith('-'):
76
if arg == '--template' or arg == '-t':
77
opt_template = argv[i + 1]
79
elif arg == '--staging':
81
if os.environ.has_key('QUICKLY'):
82
oldenv = os.environ['QUICKLY']
83
os.environ['QUICKLY'] = "staging:" + oldenv
84
elif arg == '--verbose':
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()
92
elif arg == '--help' or arg == '-h':
96
opt_command.append(arg) # temporary solution, see commit.
98
opt_command.append(arg)
101
if len(opt_command) == 0:
102
print _("ERROR: No command provided in command line")
106
return (opt_command, opt_template)
110
"""seek for available commands for shell completion
112
: return tuples with list of available commands and origin (default or template)
115
available_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)
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)
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:
134
opt_template = configurationhandler.project_config['template']
137
# if no command, check for available command
138
if len(opt_command) == 1:
139
# list available command in template if suit context
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)])
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
150
print " ".join(elem for elem in available_completion if elem is not None)
154
40
"""Main ubuntu command line processor
156
42
:return: exit code of quickly command.
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]
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)
204
90
except IndexError:
205
91
# so, check for a template command followed by template
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():
103
commands.get_all_commands()[template][command_name]
104
proposed_templates.append(template)
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)
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])