Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Each individual pyhoe command is implemented in it's own file. - Changed template to templates. The templates directory will hold several templates in the future.
- Loading branch information
Brian Gesiak
committed
Feb 10, 2012
1 parent
63994b2
commit a3f387b
Showing
23 changed files
with
151 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import sys | ||
import types | ||
import argparse | ||
from pyhoe import commands as cmds | ||
from pyhoe.commands import * | ||
|
||
COMMANDS = list(( | ||
cmds.__dict__.get(c) for c in dir(cmds) if isinstance( | ||
cmds.__dict__.get(c), types.ModuleType | ||
) | ||
)) | ||
|
||
def available_command_names(): | ||
""" | ||
Returns a list of command names in pyhoe.commands. | ||
""" | ||
return [c.__name__.split(".")[-1] for c in COMMANDS] | ||
|
||
|
||
if __name__ == "__main__": | ||
# Instantiate argument parser, add arguments. | ||
parser = argparse.ArgumentParser( | ||
prog="pyhoe", | ||
description = ( | ||
"Provides several convenient functions for developing " | ||
"Python packages and scripts using best practices." | ||
) | ||
) | ||
parser.add_argument( | ||
"action", | ||
choices = available_command_names(), | ||
help = "Choose an action for pyhoe to perform." | ||
) | ||
parser.add_argument( | ||
"options", | ||
nargs = "*", | ||
help = ( | ||
"Add any option flags or positional arguments for " | ||
"the specified action. You can see options by simply " | ||
"entering the action name." | ||
) | ||
) | ||
|
||
# Print help if no args provided. | ||
if len(sys.argv) <= 1: | ||
parser.print_help() | ||
sys.exit(0) # TODO - Perhaps exit with error? | ||
|
||
# Pass remaining args to appropriate function. | ||
args = vars(parser.parse_args(sys.argv[1:])) | ||
for c in COMMANDS: | ||
if args["action"] == c.__name__.split(".")[-1]: | ||
c.execute(sys.argv[2:]) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from os import listdir | ||
from os.path import dirname, splitext | ||
import re | ||
|
||
r = re.compile("^[a-zA-Z0-9]*\.py$") | ||
|
||
__all__ = [ | ||
splitext(m)[0]for m in listdir(dirname(__file__)) if r.match(m) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env python | ||
|
||
import os, sys | ||
import argparse | ||
from cmdline import CommandLineDelegator | ||
|
||
# FIXME - Place this somewhere | ||
TEMPLATE_DIR = "templates" | ||
|
||
def default_temaplate(): | ||
""" | ||
Returns a string representing the default template directory. | ||
""" | ||
default = "package" | ||
if default in os.listdir(TEMPLATE_DIR): | ||
return default | ||
else: | ||
return os.listdir(TEMPLATE_DIR)[0] | ||
|
||
|
||
def parse_cl_args(sysargs): | ||
""" | ||
Uses argparse to handle user input. | ||
Returns a __dict__ representation of | ||
the parsed arguments. | ||
""" | ||
parser = argparse.ArgumentParser( | ||
prog="pyhoe startproject", | ||
description = ( | ||
"Initializes a Python project using established best practices." | ||
) | ||
) | ||
parser.add_argument( | ||
"project_name", | ||
help = "The name of the project." | ||
) | ||
parser.add_argument( | ||
"-c", "--cucumber", | ||
action = "store_true", | ||
help = "Use freshen for behavior-driven development." | ||
) | ||
parser.add_argument( | ||
"-p", "--python", | ||
dest = "python_exe", | ||
help = ( | ||
"The Python interpreter to use, e.g.: " | ||
"--python=python2.6 will use the Python " | ||
"2.6 interpreter to create any new virtual " | ||
"environments." | ||
), | ||
) | ||
parser.add_argument( | ||
"-t", "--template", | ||
choices = os.listdir(TEMPLATE_DIR), | ||
default = default_temaplate(), | ||
help = "The template to use for your project." | ||
) | ||
parser.add_argument( | ||
"-y", "--yes-to-all", | ||
action = "store_true", | ||
help = ( | ||
"Skip all confirmation and use recommended settings." | ||
) | ||
) | ||
return vars(parser.parse_args(sysargs)) | ||
|
||
|
||
def execute(args=None): | ||
""" | ||
Parses sys.args or args parameter and executes | ||
the parsed values using CommandLineDelegator. | ||
""" | ||
a = args or sys.argv | ||
delegator = CommandLineDelegator(parse_cl_args(a)) | ||
delegator.execute() | ||
|
||
|
||
if __name__ == "__main__": | ||
execute() |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.