Skip to content

Commit

Permalink
Merge branch 'revamp'
Browse files Browse the repository at this point in the history
  • Loading branch information
heynemann committed May 23, 2011
2 parents ca373aa + fed8377 commit c1c2736
Show file tree
Hide file tree
Showing 210 changed files with 34,146 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
@@ -1,3 +1,7 @@
# since I'm revamping I'm using a tool that I think is faster and more
# descriptive for tests - http://pyvows.org
vows:
@env PYTHONPATH=$$PYTHONPATH:. pyvows tests/
# Not sure if that's a appropriate, but since nose is pretty much the standard
# in python I guessed it to be a good choice.
test:
Expand Down
Empty file added cordova/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions cordova/commands/__init__.py
@@ -0,0 +1,24 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from cordova.commands.help import HelpCommand
from cordova.commands.version import VersionCommand
from cordova.commands.read_config import ReadConfigCommand
from cordova.commands.validate_config import ValidateConfigCommand
from cordova.commands.version_index import VersionIndexCommand
from cordova.commands.find_plugin import FindPluginCommand
from cordova.commands.install_plugin import InstallPluginCommand
from cordova.commands.create import CreateCommand
from cordova.commands.list_recipes import ListRecipesCommand

COMMANDS = [
ListRecipesCommand,
CreateCommand,
FindPluginCommand,
InstallPluginCommand,
ReadConfigCommand,
ValidateConfigCommand,
VersionIndexCommand,
VersionCommand,
HelpCommand,
]
26 changes: 26 additions & 0 deletions cordova/commands/base.py
@@ -0,0 +1,26 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
from os.path import abspath, exists, join

from cordova.version import __version__

class Command(object):

def __init__(self, console):
self.console = console

@staticmethod
def print_version():
print 'PhoneGap - Cordova v%d.%d.%d' % __version__

def run(self):
raise NotImplementedError()

def is_cordova_folder(self, path=None):
if not path:
path = abspath(os.curdir)

return exists(join(path, 'www')) and exists(join(path, 'tmp'))

83 changes: 83 additions & 0 deletions cordova/commands/create.py
@@ -0,0 +1,83 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import os
from os.path import join, abspath, dirname
from optparse import OptionParser
import shutil

from cordova.commands.base import Command

class CreateCommand(Command):
key = 'create'
type = 'main'

def run(self):
root_path = abspath(join(dirname(__file__), '..', '..'))
recipes_path = join(root_path, 'recipes')

parser = OptionParser()

parser.add_option('-w', '--www', action='store',
dest='www', default='vanilla',
help='recipe for www')

parser.add_option('-t', '--test', action='store',
dest='test', default='qunit',
help='recipe for test directory')

options, args = parser.parse_args(self.console.arguments)

if not args:
print 'ERROR: The project name is required!'
print
print 'Type "phonegap help create" for more information.'
print
self.print_version()
sys.exit(1)

prj = args[0]

www = join(recipes_path, options.www)
test = join(recipes_path, options.test)

tmpl = join(root_path, 'generate-template')
dest = abspath(join(os.curdir, prj))
dest_www = join(dest, 'www')
dest_test = join(dest, 'test')

# copy in the new project yay!
shutil.copytree(tmpl, dest)

# clobber crummy local www
shutil.rmtree(dest_www)
shutil.rmtree(dest_test)

# copy in recipes for www and test
shutil.copytree(www, dest_www)
shutil.copytree(test, dest_test)

print 'Project %s was created successfully!' % prj
print
print 'Don\'t forget to edit the config.xml file under www.'
print 'Use ./bin/emulate to fire all emulators and ./bin/debug to install and debug your app.'
print 'Explore the ./bin/ for more options.'
print 'Happy hacking!'

@staticmethod
def print_overview():
print ' create - starts a new PhoneGap project.'

@classmethod
def print_detailed_usage(cls):
print 'Usage: phonegap create [project name] [-w WWW_TEMPLATE, --www=WWW_TEMPLATE] [-t TEST_TEMPLATE, --test=TEST_TEMPLATE]'
print
print ' Starts a new PhoneGap project named after project name.'
print ' The www template is optional and defaults to the vanilla template.'
print ' The test template is also optional and defaults to qunit.'

print
cls.print_version()


133 changes: 133 additions & 0 deletions cordova/commands/find_plugin.py
@@ -0,0 +1,133 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import re
import json
import urllib

from cordova.commands.base import Command

class PluginList(list):
def find_by_key(self, key):
for item in self:
if item.key == key:
return item
return None

class Repository(object):
def __init__(self, type, url):
self.type = type
self.url = url

class Plugin(object):
def __init__(self,
name,
description,
version,
repository_type,
repository_url,
author,
directories,
engines):
self.name = name
self.description = description
self.version = version
self.repository = Repository(repository_type, repository_url)
self.author = author
self.directories = directories
self.engines = engines

@classmethod
def from_json(cls, item):
return Plugin(item['name'], item['description'], item['version'], item['repository']['type'],
item['repository']['url'], item['author'], item['directories'], item['engines'])

def simple_describe(self):
return "%s v%s - %s" % (self.name, self.version, self.description)

def detailed_describe(self):
name = "%s v%s" % (self.name, self.version)
name_separator = "-" * len(name)

description = [
name,
name_separator,
self.description,
'',
'Author: %s' % self.author,
'Repository (%s): %s' % (self.repository.type, self.repository.url)
]

return "\n".join(description)

class FindPluginCommand(Command):
key = 'find-plugin'
type = 'main'
url = 'http://phonegap-plugins.appspot.com/_je/plugin'

@classmethod
def get_all_plugins(cls):
try:
plugins_json = urllib.urlopen(cls.url).read()
plugins = json.loads(plugins_json)

plugin_list = PluginList()
for index, item in enumerate(plugins):
if not 'name' in item:
continue
plugin_list.append(Plugin.from_json(item))

return plugin_list
except (ValueError, ):
return None

def run(self):
plugin_list = self.get_all_plugins()
if plugin_list is None:
print "Connection to %s failed. Could not retrieve plugin list." % self.url
sys.exit(1)

plugin_name = None
if self.console.arguments:
plugin_name = self.console.arguments[-1]

if not plugin_name:
print 'Available PhoneGap Plugins'
print

for plugin in plugin_list:
print ' %s' % plugin.simple_describe()

print
print "Type 'phonegap find-plugin <plugin name or part of plugin name>' to find more about it."

print
self.print_version()

else:
matching_plugins = [plugin for plugin in plugin_list if re.search(plugin_name.lower(), plugin.name.lower())]

if not matching_plugins:
print "No plugin found with a name that matches %s." % plugin_name
sys.exit(1)

for plugin in matching_plugins:
print plugin.detailed_describe()

print
self.print_version()

@staticmethod
def print_overview():
print ' find-plugin - shows informaton on a given plugin or lists all available plugins.'

@classmethod
def print_detailed_usage(cls):
print 'Usage: phonegap find-plugin [plugin name]'
print
print ' Shows information on plugins. Displays information about one plugin if plugin name is specified.'
print
cls.print_version()


69 changes: 69 additions & 0 deletions cordova/commands/help.py
@@ -0,0 +1,69 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys

from cordova.commands.base import Command

class HelpCommand(Command):
key = 'help'
type = 'system'

def __init__(self, console, all_commands):
super(HelpCommand, self).__init__(console)
self.all_commands = all_commands

def run(self):
if not self.console.arguments:
self.print_detailed_usage()
return

command_key = self.console.arguments[0]
command = [command for command in self.all_commands if command.key == command_key]

if not command or command_key == 'help':
print "Error: command %s not found." % command_key
print

print 'Usage: phonegap help command'
print

self.print_version()
sys.exit(1)

command[0].print_detailed_usage()

def print_detailed_usage(self):
self.print_usage()
print

self.print_commands()

print
print "See 'phonegap help <command>' for more information on a specific command."
print

self.print_version()

def print_usage(self):
print 'Usage: phonegap command [options]'

@staticmethod
def print_overview():
print ' help - show this help message and exit.'

def print_commands(self):
print 'Available commands:'
for command in filter(lambda c: c.type == 'main', self.all_commands):
command.print_overview()

print
print 'Utilities:'
for command in filter(lambda c: c.type == 'util', self.all_commands):
command.print_overview()

print
print 'Other commands:'
for command in filter(lambda c: c.type == 'system', self.all_commands):
command.print_overview()

38 changes: 38 additions & 0 deletions cordova/commands/install_plugin.py
@@ -0,0 +1,38 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys

from cordova.commands.base import Command

class InstallPluginCommand(Command):
key = 'install-plugin'
type = 'main'

def run(self):
if not self.console.arguments:
print 'ERROR: The plugin name is mandatory!'
print
self.print_version()
sys.exit(1)

plugin_list = self.get_all_plugins()
plugin = plugin_list.find_by_key(self.console.arguments)
if not plugin:
print 'ERROR: The plugin with key %s was not found!'
print
self.print_version()

@staticmethod
def print_overview():
print ' install-plugin - install the specified plugin in the current PhoneGap project.'

@classmethod
def print_detailed_usage(cls):
print 'Usage: phonegap install-plugin [plugin name]'
print
print ' Install the specified plugin in the current PhoneGap project.'
print
cls.print_version()


0 comments on commit c1c2736

Please sign in to comment.