# coding=utf-8
"""
-Exports data from optparse-based manage.py commands and reports it to pycharm.django_manage_obtainer._XmlDumper
+Exports data from optparse-based manage.py commands and reports it to _xml.XmlDumper.
+This module encapsulates Django semi-public API knowledge, and not very stable because of it.
"""
from optparse import Option
import django
def report_data(dumper):
"""
- Fetches data from manage.py commands and reports it to dumper.
+ Fetches data from management commands and reports it to dumper.
- :type dumper _django_obtainer_core_XmlDumper
+ :type dumper _xml.XmlDumper
:param dumper: destination to report
"""
utility = ManagementUtility()
# coding=utf-8
"""
-TODO: Support real help (from show_help()), not only help text
This module exports information about manage commands and options from django to PyCharm.
Information is provided in XML (to prevent encoding troubles and simplify deserialization on java side).
It does not have schema (yet!) but here is XML format it uses.
</commandInfo>
</commandInfo-array>
-
+Classes like DjangoCommandsInfo is used on Java side.
"""
-from distutils.version import StrictVersion
from xml.dom import minidom
from xml.dom.minidom import Element
-import django
-import _django_obtainer_optparse
__author__ = 'Ilya.Kazakevich'
--- /dev/null
+# coding=utf-8
+"""
+This is an entry point of this helper.
+It fetches data from Django manage commands via _optparse module and report is via _xml module.
+See _xml module and readme.txt for more info.
+
+Module can be called directly, but be sure env var DJANGO_SETTINGS_MODULE is set to something like "mysite.settings"
+"""
+
+from distutils.version import LooseVersion
+import django
+import _optparse
+import _xml
+
+__author__ = 'Ilya.Kazakevich'
+
+# TODO: Support Django 1.8 as well, it uses argparse, not optparse
+version = LooseVersion(django.get_version())
+assert version < LooseVersion('1.8a'), "Only Django <1.8 is supported now"
+# Some django versions require setup
+if django.setup:
+ django.setup()
+dumper = _xml.XmlDumper()
+_optparse.report_data(dumper)
+print(dumper.xml)
\ No newline at end of file
--- /dev/null
+This helper fetchers manage commands from Django installation.
+It supports custom commands as well.
+Entry point is "provider.py": it exports data in XML format that is described in "_xml.py".
+This helper should be used in pair with com.jetbrains.django.manage.RealCommandsProvider
\ No newline at end of file
+++ /dev/null
-# coding=utf-8
-"""
-This XML is part of API implemented by XmlDumper, but data fetch engine is optparse-specific (at least in Django <1.8)
-and implemented in _django_obtainer_optparse.py.
-
-Module to be call package directly, just to get XML, but be sure env var DJANGO_SETTINGS_MODULE is set to something
-like "mysite.settings"
-"""
-from distutils.version import LooseVersion
-import django
-import _django_obtainer_optparse
-from _django_obtainer_core import XmlDumper
-
-__author__ = 'Ilya.Kazakevich'
-
-# TODO: Support Django 1.8 as well, it uses argparse, not optparse
-version = LooseVersion(django.get_version())
-assert version < LooseVersion('1.8a'), "Only Django <1.8 is supported now"
-# Some django versions require setup
-if django.setup:
- django.setup()
-dumper = XmlDumper()
-_django_obtainer_optparse.report_data(dumper)
-print(dumper.xml)
\ No newline at end of file
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import java.util.*;
+import java.util.List;
/**
- * Command
- * TODO: add args
+ * Command with arguments
*
* @author Ilya.Kazakevich
*/
-public final class Command {
- @NotNull
- private final String myName;
- @NotNull
- private final List<Argument> myArguments = new ArrayList<Argument>();
- @Nullable
- private final String myHelp;
-
- /**
- * @param help help text
- * @param name command name
- * @param arguments command arguments
- */
- public Command(@NotNull final String name, @Nullable final String help, @NotNull final Argument... arguments) {
- this(name, help, Arrays.asList(arguments));
- }
+public interface Command {
- /**
- * @param help help text
- * @param name command name
- * @param arguments command arguments
- */
- public Command(@NotNull final String name, @Nullable final String help, @NotNull final Collection<Argument> arguments) {
- myName = name;
- myArguments.addAll(arguments);
- myHelp = help;
- }
/**
* @return command name
*/
@NotNull
- String getName() {
- return myName;
- }
+ String getName();
/**
* @return command arguments
*/
@NotNull
- List<Argument> getArguments() {
- return Collections.unmodifiableList(myArguments);
- }
+ List<Argument> getArguments();
+ /**
+ * @return Command readable help text
+ */
@Nullable
- public String getHelp() {
- return myHelp;
- }
+ String getHelp();
}
--- /dev/null
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.jetbrains.python.commandInterface.commandsWithArgs;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.*;
+
+/**
+ * Simple command implementation
+ * @author Ilya.Kazakevich
+ */
+public class CommandAdapter implements Command {
+ @NotNull
+ private final String myName;
+ @NotNull
+ private final List<Argument> myArguments = new ArrayList<Argument>();
+ @Nullable
+ private final String myHelp;
+
+ /**
+ * @param help help text
+ * @param name command name
+ * @param arguments command arguments
+ */
+ public CommandAdapter(@NotNull final String name, @Nullable final String help, @NotNull final Argument... arguments) {
+ this(name, help, Arrays.asList(arguments));
+ }
+
+ /**
+ * @param help help text
+ * @param name command name
+ * @param arguments command arguments
+ */
+ public CommandAdapter(@NotNull final String name, @Nullable final String help, @NotNull final Collection<Argument> arguments) {
+ myName = name;
+ myArguments.addAll(arguments);
+ myHelp = help;
+ }
+
+ /**
+ * @return command name
+ */
+ @Override
+ @NotNull
+ public final String getName() {
+ return myName;
+ }
+
+ /**
+ * @return command arguments
+ */
+ @Override
+ @NotNull
+ public final List<Argument> getArguments() {
+ return Collections.unmodifiableList(myArguments);
+ }
+
+ @Override
+ @Nullable
+ public final String getHelp() {
+ return myHelp;
+ }
+}
* Command-line interface presenter that is command-based
*
* @author Ilya.Kazakevich
+ * @param <C> Command type
*/
-public class CommandInterfacePresenterCommandBased extends CommandInterfacePresenterAdapter {
+public class CommandInterfacePresenterCommandBased<C extends Command> extends CommandInterfacePresenterAdapter {
private static final Pattern EMPTY_SPACE = Pattern.compile("\\s+");
/**
* [name] -> command. Linked is used to preserve order.
*/
- private final Map<String, Command> myCommands = new LinkedHashMap<String, Command>();
+ private final Map<String, C> myCommands = new LinkedHashMap<String, C>();
/**
* currenly used strategy (see interface for more info)
*/
* @param commands available commands
*/
public CommandInterfacePresenterCommandBased(@NotNull final CommandInterfaceView view,
- @NotNull final Iterable<Command> commands) {
+ @NotNull final Iterable<C> commands) {
super(view);
- for (final Command command : commands) {
+ for (final C command : commands) {
myCommands.put(command.getName(), command);
}
}
* @param commands available commands
*/
public CommandInterfacePresenterCommandBased(@NotNull final CommandInterfaceView view,
- @NotNull final Command... commands) {
+ @NotNull final C... commands) {
this(view, Arrays.asList(commands));
}
* @return [command_name => command] all available commands
*/
@NotNull
- Map<String, Command> getCommands() {
+ protected final Map<String, C> getCommands() {
return Collections.unmodifiableMap(myCommands);
}