def __init__(self, package_dir):
     # Figure out package directories.
     self.package_dir = os.path.abspath(package_dir)
     root_dir = setpath.setpath(self.package_dir, False)[0]
     assert self.package_dir.startswith(root_dir), \
            "%s: setpath did not return a root of package_dir,\n" \
            "  got %s\n" \
            "  for %s" % (os.path.basename(__file__), 
                          root_dir, 
                          self.package_dir)
     self.package_name = self.package_dir[len(root_dir) + 1:] \
                             .replace(os.sep, '.') \
                             .replace('/', '.')
     self.load_words()
Example #2
0
def test(path, remove_first_path = False, full = True):
    r"""Runs doctest on the file indicated by 'path'.

    This will run testmod if the file ends in .py, .pyc or .pyo; and testfile
    for all other files.

    When running testfile on python 2.5, it enables Python's "with" statement
    (as if the file being tested had done "from __future__ import
    with_statement").  This is done because doing the __future__ import does
    not work in files. :-(

    Also when running testfile, the current working directory is first set to
    the directory containing the file.  This is not done for python modules
    (.py, .pyc or .pyo files).

    In all cases, all non-package directories containing package directories
    (i.e., directories containing an __init__.{py,pyc,pyo} file) are added to
    sys.path.  The search is started in the directory containing the file.  If
    the bottom-most directory is not a package directory, it is added to the
    path too.
    """
    path = os.path.normpath(path)
    fullpath = os.path.abspath(path)
    if path.endswith('.py'):
        module = import_module(fullpath[:-3], remove_first_path, full)
    elif path.endswith(('.pyc', '.pyo')):
        module = import_module(fullpath[:-4], remove_first_path, full)
    else:
        new_paths = \
          setpath.setpath(fullpath, remove_first=remove_first_path, full=full)
        if debug:
            sys.stderr.write("setpath added: %s\n" % (new_paths,))
        os.chdir(os.path.dirname(fullpath))
        if sys.version_info[:2] == (2, 5):
            import __future__
            return doctest.testfile(fullpath, False,
                                    globs={
                                      'with_statement':
                                        __future__.with_statement,
                                    })
        else:
            return doctest.testfile(fullpath, False)
    module.doing_doctest = True
    return doctest.testmod(module)
Example #3
0
def import_module(modulepath, remove_first_path = False, full = True):
    r"""Imports the module indicated by modulepath.

    Also adds the proper containing directories to Python's sys.path.

    Returns the imported module.
    """
    pythonpath = \
      setpath.setpath(modulepath, remove_first=remove_first_path, full=full)
    if debug:
        sys.stderr.write("setpath added: %s\n" % (pythonpath,))
    modulepath = modulepath[len(pythonpath[0]) + 1:]
    if debug:
        sys.stderr.write("modulepath: %s\n" % (modulepath,))
    modulename = modulepath.replace('/', '.').replace(os.path.sep, '.')
    if debug:
        sys.stderr.write("modulename: %s\n" % (modulename,))
    module = __import__(modulename)
    for comp in modulename.split('.')[1:]:
        module = getattr(module, comp)
    return module
#!/usr/bin/python

# load.py memory_type

import os
import sys
import optparse

from doctest_tools import setpath
setpath.setpath(__file__, remove_first = True)

import wx
from ucc.parser import load
import ucc.config

config = ucc.config.load()

class options_dict(dict):
    def __setattr__(self, key, value):
        if value is not None:   
            self[key] = value

def run():
    optparser = optparse.OptionParser(
                  usage="usage: %s [options] [load_dir [memory_type]]" % 
                          os.path.basename(sys.argv[0]))

    optparser.add_option('--install_dir',
      help='the location of the arduino-xxxx directory downloaded from arduino.cc')
    optparser.add_option('--avrdude_port',
      help='the pseudo serial device on your PC that talks to the Arduino')