Skip to content

Commit

Permalink
made introspection less project specific
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmoggach committed Feb 16, 2012
1 parent 17d53a5 commit 56dc9c7
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 65 deletions.
6 changes: 3 additions & 3 deletions MANIFEST
Expand Up @@ -19,9 +19,9 @@ dirtt/data/templates/project_sequence.xml
dirtt/data/templates/project_shot.xml
dirtt/data/templates/project_work.xml
dirtt/data/templates/workspace.mel
dirtt/scripts/mkdirt
dirtt/scripts/mkdirtt
dirtt/scripts/mkproj
dirtt/scripts/mkproject.py
dirtt/scripts/mktemplate.py
dirtt/scripts/mktree.py
docs/index.rst
docs/news.rst
tests/__init__.py
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Expand Up @@ -71,12 +71,12 @@ Forking through Bitbucket
~~~~~~~~~~~~~~~~~~~~~~~~~

First of all, you need to fork from the official repository, which is
`https://bitbucket.org/mogga/python-dirtt <https://bitbucket.org/mogga/python-dirtt>`_.
`https://github.com/dshng/python-dirtt <https://github.com/dshng/python-dirtt>`_.

Log in to Bitbucket, go to the dirtt repository page, follow the fork link,
wait for Bitbucket to copy the repository and then clone your fork, like:

``git clone https://bitbucket.org/YOUR_USER_NAME/python-dirtt``
``git clone https://github.com/YOUR_USER_NAME/python-dirtt``

Now you can change whatever you want, commit, push to your fork and when
your contribution is done, follow the pull request link and send us a
Expand Down Expand Up @@ -221,5 +221,5 @@ Links

Here's the links:

`Bitbucket <https://bitbucket.org/mogga/python-dirtt>`_
`Bitbucket <https://github.com/dshng/python-dirtt>`_

3 changes: 2 additions & 1 deletion dirtt/__init__.py
Expand Up @@ -35,7 +35,6 @@ def get_version():


import os

from xml.etree import ElementTree
#from xml.sax import make_parser
from xml.sax import parseString
Expand All @@ -51,6 +50,7 @@ def get_version():

TEMPLATES_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data', 'templates')


def list_available_templates():
print "\n These are the available templates. Reference using the full path provided."
template_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data', 'templates')
Expand All @@ -69,6 +69,7 @@ def list_available_templates():
# template_list.append(os.path.join(root,file))
# print " %s" % os.path.join(root, file)


class DirectoryTreeHandler(ContentHandler):
"""
Main SAX Interface for handling directory tree XML templates
Expand Down
1 change: 0 additions & 1 deletion dirtt/data/dirtt.dtd
Expand Up @@ -61,4 +61,3 @@
idref IDREF #IMPLIED
ref CDATA #IMPLIED
dirname CDATA #IMPLIED>

42 changes: 0 additions & 42 deletions dirtt/scripts/mkdirtt.py

This file was deleted.

9 changes: 5 additions & 4 deletions dirtt/scripts/mkproj.py → dirtt/scripts/mkproject.py
@@ -1,11 +1,11 @@
#!/usr/bin/python

"""
python-dirtt - Directory Tree Templater
(c) 2012 Dashing Collective Inc. and contributors
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
python-dirtt - Directory Tree Templater
(c) 2012 Dashing Collective Inc. and contributors
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
mkproj.py
mkproject.py
This is a generic command line tool that prompts for template
variables in a given template and renders the tree.
Expand All @@ -31,6 +31,7 @@
SEQUENCE_TEMPLATE=os.path.join(TEMPLATE_DIR,"project_sequence.xml")
SHOT_TEMPLATE=os.path.join(TEMPLATE_DIR,"project_shot.xml")


def main():
usage = "usage: %prog [-t TEMPLATE]"
version=__import__('dirtt').get_version()
Expand Down
43 changes: 43 additions & 0 deletions dirtt/scripts/mktemplate.py
@@ -0,0 +1,43 @@
#!/usr/bin/env python

"""
python-dirtt - Directory Tree Templater
(c) 2012 Dashing Collective Inc. and contributors
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
mktemplate.py
This is a generic command line tool to create a tree template from an
existing source path
"""

import os
import sys
from optparse import OptionParser
from dirtt.util.introspection import *


def main():
usage = "usage: %prog [-p SOURCE_PATH]"
version=__import__('dirtt').get_version()
description="""Return an XML directory template from an existing directory tree."""
parser = OptionParser(usage=usage, version=version, description=description)
parser.add_option("-p", "--path", dest="source_path", help="Absolute path to source tree.")
(options, args) = parser.parse_args()
if options.project_path:
project_path = options.project_path
else:
project_path = None
print "\n You must specify a source path to introspect\n with -p or --path to run this script."
sys.exit(-6)
introspected_tree = TreeIntrospector(project_path)
introspected_tree.build_template()
sys.exit(0)


if __name__ == "__main__":
main()



10 changes: 5 additions & 5 deletions dirtt/scripts/mkdirt.py → dirtt/scripts/mktree.py
@@ -1,11 +1,11 @@
#!/usr/bin/python

"""
python-dirtt - Directory Tree Templater
(c) 2012 Dashing Collective Inc. and contributors
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
python-dirtt - Directory Tree Templater
(c) 2012 Dashing Collective Inc. and contributors
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
mkdirt.py
mktree.py
This is a generic command line tool that prompts for template
variables in a given template and renders the tree.
Expand All @@ -15,12 +15,12 @@
import os
import sys
from optparse import OptionParser

from dirtt import DirectoryTreeHandler, list_available_templates
from dirtt.util.template import return_placeholders

ENABLED_USERS = [0,1111,1003]


def main():
usage = "usage: %prog [-t TEMPLATE]"
version=__import__('dirtt').get_version()
Expand Down
2 changes: 1 addition & 1 deletion dirtt/util/introspection.py
Expand Up @@ -15,7 +15,7 @@
from xml.dom.minidom import Document
from stat import *

class ProjectBuilder:
class TreeIntrospector:

def __init__(self, base="."):
self.base = os.path.realpath(base)
Expand Down
21 changes: 19 additions & 2 deletions dirtt/util/template.py
Expand Up @@ -33,14 +33,15 @@ def foo(bar):
If there are syntax errors ``TemplateError`` will be raised.
"""


import re
import sys
import cgi
import urllib
import looper

__all__ = ['TemplateError', 'Template', 'sub', 'HTMLTemplate',
'sub_html', 'html', 'bunch']

__all__ = ['TemplateError', 'Template', 'sub', 'HTMLTemplate', 'sub_html', 'html', 'bunch']

token_re = re.compile(r'\{\{|\}\}')
in_re = re.compile(r'\s+in\s+')
Expand Down Expand Up @@ -311,6 +312,7 @@ def __repr__(self):
self.__class__.__name__,
' '.join(['%s=%r' % (k, v) for k, v in items]))


############################################################
## HTML Templating
############################################################
Expand All @@ -324,6 +326,7 @@ def __repr__(self):
return '<%s %r>' % (
self.__class__.__name__, self.value)


def html_quote(value):
if value is None:
return ''
Expand All @@ -337,6 +340,7 @@ def html_quote(value):
value = value.encode('ascii', 'xmlcharrefreplace')
return value


def url(v):
if not isinstance(v, basestring):
if hasattr(v, '__unicode__'):
Expand All @@ -347,6 +351,7 @@ def url(v):
v = v.encode('utf8')
return urllib.quote(v)


def attr(**kw):
kw = kw.items()
kw.sort()
Expand All @@ -359,6 +364,7 @@ def attr(**kw):
parts.append('%s="%s"' % (html_quote(name), html_quote(value)))
return html(' '.join(parts))


class HTMLTemplate(Template):

default_namespace = Template.default_namespace.copy()
Expand All @@ -375,6 +381,7 @@ def _repr(self, value, pos):
else:
return html_quote(plain)


def sub_html(content, **kw):
name = kw.get('__name')
tmpl = HTMLTemplate(content, name=name)
Expand All @@ -390,6 +397,7 @@ def f7(seq):
S,L = set, list
return S(L(seq))


def return_placeholders(s, name=None):
in_expr = False
vars = []
Expand Down Expand Up @@ -478,6 +486,7 @@ def lex(s, name=None, trim_whitespace=True):
trail_whitespace_re = re.compile(r'\n[\t ]*$')
lead_whitespace_re = re.compile(r'^[\t ]*\n')


def trim_lex(tokens):
r"""
Takes a lexed set of tokens, and removes whitespace when there is
Expand Down Expand Up @@ -527,6 +536,7 @@ def find_position(string, index):
leading = string[:index].splitlines()
return (len(leading), len(leading[-1])+1)


def parse(s, name=None):
r"""
Parses a string into a kind of AST
Expand Down Expand Up @@ -584,6 +594,7 @@ def parse(s, name=None):
result.append(next)
return result


def parse_expr(tokens, name, context=()):
if isinstance(tokens[0], basestring):
return tokens[0], tokens[1:]
Expand Down Expand Up @@ -628,6 +639,7 @@ def parse_expr(tokens, name, context=()):
return ('comment', pos, tokens[0][0]), tokens[1:]
return ('expr', pos, tokens[0][0]), tokens[1:]


def parse_cond(tokens, name, context):
start = tokens[0][1]
pieces = []
Expand All @@ -643,6 +655,7 @@ def parse_cond(tokens, name, context):
next, tokens = parse_one_cond(tokens, name, context)
pieces.append(next)


def parse_one_cond(tokens, name, context):
(first, pos), tokens = tokens[0], tokens[1:]
content = []
Expand All @@ -669,6 +682,7 @@ def parse_one_cond(tokens, name, context):
next, tokens = parse_expr(tokens, name, context)
content.append(next)


def parse_for(tokens, name, context):
first, pos = tokens[0]
tokens = tokens[1:]
Expand Down Expand Up @@ -703,6 +717,7 @@ def parse_for(tokens, name, context):
next, tokens = parse_expr(tokens, name, context)
content.append(next)


def parse_default(tokens, name, context):
first, pos = tokens[0]
assert first.startswith('default ')
Expand Down Expand Up @@ -731,6 +746,7 @@ def parse_default(tokens, name, context):
strings.
"""


def fill_command(args=None):
import sys, optparse, pkg_resources, os
if args is None:
Expand Down Expand Up @@ -793,6 +809,7 @@ def fill_command(args=None):
else:
sys.stdout.write(result)


if __name__ == '__main__':
from dirtt.util.template import fill_command
fill_command()
Expand Down
6 changes: 3 additions & 3 deletions docs/index.rst
Expand Up @@ -73,12 +73,12 @@ Forking through Bitbucket
~~~~~~~~~~~~~~~~~~~~~~~~~

First of all, you need to fork from the official repository, which is
`https://bitbucket.org/mogga/python-dirtt <https://bitbucket.org/mogga/python-dirtt>`_.
`https://github.com/dshng/python-dirtt <https://github.com/dshng/python-dirtt>`_.

Log in to Bitbucket, go to the dirtt repository page, follow the fork link,
wait for Bitbucket to copy the repository and then clone your fork, like:

``git clone https://bitbucket.org/YOUR_USER_NAME/python-dirtt``
``git clone https://github.com/YOUR_USER_NAME/python-dirtt``

Now you can change whatever you want, commit, push to your fork and when
your contribution is done, follow the pull request link and send us a
Expand Down Expand Up @@ -224,5 +224,5 @@ Links

Here's the links:

`Bitbucket <https://bitbucket.org/mogga/python-dirtt>`_
`Bitbucket <https://github.com/dshng/python-dirtt>`_

1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -60,6 +60,7 @@ def fullsplit(path, result=None):
root_dir = os.path.dirname(__file__)
if root_dir != '':
os.chdir(root_dir)

dirtt_dir = 'dirtt'

for dirpath, dirnames, filenames in os.walk(dirtt_dir):
Expand Down

0 comments on commit 56dc9c7

Please sign in to comment.