text:
"""Configuration variables for controlling specific things in VisTrails."""
from __future__ import division

import argparse
import ast
import copy
import itertools
import re
import shlex
import sys
import weakref

import os

from vistrails.core import system
from vistrails.core.utils import Ref, append_to_dict_of_lists
from vistrails.db.domain import DBConfiguration, DBConfigKey, DBConfigStr, \
    DBConfigInt, DBConfigFloat, DBConfigBool

##############################################################################

_docs = {}
_simple_docs = {}
_usage_args = set()

_simple_documentation = """
autoConnect: Automatically connect dragged in modules
autoSave: Automatically save backup vistrails every two minutes
batch: Run in batch mode instead of interactive mode
cache: Cache previous results so they may be used in future computations
dataDir: Default data directory
db: The name for the database to load the vistrail from
dbDefault: Save vistrails in a database by default
debugLevel: How much information should VisTrails log
defaultFileType: Default file type/extension for vistrails (.vt or .xml)
detachHistoryView: Show the version tree in a separate window
dotVistrails: User configuration directory
enablePackagesSilently: Automatically enable packages when needed
errorLog: Write errors to a log file
NoExecute: Do not execute specified workflows
executionLog: Track execution provenance when running workflows
fileDir: Default vistrail directory
fixedSpreadsheetCells: Draw spreadsheet cells at a fixed size
handlerDontAsk: Do not ask about extension handling at startup
hideUpgrades: Don't show upgrade nodes in the version tree
host: The hostname for the database to load the vistrail from
installBundles: Install missing Python dependencies
installBundlesWithPip: Use pip to install missing Python dependencies
isInServerMode: Indicates whether VisTrails is being run as a server
jobAutorun: Run jobs automatically when they finish
jobCheckInterval: How often to check for jobs (in seconds)
jobList: List running workflows
jobInfo: List jobs in running workflow
loadPackages: Whether to load the packages enabled in the configuration file
logDir: Log files directory
maxRecentVistrails: Number of recent vistrails
maximizeWindows: VisTrails windows should be maximized
migrateTags: Move tags to upgraded versions
multiHeads: Use multiple screens for VisTrails windows
multithread: Server will start a thread for each request
packageDir: System packages directory
parameterExploration: Run parameter exploration instead of workflow
parameters: List of parameters to use when running workflow
port: The port for the database to load the vistrail from
repositoryHTTPURL: Remote package repository URL
repositoryLocalPath: Local package repository directory
rootDirectory: Directory that contains the VisTrails source code
rpcConfig: Config file for server connection options
rpcInstances: Number of other instances that vistrails should start
rpcLogFile: Log file for XML RPC server
rpcPort: Port where this xml rpc server will work
rpcServer: Hostname or ip address where this xml rpc server will work
shell.fontFace: Console Font
shell.fontSize: Console Font Size
showConnectionErrors: Show error when input value doesn't match type during execution
showDebugPopups: Always bring debug messages to the front
showInlineParameterWidgets: Show editable parameters inside modules
showScrollbars: Show scrollbars on the version tree and workflow canvases
showSplash: Show VisTrails splash screen during startup
showSpreadsheetOnly: Hides the VisTrails main window
showVariantErrors: Show error when variant input value doesn't match type during execution
showWindow: Show the main window
singleInstance: Do not allow more than one instance of VisTrails to run at once
spreadsheetDumpCells: Defines the location for generated cells
spreadsheetDumpPDF: Whether the spreadsheet should dump images in PDF format
staticRegistry: XML registry file
stopOnError: Stop all workflow execution immediately after first error
subworkflowsDir: Local subworkflows directory
temporaryDir: Temporary files directory
thumbs.autoSave: Save thumbnails of visual results
thumbs.cacheDir: Thumbnail cache directory
thumbs.cacheSize: Thumbnail cache size (MB)
thumbs.mouseHover: Show thumbnails when mouse is hovering above a version
thumbs.tagsOnly: Store thumbnails only for tagged versions
upgradeDelay: Persist upgrade only after other changes
upgradeModuleFailPrompt: Alert when a subworkflow upgrade fails
upgrades: Attempt to automatically upgrade old workflows
useMacBrushedMetalStyle: Use a brushed metal interface (MacOS X only)
user: The username for the database to the load vistrail from
userPackageDir: Local packages directory
viewOnLoad: Whether to show pipeline or history view when opening vistrail
webRepositoryURL: Web repository URL
webRepositoryUser: Web repository username
outputVersionTree: Output the version tree as an image
outputPipelineGraph: Output the workflow graph as an image
"""

_documentation = """
autoConnect: Boolean

    Try to automatically connect a newly dragged in module to the rest
    of the workflow.

autoSave: Boolean

    Automatically save vistrails to allow recovery from crashes, etc.

batch: Boolean

    Run vistrails in batch mode instead of interactive mode.

cache: Boolean

    Cache previous results so they may be used in future computations.

dataDir: Path

    The location that VisTrails uses as a default directory for data.

db: String

    The name for the database to load the vistrail from.

dbDefault: Boolean

    Use a database as the default storage location for vistrails entities.

debugLevel: Integer

    How much information VisTrails should alert the user about (0:
    Critical errors only, 1: Critical errors and warnings, 2: Critical
    errors, warnings, and log messages).

defaultFileType: String

    Defaults to .vt but could be .xml.

detachHistoryView: Boolean

    Show the version tree in a separate window.

dotVistrails: Path

    The location to look for VisTrails user configurations and
    storage. Defaults to ~/.vistrails.

enablePackagesSilently: Boolean

    Do not prompt the user to enable packages, just do so
    automatically.

errorLog: Boolean

    Write errors to a log file.

noExecute: Boolean

    Do not execute specified workflows.

executionLog: Boolean

    Track execution provenance when running workflows.

fileDir: Path

    The location that VisTrails uses as a default directory for
    specifying files.

fixedSpreadsheetCells: Boolean

    Draw spreadsheet cells at a fixed size (for testing).

handlerDontAsk: Boolean

    Do not ask about extension handling at startup (Linux only).

hideUpgrades: Boolean

    Don't show the "upgrade" nodes in the version tree.

host: URL

    The hostname for the database to load the vistrail from.

installBundles: Boolean

    Automatically try to install missing Python dependencies.

installBundlesWithPip: Boolean

    Whether to try to use pip to install Python dependencies or use
    distribution support.

isInServerMode: Boolean

    Indicates whether VisTrails is being run as a server.

jobAutorun: Boolean

    Run jobs automatically when they finish.

jobCheckInterval: Integer:

    How often to check for jobs (in seconds, default=600).

jobList: Boolean

    List running workflows.

jobInfo: Boolean

    List jobs in running workflow

loadPackages: Boolean

    Whether to load the packages enabled in the configuration file

logDir: Path

    The path that indicates where log files should be stored.

logger: ConfigurationObject

    *Deprecated*

maximizeWindows: Boolean

    Whether the VisTrails windows should take up the entire screen space.

maxMemory: Integer

    *Deprecated*

maxRecentVistrails: Integer

    How many recently opened vistrails should be stored for "Open
    Recent" access.

migrateTags: Boolean

    Whether or not the tag on a workflow that was upgraded should be
    moved to point to the upgraded version.

minMemory: Integer

    *Deprecated*

multiHeads: Boolean

    Whether or not to use multiple screens for VisTrails windows.

multithread: Boolean

    Server will start a thread for each request.

OLDupgradeDelay: Boolean
    If True, will only persist the upgrade when a user makes a
    modification to or executes the workflow. Otherwise, the upgrade
    will be automatically added to the version tree when a user views
    an upgraded workflow.

outputDefaultSettings: ConfigurationObject

    One or more comma-separated key=value parameters.

outputSettings: ConfigurationObject

    One or more comma-separated key=value parameters.

packageDir: Path

    The directory to look for VisTrails core packages (use
    userPackageDir for user-defined packages).

parameterExploration: Boolean

    Open and execute parameter exploration specified by the
    version argument after the .vt file.

parameters: String

    List of parameters to use when running workflow.

port: Integer

    The port for the database to load the vistrail from.

pythonPrompt: Boolean

    *Deprecated*

recentVistrailList: String

    Storage for recent vistrails. Users should not edit.

repositoryHTTPURL: URL

    URL used to locate packages available to be installed.

repositoryLocalPath: Path

    Path used to locate packages available to be installed.

reviewMode: Boolean

    *Deprecated* Used to interactively export a pipeline.

rootDirectory: Path

    Directory that contains the VisTrails source code.

rpcConfig: String

    Config file for server connection options.

rpcInstances: Integer

    Number of other instances that vistrails should start.

rpcLogFile: String

    Log file for XML RPC server.

rpcPort: Integer

    Port where this xml rpc server will work.

rpcServer: URL

    Hostname or ip address where this xml rpc server will work.

runningJobsList: String

    Storage for recent vistrails; users should not edit.

shell: ConfigurationObject

    Settings for the appearance of the VisTrails console.

shell.fontFace: String

    The font to be used for the VisTrails console.

shell.fontSize: Integer

    The font size used for the VisTrails console.

showConnectionErrors: Boolean

    Alert the user if the value along a connection doesn't match
    connection types.

showDebugPopups: Boolean

    Always show the debug popups or only if there is a modal widget.

showMovies: Boolean

    *Deprecated* Set automatic movie creation on the spreadsheet.

showScrollbars: Boolean

    Whether VisTrails should show scrollbars on the version tree and workflow
    canvases.

showSplash: Boolean

    Whether the VisTrails splash screen should be shown on startup.

showSpreadsheetOnly: Boolean

    Whether the VisTrails main window should be hidden.

showVariantErrors: Boolean

    Alert the user if the value along a connection coming from a
    Variant output doesn't match the input port.

showWindow: Boolean

    Show the main VisTrails window.

singleInstance: Boolean

    Whether or not VisTrails should only allow one instance to be
    running.

spreadsheetDumpCells: Path

    If specified, defines the location for parameter exploration to
    store the cells it generates.

spreadsheetDumpPDF: Boolean

    Whether the spreadsheet should dump images in PDF format.

staticRegistry: Path

    If specified, VisTrails uses an XML file defining the VisTrails
    module registry to load modules instead of from the packages directly.

stopOnError: Boolean

    Whether or not VisTrails stops executing the rest of the workflow
    if it encounters an error in one module.

subworkflowsDir: Path

    The location where a user's local subworkflows are stored.

temporaryDir: Path

    The directory to use for temporary files generated by VisTrails.

thumbs: ConfiguationObject

    Settings for generating and saving thumbnail images.

thumbs.autoSave: Boolean

    Whether to save thumbnails of results when executing VisTrails.

thumbs.cacheDir: Path

    The directory to be used to cache thumbnails.

thumbs.cacheSize: Integer

    The size (in MB) of the thumbnail cache.

thumbs.mouseHover: Boolean

    Whether to show thumbnails when hovering over a version in the
    version tree.

thumbs.tagsOnly: Boolean

    If True, only stores thumbnails for tagged versions. Otherwise,
    stores thumbnails for all versions.

upgradeDelay: Boolean

    Persist upgrade only after other changes.

upgrades: Boolean

    Whether to upgrade old workflows so they work with newer packages.

upgradeModuleFailPrompt: Boolean

    Whether to alert the user when an upgrade may fail when upgrading
    a subworkflow.

useMacBrushedMetalStyle: Boolean

    Whether should use a brushed metal interface (MacOS X only).

user: String

    The username for the database to load the vistrail from.

userPackageDir: Boolean

    The location for user-installed packages (defaults to
    ~/.vistrails/userpackages).

viewOnLoad: String

    Whether to show pipeline or history view when opening vistrail
    Can be either appropriate/pipeline/history

webRepositoryURL: URL

    The URL of the web repository that should be attached to VisTrails
    (e.g. www.crowdlabs.org).

webRepositoryUser: String

    The default username for logging into a VisTrails web repository
    like crowdLabs.

outputVersionTree: Boolean

    Output the version tree as an image.

outputPipelineGraph: Boolean

    Output the workflow graph as an image.

showInlineParameterWidgets: Boolean

    Show editable parameters inside modules

"""

class ConfigType(object):
    NORMAL = 0
    SHOW_HIDE = 1
    ON_OFF = 2
    COMMAND_LINE = 3
    COMMAND_LINE_FLAG = 4
    INTERNAL = 5
    STORAGE = 6
    PACKAGE = 7
    SUBOBJECT = 8
    INTERNAL_SUBOBJECT = 9

class ConfigString(object):
    @classmethod
    def from_string(cls, val):
        if not val:
            return None
        return val

    @classmethod
    def to_string(cls, val):
        if val is None:
            return ""
        return val

class ConfigPath(ConfigString):
    pass

class ConfigURL(ConfigString):
    pass

class ConfigField(object):
    def __init__(self, name, default_val, val_type,
                 field_type=ConfigType.NORMAL, category=None, flag=None,
                 nargs=None, widget_type=None,
                 widget_options=None, depends_on=None):
        self.name = name
        self.default_val = default_val
        self.val_type = val_type
        self.field_type = field_type
        self.category = category
        self.flag = flag
        self.nargs = nargs
        self.widget_type = widget_type
        if widget_options is not None:
            self.widget_options = widget_options
        else:
            self.widget_options = {}
        self.depends_on = depends_on

    def from_string(self, str_val):
        if hasattr(self.val_type, "from_string"):
            return self.val_type.from_string(str_val)
        if not str_val:
            return None
        if issubclass(self.val_type, basestring):
            return str_val
        val = ast.literal_eval(str_val)
        if not isinstance(val, self.val_type):
            raise ValueError('Output setting "%s" cannot be parsed to %s' %
                             (self.name, self.val_type.__name__))
        return val

    def to_string(self, val):
        if hasattr(self.val_type, "to_string"):
            return self.val_type.to_string(val)
        elif val is None:
            return ""
        return unicode(val)

class ConfigFieldParent(object):
    def __init__(self, name, sub_fields):
        self.name = name
        self.sub_fields = sub_fields

base_config = {
    "Command-Line":
    [ConfigField("noExecute", False, bool, ConfigType.COMMAND_LINE_FLAG,
                 flag='-E'),
     ConfigField("batch", False, bool, ConfigType.COMMAND_LINE_FLAG,
                 flag='-b'),
     ConfigField("outputDirectory", None, ConfigPath, flag='-o'),
     ConfigField('outputDefaultSettings', [], str,
                 ConfigType.INTERNAL_SUBOBJECT),
     ConfigField('outputSettings', [], str, ConfigType.SUBOBJECT,
                 flag='-p'),
     # ConfigField("package", [], str, flag='-p', nargs='*'),
     ConfigField("parameters", None, str, ConfigType.COMMAND_LINE),
     ConfigField("parameterExploration", False, bool,
                 ConfigType.COMMAND_LINE_FLAG),
     ConfigField('showWindow', True, bool, ConfigType.COMMAND_LINE_FLAG),
     ConfigField("outputVersionTree", False, bool, ConfigType.COMMAND_LINE_FLAG),
     ConfigField("outputPipelineGraph", False, bool, ConfigType.COMMAND_LINE_FLAG),
     ConfigField("graphsAsPdf", True, bool, ConfigType.COMMAND_LINE_FLAG)],
    "Database":
    [ConfigField("host", None, ConfigURL, ConfigType.COMMAND_LINE),
     ConfigField("port", None, int, ConfigType.COMMAND_LINE),
     ConfigField("db", None, str, ConfigType.COMMAND_LINE),
     ConfigField("user", None, str, ConfigType.COMMAND_LINE)],
    "Server":
    [ConfigField('rpcServer', None, str, ConfigType.COMMAND_LINE),
     ConfigField('rpcPort', 8080, int, ConfigType.COMMAND_LINE),
     ConfigField('rpcLogFile', os.path.join(system.vistrails_root_directory(),
                       'rpcserver.log'), ConfigPath, ConfigType.COMMAND_LINE),
     ConfigField('rpcInstances', 0, int, ConfigType.COMMAND_LINE),
     ConfigField('multithread', None, bool, ConfigType.COMMAND_LINE_FLAG),
     ConfigField('rpcConfig', os.path.join(system.vistrails_root_directory(),
                      'server.cfg'), ConfigPath, ConfigType.COMMAND_LINE)],
    "General":
    [ConfigField('autoSave', True, bool, ConfigType.ON_OFF),
     ConfigField('dbDefault', False, bool, ConfigType.ON_OFF),
     ConfigField('cache', True, bool, ConfigType.ON_OFF),
     ConfigField('stopOnError', True, bool, ConfigType.ON_OFF),
     ConfigField('executionLog', True, bool, ConfigType.ON_OFF),
     ConfigField('errorLog', True, bool, ConfigType.ON_OFF),
     ConfigField('defaultFileType', system.vistrails_default_file_type(), str,
                 widget_type="combo",
                 widget_options={"allowed_values": [".vt", ".xml"],
                                 "label": "Default File Type/Extension"}),
     ConfigField('debugLevel', 0, int,
                 flag='-v',
                 widget_type="combo",
                 widget_options={"allowed_values": [0,1,2],
                                 "label": "Show alerts for",
                                 "remap": {0: "Critical Errors Only",
                                           1: "Critical Errors and Warnings",
                                           2: "Errors, Warnings, and " \
                                           "Debug Messages"}})],
    "Startup":
    [ConfigField('maximizeWindows', False, bool, ConfigType.ON_OFF),
     ConfigField('multiHeads', False, bool, ConfigType.ON_OFF),
     ConfigField('showSplash', True, bool, ConfigType.SHOW_HIDE)],
    "Upgrades":
    [ConfigField('upgrades', True, bool, ConfigType.ON_OFF),
     ConfigField('migrateTags', False, bool, ConfigType.ON_OFF,
                 depends_on="upgrades"),
     ConfigField('hideUpgrades', True, bool, ConfigType.ON_OFF,
                 depends_on='upgrades'),
     ConfigField('upgradeDelay', True, bool, ConfigType.ON_OFF,
                 depends_on="upgrades"),
     ConfigField('upgradeModuleFailPrompt', True, bool, ConfigType.ON_OFF,
                 depends_on="upgrades")],
    "Interface":
    [ConfigField('autoConnect', True, bool, ConfigType.ON_OFF),
     ConfigField('detachHistoryView', False, bool, ConfigType.ON_OFF),
     ConfigField('showConnectionErrors', False, bool, ConfigType.SHOW_HIDE),
     ConfigField('showVariantErrors', True, bool, ConfigType.SHOW_HIDE),
     ConfigField('showDebugPopups', False, bool, ConfigType.SHOW_HIDE),
     ConfigField('showScrollbars', True, bool, ConfigType.SHOW_HIDE),
     ConfigField('showInlineParameterWidgets', False, bool, ConfigType.SHOW_HIDE),
     ConfigFieldParent('shell',
        [ConfigField('fontFace', system.shell_font_face(), str),
         ConfigField('fontSize', system.shell_font_size(), int)]),
     ConfigField('maxRecentVistrails', 5, int),
     ConfigField('viewOnLoad', "appropriate", str, widget_type='combo',
                 widget_options={"allowed_values": ["appropriate",
                                                    "history",
                                                    "pipeline"],
                                 "label": "Default view after loading vistrail:",
                                 "remap": {"appropriate": "Most Appropriate",
                                           "history": "Always History",
                                           "pipeline": "Always Pipeline"}}),
     ConfigField('enableCustomVersionColors', False, bool, ConfigType.ON_OFF),
     ConfigField('fixedCustomVersionColorSaturation', False,
                 bool, ConfigType.ON_OFF)],
    "Thumbnails":
    [ConfigFieldParent('thumbs',
        [ConfigField('autoSave', True, bool, ConfigType.ON_OFF),
         ConfigField('mouseHover', False, bool, ConfigType.ON_OFF),
         ConfigField('tagsOnly', False, bool, ConfigType.ON_OFF),
         ConfigField('cacheDir', "thumbs", ConfigPath,
                     ConfigType.NORMAL),
         ConfigField('cacheSize', 20, int, widget_type='thumbnailcache')])],
    "Packages":
    [ConfigField('enablePackagesSilently', False, bool, ConfigType.ON_OFF),
     ConfigField('loadPackages', True, bool, ConfigType.ON_OFF),
     ConfigField('installBundles', True, bool, ConfigType.ON_OFF),
     ConfigField('installBundlesWithPip', False, bool, ConfigType.ON_OFF,
                 depends_on="installBundles"),
     ConfigField('repositoryLocalPath', None, ConfigPath),
     ConfigField('repositoryHTTPURL', "http://www.vistrails.org/packages",
                 ConfigURL)],
    "Paths":
    [ConfigField('dotVistrails', system.default_dot_vistrails(),
                 ConfigPath, flag="-S"),
     ConfigField('subworkflowsDir', "subworkflows", ConfigPath),
     ConfigField('dataDir', None, ConfigPath),
     ConfigField('packageDir', None, ConfigPath),
     ConfigField('userPackageDir', "userpackages", ConfigPath),
     ConfigField('fileDir', None, ConfigPath),
     ConfigField('logDir', "logs", ConfigPath),
     ConfigField('temporaryDir', None,  ConfigPath)],
    "Advanced":
    [ConfigField('singleInstance', True, bool, ConfigType.ON_OFF),
     ConfigField('staticRegistry', None, ConfigPath)],
    "Web Sharing":
    [ConfigField('webRepositoryURL', "http://www.crowdlabs.org", ConfigURL),
     ConfigField('webRepositoryUser', None, str)],
    "Internal":
    [ConfigField('recentVistrailList', None, str, ConfigType.STORAGE),
     ConfigField('isInServerMode', False, bool, ConfigType.INTERNAL),
     ConfigField('isRunningGUI', True, bool, ConfigType.INTERNAL),
     ConfigField('spawned', False, bool, ConfigType.INTERNAL),
     ConfigField('rootDirectory', None, ConfigPath, ConfigType.INTERNAL),
     ConfigField('developerDebugger', False, bool, ConfigType.INTERNAL),
     ConfigField('dontUnloadModules', False, bool, ConfigType.INTERNAL),
     ConfigField('bundleDeclinedList', '', str, ConfigType.INTERNAL)],
    "Jobs":
    [ConfigField('jobCheckInterval', 600, int),
     ConfigField('jobAutorun', False, bool),
     ConfigField('jobList', False, bool, ConfigType.COMMAND_LINE_FLAG),
     ConfigField('jobInfo', False, bool, ConfigType.COMMAND_LINE_FLAG)],
}

# FIXME make sure that the platform-specific configs are added!
mac_config = {
    "Interface":
    [ConfigField('useMacBrushedMetalStyle', True, bool, ConfigType.ON_OFF)]
}

win_config = { }

linux_config = {
    "General":
    [ConfigField('handlerCheck', None, str, ConfigType.INTERNAL,
                 widget_type="linuxext",
                 widget_options={'label': 'Extension Handler'}),
     ConfigField('handlerDontAsk', None, bool)]
}

all_configs = [base_config, mac_config, win_config, linux_config]

def build_config_obj(d):
    new_d = {}
    for category, fields in d.iteritems():
        for field in fields:
            if isinstance(field, ConfigFieldParent):
                new_d[field.name] = build_config_obj({category:
                                                      field.sub_fields})
            elif (field.field_type == ConfigType.SUBOBJECT or
                  field.field_type == ConfigType.INTERNAL_SUBOBJECT):
                new_d[field.name] = ConfigurationObject()
            else:
                v = field.default_val
                if v is None:
                    val_type = field.val_type
                    if (field.val_type == ConfigPath or
                        field.val_type == ConfigURL):
                        val_type = basestring
                    new_d[field.name] = (v, val_type)
                else:
                    new_d[field.name] = v
    return ConfigurationObject(**new_d)

def get_system_config():
    config = {}
    config.update((k, copy.copy(v)) for k, v in base_config.iteritems())
    if system.systemType in ['Windows', 'Microsoft']:
        sys_config = win_config
    elif system.systemType in ['Linux']:
        sys_config = linux_config
    elif system.systemType in ['Darwin']:
        sys_config = mac_config
    else:
        return config
    for category, fields in sys_config.iteritems():
        if category not in base_config:
            config[category] = fields
        else:
            config[category].extend(fields)
    return config

def default():
    config = get_system_config()
    retval = build_config_obj(config)
    return retval

def parse_documentation():
    line_iter = iter(_documentation.splitlines())
    line_iter.next()
    for line in line_iter:
        arg_path, arg_type = line.strip().split(':', 1)
        doc_lines = []
        line = line_iter.next()
        while True:
            line = line_iter.next()
            if not line.strip():
                break
            doc_lines.append(line.strip())
        _docs[arg_path] = (arg_type, ' '.join(doc_lines))

def parse_simple_docs():
    line_iter = iter(_simple_documentation.splitlines())
    line = line_iter.next()
    for line in line_iter:
        (arg, doc) = line.strip().split(':', 1)
        _simple_docs[arg] = doc.strip()

def find_help(arg_path):
    if len(_docs) == 0:
        parse_documentation()

    if arg_path in _docs:
        return _docs[arg_path][1]
    return None

def find_simpledoc(arg_path):
    if len(_simple_docs) == 0:
        parse_simple_docs()

    if arg_path in _simple_docs:
        return _simple_docs[arg_path]
    return find_help(arg_path)

def set_field_labels(fields, prefix=""):
    for field in fields:
        if isinstance(field, ConfigFieldParent):
            prefix = "%s%s." % (prefix, field.name)
            set_field_labels(field.sub_fields, prefix=prefix)
        else:
            full_field_name = "%s%s" % (prefix, field.name)
            label = find_simpledoc(full_field_name)
            if label is not None and 'label' not in field.widget_options:
                field.widget_options['label'] = label

for config in all_configs:
    for field_list in config.itervalues():
        set_field_labels(field_list)

class VisTrailsHelpFormatter(argparse.HelpFormatter):
    def add_usage(self, usage, actions, groups, prefix=None):
        new_actions = []
        new_actions.append(argparse.Action([], dest="__nowhere__",
                                           metavar="[CONFIGURATION OPTIONS]"))
        for action in actions:
            if action.dest in _usage_args:
                new_actions.append(action)
        argparse.HelpFormatter.add_usage(self, usage, new_actions, groups,
                                         prefix)

class NestedSetKwargs(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        orig_dest = self.dest
        nesting = self.dest.split('.')
        while len(nesting) > 1:
            namespace = getattr(namespace, nesting.pop(0))
        self.dest = nesting[0]

        param_splitter = shlex.shlex(values, posix=True)
        param_splitter.whitespace = ','
        param_splitter.whitespace_split = True
        for param in param_splitter:
            key_val_split = param.split('=',1)
            if len(key_val_split) < 2:
                raise ValueError("Expected key=value comma-separated list")
            key, val = key_val_split

            dest = "%s.%s" % (self.dest, key)
            namespace.set_deep_value(dest, val, True)
        self.dest = orig_dest

def nested_action(parser, action_type):
    cls = parser._registry_get('action', action_type)
    if cls is None:
        raise ValueError('Action type "%s" is not defined' % action_type)

    def __call__(self, parser, namespace, values, option_string=None):
        orig_dest = self.dest
        nesting = self.dest.split('.')
        while len(nesting) > 1:
            namespace = getattr(namespace, nesting.pop(0))
        self.dest = nesting[0]
        cls.__call__(self, parser, namespace, values, option_string=None)
        self.dest = orig_dest

    nested_name = "_Nested%s" % cls.__name__[1:]
    nested_cls = type(nested_name, (cls,), {"__call__": __call__})
    return nested_cls

class RawVersionAction(argparse.Action):
    """Variant of the default _VersionAction that doesn't reflow.
    """
    def __init__(self, option_strings, version,
                 dest=argparse.SUPPRESS, default=argparse.SUPPRESS,
                 help="show program's version and exit"):
        argparse.Action.__init__(self, option_strings=option_strings,
                                 dest=dest, default=default, nargs=0,
                                 help=help)
        self.version = version

    def __call__(self, parser, namespace, values, option_string=None):
        parser.exit(message=self.version)

def build_command_line_parser(d, parser=None, prefix="", **parser_args):
    # if k is not a command-line-option, skip
    # if k is show/hide, add --show-, --hide- options
    # if k is an on/off, add --option, --no-option flags
    # otherwise, run with k converted to dashed form and store res

    def camel_to_dashes(s):
        # from http://stackoverflow.com/questions/1175208/elegant-python-function-to-convert-camelcase-to-camel-case/1176023#1176023
        s1 = re.sub('(.)([A-Z][a-z]+)', r'\1-\2', s)
        return re.sub('([a-z0-9])([A-Z])', r'\1-\2', s1).lower()

    if parser is None:
        parser = argparse.ArgumentParser(prog='vistrails',
                                         **parser_args)
        parser._my_arg_groups = {}
        parser.add_argument('vistrails', metavar='vistrail', type=str,
                            nargs='*', help="Vistrail to open")
        _usage_args.add('vistrails')
        parser.add_argument('--version', action=RawVersionAction,
                            version=system.about_string())

    prefix_dashes = ''
    if prefix:
        prefix_dashes = camel_to_dashes(prefix.replace('.', '-'))

    for category, fields in d.iteritems():
        if category == "Internal":
            # don't deal with these
            continue
        if category == "Command-Line":
            cat_group = parser
        else:
            if category not in parser._my_arg_groups:
                parser._my_arg_groups[category] = \
                                        parser.add_argument_group(category)
            cat_group = parser._my_arg_groups[category]

        for field in fields:
            if isinstance(field, ConfigFieldParent):
                build_command_line_parser({category: field.sub_fields},
                                          parser,
                                          '%s%s.' % (prefix, field.name),
                                          **parser_args)
                continue
            k_dashes = camel_to_dashes(field.name)
            help_str = find_help('%s%s' % (prefix, field.name))
            dest_name = prefix + field.name

            config_type = field.field_type
            if config_type is None:
                config_type = ConfigType.NORMAL
            if (config_type == ConfigType.INTERNAL or \
                config_type == ConfigType.STORAGE or
                config_type == ConfigType.INTERNAL_SUBOBJECT):
                # these are not in the command line
                continue
            elif config_type == ConfigType.ON_OFF:
                k_dashes = camel_to_dashes(field.name)
                group = cat_group.add_mutually_exclusive_group()
                group.add_argument('--%s%s' % (prefix_dashes, k_dashes),
                                   # action="store_true",
                                   action=nested_action(group, "store_true"),
                                   dest=dest_name, help=help_str,
                                   default=argparse.SUPPRESS)
                group.add_argument('--no-%s%s' % (prefix_dashes, k_dashes),
                                   # action="store_false",
                                   action=nested_action(group, "store_false"),
                                   dest=dest_name,
                                   help=("Inverse of --%s%s" %
                                         (prefix_dashes, k_dashes)),
                                   default=argparse.SUPPRESS)
            elif config_type == ConfigType.SHOW_HIDE:
                k_dashes = camel_to_dashes(field.name[4:])
                group = cat_group.add_mutually_exclusive_group()
                group.add_argument('--show-%s%s' % (prefix_dashes, k_dashes),
                                   # action="store_true",
                                   action = nested_action(group, "store_true"),
                                   dest=dest_name, help=help_str,
                                   default=argparse.SUPPRESS)
                group.add_argument('--hide-%s%s' % (prefix_dashes, k_dashes),
                                   # action="store_false",
                                   action=nested_action(group, "store_false"),
                                   dest=dest_name,
                                   help=("Inverse of --show-%s%s" %
                                         (prefix_dashes, k_dashes)),
                                   default=argparse.SUPPRESS)
            else:
                k_dashes = camel_to_dashes(field.name)
                long_arg = '--%s%s' % (prefix_dashes, k_dashes)
                if field.flag is not None:
                    args = (field.flag, long_arg)
                else:
                    args = (long_arg,)
                kwargs = {'dest': dest_name,
                          'help': help_str,
                          'default': argparse.SUPPRESS}
                if (field.val_type != ConfigPath and
                    field.val_type != ConfigURL and
                    field.val_type != str and
                    field.val_type != bool):
                    kwargs["type"] = field.val_type
                if config_type == ConfigType.SUBOBJECT:
                    kwargs["action"] = NestedSetKwargs
                elif config_type == ConfigType.COMMAND_LINE_FLAG:
                    kwargs["action"] = nested_action(cat_group, "store_true")
                else:
                    kwargs["action"] = nested_action(cat_group, "store")
                if field.val_type == ConfigPath:
                    kwargs["metavar"] = "DIR"
                elif field.val_type == ConfigURL:
                    kwargs["metavar"] = "URL"
                if field.nargs is not None:
                    kwargs["nargs"] = field.nargs

                cat_group.add_argument(*args, **kwargs)
                if category == "Command-Line":
                    _usage_args.add(field.name)
    return parser

def build_default_parser():
    parser_args = {"formatter_class": VisTrailsHelpFormatter,
                   "argument_default": argparse.SUPPRESS}
    return build_command_line_parser(get_system_config(), **parser_args)

def build_sphinx_parser():
    # FIXME add system-specific config options somehow
    return build_command_line_parser(base_config)

class ConfigValue(object):
    @staticmethod
    def create(value):
        if isinstance(value, bool):
            obj = ConfigBool()
        elif isinstance(value, basestring):
            obj = ConfigStr()
        elif isinstance(value, int):
            obj = ConfigInt()
        elif isinstance(value, float):
            obj = ConfigFloat()
        elif isinstance(value, list):
            obj = ConfigList()
        elif isinstance(value, ConfigurationObject):
            obj = value
        elif value is None:
            obj = None
        else:
            raise Exception('Cannot create ConfigValue from value "%s"' % value)
        if obj is not None:
            obj.set_value(value)
        return obj

    def get_value(self):
        return self.db_value

    def set_value(self, val):
        self.db_value = val

class ConfigBool(DBConfigBool, ConfigValue):
    def __copy__(self):
        """ __copy__() -> ConfigBool - Returns a clone of itself """
        return ConfigBool.do_copy(self)

    def do_copy(self, new_ids=False, id_scope=None, id_remap=None):
        cp = DBConfigBool.do_copy(self, new_ids, id_scope, id_remap)
        cp.__class__ = ConfigBool
        return cp

    @staticmethod
    def convert(_val):
        _val.__class__ = ConfigBool

    def get_value(self):
        return self.db_value.lower() == "true"

    def set_value(self, val):
        self.db_value = unicode(val)

class ConfigInt(DBConfigInt, ConfigValue):
    def __copy__(self):
        """ __copy__() -> ConfigInt - Returns a clone of itself """
        return ConfigInt.do_copy(self)

    def do_copy(self, new_ids=False, id_scope=None, id_remap=None):
        cp = DBConfigInt.do_copy(self, new_ids, id_scope, id_remap)
        cp.__class__ = ConfigInt
        return cp

    @staticmethod
    def convert(_val):
        _val.__class__ = ConfigInt

class ConfigStr(DBConfigStr, ConfigValue):
    def __copy__(self):
        """ __copy__() -> ConfigStr - Returns a clone of itself """
        return ConfigStr.do_copy(self)

    def do_copy(self, new_ids=False, id_scope=None, id_remap=None):
        cp = DBConfigStr.do_copy(self, new_ids, id_scope, id_remap)
        cp.__class__ = ConfigStr
        return cp

    @staticmethod
    def convert(_val):
        _val.__class__ = ConfigStr

class ConfigFloat(DBConfigFloat, ConfigValue):
    def __copy__(self):
        """ __copy__() -> ConfigFloat - Returns a clone of itself """
        return ConfigFloat.do_copy(self)

    def do_copy(self, new_ids=False, id_scope=None, id_remap=None):
        cp = DBConfigFloat.do_copy(self, new_ids, id_scope, id_remap)
        cp.__class__ = ConfigFloat
        return cp

    @staticmethod
    def convert(_val):
        _val.__class__ = ConfigFloat

class ConfigList(DBConfigStr, ConfigValue):
    def __copy__(self):
        """ __copy__() -> ConfigList - Returns a clone of itself """
        return ConfigList.do_copy(self)

    def do_copy(self, new_ids=False, id_scope=None, id_remap=None):
        cp = DBConfigStr.do_copy(self, new_ids, id_scope, id_remap)
        cp.__class__ = ConfigList
        return cp

    @staticmethod
    def convert(_val):
        _val.__class__ = ConfigList

    def get_value(self):
        return ast.literal_eval(self.db_value)

    def set_value(self, val):
        self.db_value = unicode(val)

class ConfigKey(DBConfigKey):
    def __init__(self, name, value):
        if isinstance(value, tuple):
            DBConfigKey.__init__(self, name=name)
            self.set_type(value[1])
        else:
            DBConfigKey.__init__(self, name=name,
                                 value=ConfigValue.create(value))
            self.set_type(type(value))

    def __copy__(self):
        """ __copy__() -> ConfigKey - Returns a clone of itself """
        return ConfigKey.do_copy(self)

    def do_copy(self, new_ids=False, id_scope=None, id_remap=None):
        cp = DBConfigKey.do_copy(self, new_ids, id_scope, id_remap)
        cp.__class__ = ConfigKey
        cp._type = self._type
        return cp

    @staticmethod
    def convert(_key):
        _key.__class__ = ConfigKey
        if isinstance(_key.db_value, DBConfiguration):
            ConfigurationObject.convert(_key.db_value)
        elif isinstance(_key.db_value, DBConfigBool):
            ConfigBool.convert(_key.db_value)
        elif isinstance(_key.db_value, DBConfigStr):
            ConfigStr.convert(_key.db_value)
        elif isinstance(_key.db_value, DBConfigInt):
            ConfigInt.convert(_key.db_value)
        elif isinstance(_key.db_value, DBConfigFloat):
            ConfigFloat.convert(_key.db_value)
        #FIXME add ConfigList to db and here
        _key.set_type(type(_key.value))

    def _get_value(self):
        if self.db_value is not None:
            return self.db_value.get_value()
        return None
    def _set_value(self, val):
        if not self.check_type(val):
            raise TypeError('Value "%s" does not match type %s' %
                            (val, self._type))
        self.db_value = ConfigValue.create(val)
    value = property(_get_value, _set_value)

    def set_type(self, t):
        if issubclass(t, basestring):
            t = basestring
        self._type = t

    def check_type(self, val):
        return val is None or isinstance(val, self._type)

class ConfigurationObject(DBConfiguration):
    """A ConfigurationObject is an InstanceObject that respects the
    following convention: values that are not 'present' in the object
    should have value (None, type), where type is the type of the
    expected object.

    ConfigurationObject exists so that the GUI can automatically infer
    the right types for the widgets.

    """

    def __init__(self, **kwargs):
        self._in_init = True
        self._unset_keys = {}
        DBConfiguration.__init__(self)
        self._in_init = False
        for k, v in kwargs.iteritems():
            if type(v) == tuple:
                self._unset_keys[k] = v
            else:
                key = ConfigKey(name=k, value=v)
                self.db_add_config_key(key)

        # InstanceObject.__init__(self, *args, **kwargs)
        self._subscribers = {}
        self.vistrails = []

    def __copy__(self):
        """ __copy__() -> ConfigurationObject - Returns a clone of itself """
        return ConfigurationObject.do_copy(self)

    def do_copy(self, new_ids=False, id_scope=None, id_remap=None):
        cp = DBConfiguration.do_copy(self, new_ids, id_scope, id_remap)
        cp._in_init = False
        cp.__class__ = ConfigurationObject
        cp._unset_keys = copy.copy(self._unset_keys)
        cp._subscribers = copy.copy(self._subscribers)
        cp.vistrails = copy.copy(self.vistrails)
        return cp

    @staticmethod
    def convert(_config_obj):
        _config_obj._in_init = False
        _config_obj.__class__ = ConfigurationObject
        for _key in _config_obj.db_config_keys:
            ConfigKey.convert(_key)
        _config_obj._subscribers = {}
        _config_obj._unset_keys = {}
        _config_obj.vistrails = []

    def get_value(self):
        return self

    def set_value(self, val):
        # it itself is the value already
        pass

    def matches_type(self, value, t):
        if t == str:
            t = basestring
        return isinstance(value, t)

    def __getattr__(self, name):
        try:
            return object.__getattribute__(self, name)
        except AttributeError:
            try:
                return self.get(name)
            except:
                raise AttributeError(name)

    def __setattr__(self, name, value):
        if name == '_subscribers' or name == '_unset_keys' or name == '_in_init' or name == 'is_dirty' or name == 'vistrails' or self._in_init:
            object.__setattr__(self, name, value)
        else:
            if name in self.db_config_keys_name_index:
                config_key = self.db_config_keys_name_index[name]
                if value is None:
                    self.db_delete_config_key(config_key)
                    self._unset_keys[name] = (None, type(config_key.value))
                else:
                    config_key.value = value
            else:
                if name not in self._unset_keys:
                    self._unset_keys[name] = (None, type(value))
                    # raise AttributeError('Key "%s" was not defined when '
                    #                      'ConfigurationObject was created' %
                    #                      name)
                if (value is not None and
                      not self.matches_type(value, self._unset_keys[name][1])):
                    raise TypeError('Value "%s" does match type "%s" for "%s"' %
                                    (value, self._unset_keys[name][1], name))
                if value is not None:
                    del self._unset_keys[name]
                    config_key = ConfigKey(name=name, value=value)
                    self.db_add_config_key(config_key)
            if name in self._subscribers:
                to_remove = []
                for subscriber in self._subscribers[name]:
                    obj = subscriber()
                    if obj:
                        obj(name, value)
                    else:
                        to_remove.append(obj)
                for ref in to_remove:
                    self._subscribers[name].remove(ref)

    def __eq__(self, other):
        if type(self) != type(other):
            return False
        seen_keys = set()
        for name in self.keys():
            if self.is_unset(name):
                continue
            seen_keys.add(name)
            if name not in other.keys():
                return False
            val1 = getattr(self, name)
            val2 = getattr(other, name)
            if type(val1) != type(val2):
                return False
            if val1 != val2:
                return False
        for name in other.keys():
            if other.is_unset(name):
                continue
            if name not in seen_keys:
                return False
        return True

    def __ne__(self, other):
        return not self.__eq__(other)

    def __contains__(self, k):
        return self.has(k)

    def __getitem__(self, k):
        return self.get(k)

    def __setitem__(self, k, v):
        return self.__setattr__(k, v)

    def update(self, other):
        for name, other_key in other.db_config_keys_name_index.iteritems():
            if (isinstance(other_key.value, ConfigurationObject) and
                    self.has(name)):
                self.get(name).update(other_key.value)
            else:
                self.__setattr__(name, other_key.value)

    def unsubscribe(self, field, callable_):
        """unsubscribe(field, callable_): remove observer from subject
        """
        self._subscribers[field].remove(weakref.ref(callable_))

    def subscribe(self, field, callable_):
        """subscribe(field, callable_): call observer callable_ when
        self.field is set.
        """
        append_to_dict_of_lists(self._subscribers, field,
                                Ref(callable_))

    def has(self, key):
        """has(key) -> bool.

        Returns true if key has valid value in the object.
        """

        return key in self.db_config_keys_name_index

    def get(self, key):
        if key in self._unset_keys:
            return self._unset_keys[key]
        config_key = self.db_config_keys_name_index[key]
        return config_key.value

    def is_unset(self, keys_str):
        keys = keys_str.split('.')
        config = self
        for key in keys[:-1]:
            config = config.get(key)
        return keys[-1] in config._unset_keys

    def get_deep_value(self, keys_str):
        # keys_str is something like "thmbs.cacheDir"
        keys = keys_str.split('.')
        config = self
        for key in keys:
            config = config.get(key)
        return config

    def has_deep_value(self, keys_str):
        # keys_str is something like "thmbs.cacheDir"
        keys = keys_str.split('.')
        config = self
        for key in keys:
            if config.has(key):
                config = config.get(key)
            else:
                return False
        return True

    def set_deep_value(self, keys_str, value, create_if_missing=False):
        keys = keys_str.split('.')
        config = self
        for key in keys[:-1]:
            if config.has(key):
                config = config.get(key)
            elif create_if_missing:
                new_config = ConfigurationObject()
                config.__setattr__(key, new_config)
                config = new_config
            else:
                raise ValueError('No path for key "%s"' % keys_str)
        config.__setattr__(keys[-1], value)

    def check(self, key):
        """check(key) -> obj

        Returns False if key is absent in object, and returns object
        otherwise.
        """

        return self.has(key) and getattr(self, key)

    def allkeys(self):
        """allkeys() -> list of strings

        Returns all options stored in this object.
        """

        return self.db_config_keys_name_index.keys() + self._unset_keys.keys()

    def keys(self):
        """keys(self) -> list of strings
        Returns all public options stored in this object.
        Public options are keys that do not start with a _
        """
        return [k for k in itertools.chain(self.db_config_keys_name_index,
                                           self._unset_keys)
                if not k.startswith('_')]

# def default():
#     """ default() -> ConfigurationObject
#     Returns the default configuration of VisTrails

#     """

#     base_dir = {
#         'abstractionsDirectory': os.path.join("$DOT_VISTRAILS",
#                                               "subworkflows"),
#         'alwaysShowDebugPopup': False,
#         'autoConnect': True,
#         'autosave': True,
#         'dataDirectory': (None, str),
#         'dbDefault': False,
# #        'debugSignals': False,
#         'defaultFileType':system.vistrails_default_file_type(),
#         'detachHistoryView': False,
#         'dotVistrails': system.default_dot_vistrails(),
#         'enablePackagesSilently': False,
#         'errorOnConnectionTypeerror': False,
#         'errorOnVariantTypeerror': True,
#         'executeWorkflows': False,
#         'fileDirectory': (None, str),
#         'fixedSpreadsheetCells': False,
# #        'evolutionGraph': (None, str),
#         'installBundles': True,
#         'installBundlesWithPip': False,
#         'interactiveMode': True,
#         'logFile': os.path.join("$DOT_VISTRAILS", "vistrails.log"),
#         'logger': default_logger(),
#         'maxMemory': (None, int),
#         'maximizeWindows': False,
#         'maxRecentVistrails': 5,
#         'migrateTags': False,
#         'minMemory': (None, int),
#         'multiHeads': False,
#         'nologger': False,
#         'packageDirectory': (None, str),
#         'pythonPrompt': False,
#         'recentVistrailList': (None, str),
#         'repositoryLocalPath': (None, str),
#         'repositoryHTTPURL': "http://www.vistrails.org/packages",
#         'reviewMode': False,
#         'rootDirectory': (None, str),
#         'runningJobsList': (None, str),
#         'shell': default_shell(),
#         'showScrollbars': True,
#         'showMovies': True,
#         'showSplash': True,
#         'showSpreadsheetOnly': False,
#         'singleInstance': True,
#         'spreadsheetDumpCells': (None, str),
#         'spreadsheetDumpPDF': False,
#         'staticRegistry': (None, str),
#         'stopOnError': True,
#         'temporaryDirectory': (None, str),
#         'thumbs': default_thumbs(),
#         'upgradeOn': True,
#         'upgradeDelay': True,
#         'upgradeModuleFailPrompt': True,
#         'useCache': True,
#         'userPackageDirectory': os.path.join("$DOT_VISTRAILS", "userpackages"),
#         'verbosenessLevel': (None, int),
# #        'workflowGraph': (None, str),
# #        'workflowInfo': (None, str),
#         'webRepositoryLogin': (None, str),
#         'webRepositoryURL': "http://www.crowdlabs.org",
#         'isInServerMode': False,
#         }
#     specific_dir = add_specific_config(base_dir)
#     return ConfigurationObject(**specific_dir)

# def default_logger():
#     """default_logger() -> ConfigurationObject
#     Returns the default configuration for the VisTrails logger

#     """
#     logger_dir = {
#         'dbHost': '',
#         'dbName': '',
#         'dbPasswd': '',
#         'dbPort': 0,
#         'dbUser': '',
#         }
#     return ConfigurationObject(**logger_dir)

# def default_shell():
#     """default_shell() -> ConfigurationObject
#     Returns the default configuration for the VisTrails shell
#
#     """
#     if system.systemType == 'Linux':
#         shell_dir = {
#             'font_face': 'Fixed',
#             'font_size': 12,
#             }
#     elif system.systemType in ['Windows', 'Microsoft']:
#         shell_dir = {
#             'font_face': 'Courier New',
#             'font_size': 8,
#             }
#     elif system.systemType == 'Darwin':
#         shell_dir = {
#             'font_face': 'Monaco',
#             'font_size': 12,
#             }
#     else:
#         raise VistrailsInternalError('system type not recognized')
#     return ConfigurationObject(**shell_dir)

# def default_thumbs():
#     """default_thumbs() -> ConfigurationObject
#     Returns the default configuration for VisTrails Pipelines Thumbnails
#     """
#     thumbs_dir = {
#                   'autoSave': True,
#                   'cacheDirectory': os.path.join("$DOT_VISTRAILS", "thumbs"),
#                   'cacheSize': 20,
#                   'mouseHover': False,
#                   'tagsOnly': False,
#                 }
#     return ConfigurationObject(**thumbs_dir)

def add_specific_config(base_dir):
    """add_specific_config() -> dict

    Returns a dict with other specific configuration to the current
    platform added to base_dir

    """
    newdir = dict(base_dir)
    if system.systemType == 'Darwin':
        newdir['useMacBrushedMetalStyle'] = True

    return newdir

def get_vistrails_persistent_configuration():
    """get_vistrails_persistent_configuration() -> ConfigurationObject or None
    Returns the persistent configuration of the application. It returns None if
    configuration was not found (when running as a bogus application
    for example.
    Notice that this function should be use only to write configurations to
    the user's startup.xml file. Otherwise, use get_vistrails_configuration  or
    get_vistrails_temp_configuration.

    """
    from vistrails.core.application import get_vistrails_application
    app = get_vistrails_application()
    if hasattr(app, 'configuration'):
        return app.configuration
    else:
        return None

def get_vistrails_temp_configuration():
    """get_vistrails_temp_configuration() -> ConfigurationObject or None
    Returns the temp configuration of the application. It returns None if
    configuration was not found (when running as a bogus application
    for example. The temp configuration is the one that is used just for the
    current session and is not persistent. To make changes persistent,
    use get_vistrails_persistent_configuration() instead.

    """
    from vistrails.core.application import get_vistrails_application
    app = get_vistrails_application()
    if hasattr(app, 'temp_configuration'):
        return app.temp_configuration
    else:
        return None

get_vistrails_configuration = get_vistrails_temp_configuration

import tempfile
import unittest

class TestConfiguration(unittest.TestCase):
    def test_config(self):
        conf = ConfigurationObject(a="blah", b=3.45, c=1, d=True)
        self.assertEqual(conf.a, "blah")
        self.assertAlmostEqual(conf.b, 3.45)
        self.assertEqual(conf.c, 1)
        self.assertEqual(conf.d, True)

    def test_default(self):
        conf = default()
        self.assertEqual(conf.showWindow, True)
        self.assertEqual(conf.maxRecentVistrails, 5)

    def test_has(self):
        conf = default()
        self.assertTrue(conf.has("showWindow"))
        self.assertFalse(conf.has("reallyDoesNotExist"))

    def test_check(self):
        conf = default()
        self.assertTrue(conf.check("showWindow"))
        self.assertFalse(conf.check("showDebugPopups"))
        self.assertFalse(conf.check("thumbs.mouseHover"))

    def test_update(self):
        conf1 = default()
        conf2 = ConfigurationObject(showDebugPopups=True,
                                    logDir="/tmp",
                                    thumbs=ConfigurationObject(
                                        autoSave=True,
                                        cacheDir="/tmp",
                                        cacheSize=10,
                                        mouseHover=True,
                                        tagsOnly=False))

        conf1.update(conf2)
        self.assertTrue(conf1.showDebugPopups)
        self.assertEqual(conf1.logDir, "/tmp")
        self.assertEqual(conf1.thumbs.mouseHover, True)

        conf2.showWindow = False
        self.assertTrue(conf1.showWindow)

    def test_unset_params(self):
        conf = ConfigurationObject(test_field=(None, str))
        self.assertTrue(conf.is_unset("test_field"))
        self.assertIn("test_field", conf.keys())

    def test_type_mismatch(self):
        conf = default()
        with self.assertRaises(TypeError):
            conf.showWindow = 1

        # allowing this now
        # with self.assertRaises(AttributeError):
        #     conf.reallyDoesNotExist = True

    def test_serialize(self):
        from vistrails.db.persistence import DAOList
        conf1 = default()
        (fd, fname) = tempfile.mkstemp()
        os.close(fd)
        try:
            dao = DAOList()
            dao.save_to_xml(conf1, fname, {})
            conf2 = dao.open_from_xml(fname, ConfigurationObject.vtType)
            ConfigurationObject.convert(conf2)
        finally:
            os.unlink(fname)

        self.assertEqual(conf1, conf2)

    def test_copy(self):
        conf1 = default()
        conf2 = copy.copy(conf1)
        self.assertEqual(conf1, conf2)
        self.assertItemsEqual(conf1._unset_keys.keys(),
                              conf2._unset_keys.keys())

    def test_parser(self):
        if sys.version_info < (2, 7):
            self.skipTest("argparse on Python 2.6: bug 10680")
        from vistrails.tests.utils import capture_stdout, capture_stderr
        p = build_command_line_parser(base_config)
        err = []
        try:
            with capture_stdout() as err:
                with self.assertRaises(SystemExit) as e:
                    p.parse_args(["-h"])
            self.assertEqual(e.exception.code, 0)
            self.assertGreater(len(err), 20)
        except:
            sys.stdout.write('\n'.join(err))
            raise
        try:
            with capture_stderr() as err:
                with self.assertRaises(SystemExit) as e:
                    p.parse_args(["--db-default", "--no-db-default"])
            self.assertEqual(e.exception.code, 2)
        except:
            sys.stderr.write('\n'.join(err))
            raise

    def test_parse_into_config(self):
        p = build_command_line_parser(base_config)
        config = default()
        self.assertFalse(config.dbDefault)
        p.parse_args(args=["--db-default", "--dot-vistrails", "/tmp"],
                     namespace=config)
        self.assertTrue(config.dbDefault)
        self.assertEqual(config.dotVistrails, "/tmp")

    def test_parse_output_settings(self):
        p = build_command_line_parser(base_config)
        config = default()
        p.parse_args(args=["-p", "file.series=false"],
                     namespace=config)
        self.assertTrue(config.outputSettings.has("file"))
        self.assertTrue(config.outputSettings.file.has("series"))
        self.assertEqual(config.outputSettings.file.series, "false")

    def test_multiple_params(self):
        p = build_command_line_parser(base_config)
        config = default()
        p.parse_args(args=["-p", "file.series=false",
                           "-p", "file.suffix=.png"],
                     namespace=config)
        self.assertTrue(config.outputSettings.has("file"))
        self.assertTrue(config.outputSettings.file.has("series"))
        self.assertTrue(config.outputSettings.file.has("suffix"))
        self.assertEqual(config.outputSettings.file.series, "false")
        self.assertEqual(config.outputSettings.file.suffix, ".png")

    def test_comma_sep_params(self):
        p = build_command_line_parser(base_config)
        config = default()
        p.parse_args(args=["-p", 'file.series=false,other.separator=","'],
                     namespace=config)
        self.assertTrue(config.outputSettings.has("file"))
        self.assertTrue(config.outputSettings.file.has("series"))
        self.assertEqual(config.outputSettings.file.series, "false")
        self.assertTrue(config.outputSettings.has("other"))
        self.assertTrue(config.outputSettings.other.has("separator"))
        self.assertEqual(config.outputSettings.other.separator, ",")

if __name__ == '__main__':
    unittest.main()


text:
'use strict';

describe('AdditivesController', function () {
  var rootScope, controller;
  var additivesMock, AdditivesController;

  beforeEach(function () {
    angular.mock.module('HranitelniDobavki', function ($provide) {
      $provide.value('additives', additivesMock = []);
    });

    inject(function () {
      additivesMock = [
        { 'additive': 'test1', 'slug': 'slug1' },
        { 'additive': 'test2', 'slug': 'slug2' },
        { 'additive': 'test3', 'slug': 'slug3' }
      ];
    });
  });

  beforeEach(angular.mock.inject(function ($rootScope, $controller) {
    rootScope = $rootScope.$new();
    controller = $controller;

    AdditivesController = $controller('AdditivesController as adtv', {
      $scope: rootScope,
      additives: additivesMock
    });

    rootScope.$digest();
  }));

  it('should exists', function () {
    expect(AdditivesController).toBeTruthy();
  });

  it('should contain all additives', function () {
    expect(rootScope.adtv.additives).toEqual([
      { 'additive': 'test1', 'slug': 'slug1' },
      { 'additive': 'test2', 'slug': 'slug2' },
      { 'additive': 'test3', 'slug': 'slug3' }
    ]);
  });

  it('group-description should be active tab', function () {
    expect(rootScope.adtv.currentTab).toBe('group-description');
    expect(rootScope.adtv.isActiveTab('group-description')).toBeTruthy();
  });

  it('should change active tab', function () {
    rootScope.adtv.currentTab = 'group-list';

    expect(rootScope.adtv.currentTab).toBe('group-list');
    expect(rootScope.adtv.isActiveTab('group-list')).toBeTruthy();
  });
});

redpajama_set_name: RedPajamaGithub


text:
namespace chainerx {

Array AMax(const Array& a, const OptionalAxes& axis, bool keepdims) {
    Axes sorted_axis = internal::GetSortedAxesOrAll(axis, a.ndim());
    Array out = internal::EmptyReduced(a.shape(), a.dtype(), sorted_axis, keepdims, a.device());

    for (int8_t i : sorted_axis) {
        if (a.shape()[i] == 0) {
            throw DimensionError{"cannot compute the maximum along zero-sized axis"};
        }
    }

    {
        NoBackpropModeScope scope{};
        a.device().backend().CallKernel<AMaxKernel>(a, sorted_axis, out);
    }

    BackwardBuilder bb{"amax", a, out};
    if (BackwardBuilder::Target bt = bb.CreateTarget(0)) {
        // a and out are used only for restoring the mask. We don't need graph nodes.
        bt.Define([sorted_axis, a = a.AsGradStopped(), out = out.AsGradStopped(), keepdims](BackwardContext& bctx) {
            const Array& gout = *bctx.output_grad();
            CHAINERX_ASSERT(std::is_sorted(sorted_axis.begin(), sorted_axis.end()));

            Array reshaped_gout{};
            Array reshaped_out{};
            if (keepdims) {
                reshaped_gout = gout;
                reshaped_out = out;
            } else {
                // Add broadcastable dimensions to out and gout
                // for each one that was reduced in the forward operation
                Shape shape = internal::ReduceShape(a.shape(), sorted_axis, true);
                reshaped_gout = gout.Reshape(shape);
                reshaped_out = out.Reshape(shape);
            }

            // Compute the gradient
            // TODO(sonots): Use `where` if it becomes available.
            Array cond = (a == reshaped_out).AsType(gout.dtype(), false);
            bctx.input_grad() = reshaped_gout * cond;
        });
    }
    bb.Finalize();
    return out;
}

Array AMin(const Array& a, const OptionalAxes& axis, bool keepdims) {
    Axes sorted_axis = internal::GetSortedAxesOrAll(axis, a.ndim());
    Array out = internal::EmptyReduced(a.shape(), a.dtype(), sorted_axis, keepdims, a.device());

    for (int8_t i : sorted_axis) {
        if (a.shape()[i] == 0) {
            throw DimensionError{"cannot compute the minimum along zero-sized axis"};
        }
    }

    {
        NoBackpropModeScope scope{};
        a.device().backend().CallKernel<AMinKernel>(a, sorted_axis, out);
    }

    BackwardBuilder bb{"amin", a, out};
    if (BackwardBuilder::Target bt = bb.CreateTarget(0)) {
        // a and out are used only for restoring the mask. We don't need graph nodes.
        bt.Define([sorted_axis, a = a.AsGradStopped(), out = out.AsGradStopped(), keepdims](BackwardContext& bctx) {
            const Array& gout = *bctx.output_grad();
            CHAINERX_ASSERT(std::is_sorted(sorted_axis.begin(), sorted_axis.end()));

            Array reshaped_gout{};
            Array reshaped_out{};
            if (keepdims) {
                reshaped_gout = gout;
                reshaped_out = out;
            } else {
                // Add broadcastable dimensions to out and gout
                // for each one that was reduced in the forward operation
                Shape shape = internal::ReduceShape(a.shape(), sorted_axis, true);
                reshaped_gout = gout.Reshape(shape);
                reshaped_out = out.Reshape(shape);
            }

            // Compute the gradient
            // TODO(sonots): Use `where` if it becomes available.
            Array cond = (a == reshaped_out).AsType(gout.dtype(), false);
            bctx.input_grad() = reshaped_gout * cond;
        });
    }
    bb.Finalize();
    return out;
}

Dtype PromoteInt2Float(Dtype dtype) { return GetKind(dtype) == DtypeKind::kFloat ? dtype : internal::GetDefaultDtype(DtypeKind::kFloat); }

Array Mean(const Array& a, const OptionalAxes& axis, bool keepdims) {
    Axes sorted_axis = internal::GetSortedAxesOrAll(axis, a.ndim());
    Dtype out_dtype = PromoteInt2Float(a.dtype());
    Array out = internal::EmptyReduced(a.shape(), out_dtype, sorted_axis, keepdims, a.device());
    Scalar n = internal::CountItemsAlongAxes(a.shape(), sorted_axis);

    {
        NoBackpropModeScope scope{};
        a.device().backend().CallKernel<SumKernel>(a, sorted_axis, out);
        a.device().backend().CallKernel<DivideASKernel>(out, n, out);
    }

    BackwardBuilder bb{"mean", a, out};
    if (BackwardBuilder::Target bt = bb.CreateTarget(0)) {
        bt.Define([n, sorted_axis, in_shape = a.shape(), keepdims](BackwardContext& bctx) {
            const Array& gout = *bctx.output_grad();
            CHAINERX_ASSERT(std::is_sorted(sorted_axis.begin(), sorted_axis.end()));

            if (!(in_shape.ndim() == 0 || sorted_axis.empty() || keepdims)) {
                Shape out_shape_broadcastable = gout.shape();
                for (auto axis : sorted_axis) {
                    out_shape_broadcastable.insert(out_shape_broadcastable.begin() + axis, 1);
                }
                bctx.input_grad() = gout.Reshape(out_shape_broadcastable).BroadcastTo(in_shape) / n;
            } else {
                bctx.input_grad() = gout.BroadcastTo(in_shape) / n;
            }
        });
    }
    bb.Finalize();

    return out;
}

Array Var(const Array& a, const OptionalAxes& axis, bool keepdims) {
    // TODO(hvy): Consider allowing device implementations.
    Axes sorted_axis = internal::GetSortedAxesOrAll(axis, a.ndim());
    Dtype mean_out = PromoteInt2Float(a.dtype());
    // TODO(kshitij12345): remove once subtract allows mixed types.
    Array diff = a.AsType(mean_out, true) - Mean(a, sorted_axis, true);
    return Mean(diff * diff, sorted_axis, keepdims);
}

}  // namespace chainerx


text:
"""
flypy passes that perform translation, type inference, code generation, etc.
"""

from __future__ import print_function, division, absolute_import
from functools import partial

from flypy.compiler.backend import lltyping, llvm, lowering, rewrite_lowlevel_constants
from flypy.compiler.frontend import (translate, simplify_exceptions, checker,
                                     setup, debugprint)
from flypy.compiler.backend import (lltyping, llvm, lowering,
                                     rewrite_lowlevel_constants)
from flypy.compiler.analysis import dependence_analysis
from flypy.compiler import simplification, transition
from flypy.compiler.typing import inference, typecheck
from flypy.compiler.typing.resolution import (resolve_context, resolve_restype)
from flypy.compiler.optimizations import (dataflow, optimize, inlining,
                                           throwing, deadblocks, reg2mem)
from flypy.compiler.lower import (rewrite_calls, rewrite_raise_exc_type,
                                   rewrite_getattr, rewrite_setattr,
                                   rewrite_unpacking, rewrite_varargs,
                                   rewrite_constructors, explicit_coercions,
                                   rewrite_optional_args, rewrite_constants,
                                   conversion, rewrite_obj_return, allocator,
                                   rewrite_externs, generators, void2none)
from flypy.viz.prettyprint import dump, dump_cfg, dump_llvm, dump_optimized

from pykit.transform import dce
#from pykit.optimizations import local_exceptions
from pykit.codegen.llvm import (verify, optimize as llvm_optimize,
                                llvm_postpasses)

#===------------------------------------------------------------------===
# Passes
#===------------------------------------------------------------------===

initialize = [
    setup,
]

frontend = [
    translate,
    simplify_exceptions,
    dump_cfg,
    debugprint,
    simplification.rewrite_ops,
    simplification.rewrite_overlays,
    deadblocks,
    dataflow,
    checker,
]

typing = [
    # flypy.compiler.typing.*
    transition.single_copy,
    inference,
    resolve_context,
    resolve_restype,
    debugprint.debugprint_typed,
    typecheck,
    # flypy.compiler.lower.*
    void2none,
    rewrite_getattr,
    rewrite_setattr,
    rewrite_calls,
    rewrite_unpacking,
    rewrite_varargs,
    rewrite_raise_exc_type,
    reg2mem,
]

generators = [
    generators.generator_fusion,             # generators
    #generators.rewrite_general_generators,  # generators

]

hl_lowering = [
    rewrite_constructors,                   # constructors
    allocator,                              # allocation
    rewrite_optional_args,
    explicit_coercions,
    conversion,
    rewrite_externs,
    rewrite_constants,
    rewrite_obj_return,
    dependence_analysis,
]

optimizations = [
    dce,
    dataflow.dataflow,
    optimize,
    dependence_analysis,
]

prelowering = [
    lltyping,
    dependence_analysis,
]

ll_lowering = [
    inlining,
    dataflow,
    throwing.rewrite_local_exceptions,
    rewrite_lowlevel_constants,
    #lowering.lower_fields,
    dependence_analysis,
]

backend_init = [
    throwing.rewrite_exceptions,
    llvm.codegen_init,
]

backend_run = [
    llvm.codegen_run,
    llvm_postpasses,
    llvm.codegen_link,
]

backend_finalize = [
    verify,
    dump_llvm,
    llvm_optimize,
    dump_optimized,
]

codegen = [
    llvm.get_ctypes,
]

dpp_backend_run = [
    llvm.codegen_run,
    # llvm_postpasses,  # for math
    #llvm.codegen_link, # do nothing
]

dpp_backend_finalize = [
    verify,
    dump_llvm,
]

all_passes = [
    frontend, typing, generators, hl_lowering, optimizations,
    prelowering,
    ll_lowering, backend_init, backend_run, backend_finalize,
    codegen, dpp_backend_run, dpp_backend_finalize,
]
passes = sum(all_passes, [])


text:
"use strict";

const gulp = require("gulp");
const path = require("path");
const glob = require("glob");
const del = require("del");
const vinylPaths = require("vinyl-paths");
const runSequence = require("run-sequence");
const buildHtml = require("./src/build-html");
const afterN = require("./src/utils").afterN;
const watch = require("gulp-watch");
const nodemon = require("gulp-nodemon");
const browserSync = require("browser-sync");
const webpack = require("webpack-stream");

gulp.task("default", cb => {
    runSequence(
            "clean",
            "transform-js",
            "build-html",
            cb);
});

gulp.task("transform-js", cb => {
    glob("tutorials/*", (err, files) => {
        const done = afterN(files.length, cb);
        files.forEach(dir => {
            let snippet = path.basename(dir);
            let index = path.join(dir, "index.js");
            gulp.src(index)
                .pipe(webpack({
                    output: {
                        filename: "index.js"
                    },
                    module: {
                        loaders: [
                            {
                                exclude: /node_modules/,
                                loader: "babel",
                                query: {
                                    presets: ["es2015"],
                                    plugins: ["transform-runtime"]
                                }
                            }
                        ]
                    }
                }))
                .pipe(gulp.dest(path.join("build/tutorials", snippet)))
                .on('end', done);
        });
    });
});

gulp.task("build-html", (cb) => {
    buildHtml(cb);
});

gulp.task("serve", () => {
   runSequence("default", "browser-sync");
   watch(['tutorials/**/*.js'], () => {
       runSequence("default", "reload-browser-sync");
   });
   watch(['web-assets/**/*.hbs'], () => {
       runSequence("build-html");
   });
});

gulp.task("reload-browser-sync", () => {
    browserSync.reload();
});

gulp.task("clean", () => {
    return gulp.src("build", {read: false})
        .pipe(vinylPaths(del));
});

gulp.task('nodemon', cb => {
	let called = false;
	return nodemon({script: 'src/server.js'}).on('start', () => {
		if (!called) {
			called = true;
			cb();
		}
	});
});

gulp.task('browser-sync', ["nodemon"], () => {
    browserSync.init(null, {
        proxy: "http://localhost:3000",
        port: 4000,
        files: ["web-assets/**/*.{js,css}", "build/public/index.html"]
    });
});

gulp.task("nodemon", cb => {
    var called = false;
    return nodemon({

        // nodemon our expressjs server
        script: "src/server.js",

        // watch core server file(s) that require server restart on change
        watch: ["src/*.js"]
    })
    .on("start", function onStart() {
        // ensure start only got called once
        if (!called) { cb(); }
        called = true;
    })
    .on("restart", function onRestart() {
        // reload connected browsers after a slight delay
        setTimeout(function reload() {
            browserSync.reload({
                stream: false
            });
        }, 500);
    });
});


text:
module Jaql
  module SqlGeneration
    # Allows for creation of fields from some column on some association, e.g. creator.last_name
    class AssociationFunctionField < AssociationField

      COUNT_FUNCTION = 'count'.freeze
      EXISTS_FUNCTION = 'exists'.freeze

      SUPPORTED_FUNCTIONS = [COUNT_FUNCTION, EXISTS_FUNCTION]
      def self.supports?(function_name)
        SUPPORTED_FUNCTIONS.include?(function_name.downcase)
      end

      attr_reader :function_name
      private :function_name

      def initialize(display_name, subquery, function_name)
        super(display_name, subquery)
        @function_name = function_name.to_s.downcase
      end

      private

      def comment_sql
        "-- #{last_association.name}.#{function_name} #{from_comment}"
      end

      def field_sql
        # Consider separate subclasses for AssociationCountField, AssociationExistsField, etc.
        case function_name
        when COUNT_FUNCTION
          "(SELECT COUNT(count_column) FROM (SELECT 1 AS count_column #{selection_sql}) #{quote('count_subquery')}) #{as_display_name_sql}"
        when EXISTS_FUNCTION
          "(SELECT EXISTS (SELECT * #{selection_sql(limit: 1)}) #{as_display_name_sql})"
        end
      end

      def allowed_client_scope_options
        # filter out ORDER, LIMIT and OFFSET since they don't jibe with COUNT and EXISTS
        # TODO consider selectively supporting ORDER, LIMIT and OFFSET if they make sense with other functions
        super - [ORDER_KEY, LIMIT_KEY, OFFSET_KEY]
      end

    end
  end
end


text:
<title>Phing API Documentation</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta><link rel="stylesheet" href="css/jquery-ui.css" type="text/css"></link><link rel="stylesheet" href="css/docblox/jquery-ui-1.8.16.custom.css" type="text/css"></link><link rel="stylesheet" href="css/jquery.treeview.css" type="text/css"></link><link rel="stylesheet" href="css/theme.css" type="text/css"></link>

system/io/InputStreamReader.php

              Show:
              inherited

                          Classes

\InputStreamReader

              Table of Contents

\InputStreamReader
jump to top

Package: phing\system\io
Writer class for OutputStream objects.

Unlike the Java counterpart, this class does not (yet) handle
character set transformations.  This will be an important function
of this class with move to supporting PHP6.

Parent(s)

\Reader

Children

\FileReader

Properties

\InputStream
                 $inStream= ''

Details

Type

\InputStream

Methods

__construct(
           $inStream
          )

        :
          void

Construct a new InputStreamReader.

Parameters

Name
Type
Description

$inStream

close(

          )

        :
          void

Close the stream.

eof(

          )

        :
          boolean

Whether eof has been reached with stream.

Returns

Type
Description

boolean

getResource(

          )

        :
          string

Returns string representation of attached stream.

Returns

Type
Description

string

mark(

          )

        :
          void

Marks the current position in this input stream.

Throws

Exception
Description

\IOException
- if the underlying stream doesn't support this method.

markSupported(

          )

        :
          boolean

Whether the attached stream supports mark/reset.

Returns

Type
Description

boolean

read(
          int $len
              =
              null
          )

        :
          string

Read data from file.

Parameters

Name
Type
Description

$len
int

Num chars to read.

Returns

Type
Description

string
chars read or -1 if eof.

readInto(
           $rBuffer
          )

        :
          TRUE

Reads a entire file and stores the data in the variable
passed by reference.

Parameters

Name
Type
Description

$rBuffer

Returns

Type
Description

TRUE
on success. Err object on failure.

Details

Author

Charlie Killian, charlie@tizac.com

Deprecated

Use read() or BufferedReader instead.

ready(

          )

        :
          void

reset(

          )

        :
          void

Repositions this stream to the position at the time the mark method was last called on this input stream.

Throws

Exception
Description

\IOException
- if the underlying stream doesn't support this method.

skip(
          int $n
          )

        :
          void

Skip over $n bytes.

Parameters

Name
Type
Description

$n
int

Documentation was generated by DocBlox 0.17.1.


text:
var reddit = require("./rss.js"), bot = require("./bot.js");
//this job cycles through three RSS feeds and gets a maximum of 10 items to display every morning
var rand = bot.random(3);
if(rand==1){
    reddit.rss_feed("https://www.reddit.com/r/worldnews+news/top.rss", "Good morning humans, WAKE UP! Fetching news from https://m.reddit.com/r/worldnews+news/top :", 10, function(str){
                    bot.postMessage(str);
                    });
}else if(rand==2){
    reddit.rss_feed("http://america.aljazeera.com/content/ajam/articles.rss", "Good morning humans, WAKE UP! Fetching news from http://america.aljazeera.com/ :", 10, function(str){
                    bot.postMessage(str);
                    });

}else{
    reddit.rss_feed("http://qz.com/popular/feed", "Good morning humans, WAKE UP! Fetching news from http://qz.com/popular :", 10, function(str){
                    bot.postMessage(str);
                    });

}


text:
[Renderers](../source/robosuite.renderers) are used to visualize the simulation, and can be used either in on-screen mode or headless (off-screen) mode. Renderers are also responsible for generating image-based observations that are returned from a given environment, and compute virtual images of the environment based on the properties defined in the cameras.

Currently, the following ground-truth vision modalities are supported across the three renderers, MjViewer, NVISII, and iGibson:

- **RGB**: Standard 3-channel color frames with values in range `[0, 255]`. This is set during environment construction with the `use_camera_obs` argument.
- **Depth**: 1-channel frame with normalized values in range `[0, 1]`. This is set during environment construction with the `camera_depths` argument.
- **Segmentation**: 1-channel frames with pixel values corresponding to integer IDs for various objects. Segmentation can
    occur by class, instance, or geom, and is set during environment construction with the `camera_segmentations` argument.

Additional modalities are supported by a subset of the renderers. In **robosuite**, the user has the following rendering options:

![Comparison of renderer options](../images/renderers/renderers.png "Comparison of renderer options")

## mujoco-py

MujocoRenderer is the default onscreen (MjViewer) and offscreen (MjRenderContextOffscreen) renderer supported by [mujoco-py](https://openai.github.io/mujoco-py/build/html/reference.html#mjviewer-3d-rendering). Based on [OpenGL](https://www.opengl.org/), our assets and environment definitions have been tuned to look good with this renderer.

## NVISII
NVISIIRenderer is a ray tracing-based renderer. It is primarily used for training perception models and visualizing results in high quality. Through [NVISII](https://github.com/owl-project/NVISII), we can obtain different vision modalities, including depth, segmentations, surface normals, texture coordinates, and texture positioning.

![NVISII renderer vision modalities](../images/renderers/vision_modalities_nvisii.png "NVISII renderer vision modalities")

### Using the NVISII renderer
Installing NVISII can be done using the command `pip install nvisii`. Note that NVISII requires users' drivers to be up to date. Please refer [here](https://github.com/owl-project/NVISII) for more information. You can try the NVISII renderer with the `demo_renderers.py` [script](../demos.html#rendering-options) and learn about the APIs for obtaining vision modalities with `demo_nvisii_modalities.py`.

## iGibson
iGibsonRenderer uses a [physically based rendering](https://en.wikipedia.org/wiki/Physically_based_rendering) (PBR), a computer graphics technique that seeks to render images in a way that models the flow of light in the real world. The original [iGibson](http://svl.stanford.edu/igibson/) environment combines fast visual rendering with physics simulation based on Bullet. We have created a version of robosuite that uses only the renderer of iGibson. This renderer supports faster image generation with optimization, and the generation of a variety of vision modalities like depth, surface normal, and segmentation. It is capable of rendering and returning [PyTorch tensors](https://pytorch.org/docs/stable/tensors.html), allowing for tensor-to-tensor rendering that reduces the tensor copying time between CPU and GPU accelerating substantially the process of training models for exampe with reinforcement learning.

![iGibson renderer vision modalities](../images/renderers/vision_modalities_igibson.png "iGibson renderer vision modalities")

### Using the iGibson Renderer
Installing iGibson can be done using the command `pip install igibson`. Please refer to the [iGibson installation guide](http://svl.stanford.edu/igibson/docs/installation.html) for a step by step guide. You can try the iGibson renderer with the `demo_renderers.py` [script](../demos.html#rendering-options) and learn about the APIs for obtaining vision modalities with `demo_igibson_modalities.py`.

### Requirements to use the iGibson Renderer

Using iGibson's PBR requires Linux or Windows machines; you can still use the iGibson renderer with macOS but it won't be PBR, it goes back to classic OpenGL rendering. Apart from that, the minimum system requirements are the following:

- Linux
  - Ubuntu 16.04
  - Nvidia GPU with VRAM > 6.0GB
  - Nvidia driver >= 384
  - CUDA >= 9.0, CuDNN >= v7
  - libegl-dev (Debian/Ubuntu: vendor neutral GL dispatch library – EGL support)
- Windows
  - Windows 10
  - Nvidia GPU with VRAM > 6.0GB
  - Nvidia driver >= 384
  - CUDA >= 9.0, CuDNN >= v7
- macOS
  - Tested on 10.15
  - PBR features not supported

**NOTE**: Since PBR is not supported on macOS, colors and textures will look flat. More realistic renderings can be obtained on Linux and Windows.

Other system configurations may work, but have not been extensively tested.

## PyGame

[PyGame](https://www.pygame.org/news) is a simple renderer that serves also as an alternative to MjViewer for rendering onscreen. A limitation of PyGame is that it can only render on-screen, limiting its applicability to train on computing clusters. This is because PyGame still relies on the MjRenderContextOffscreen to render frames offscreen, from which PyGame then maps to its native onscreen renderer. However, it is useful for visualizing the robots' behaviors in the system runtime where MjViewer is not supported. Check out this [demo script](../demos.html#pygame-renderer) for an example of using the PyGame renderer.

## Renderer Profiling
The following table shows the estimated frame rate of each renderer in frames per second (FPS). The profiling was conducted on a machine with Ubuntu 18.04, Intel Core i9-900K CPU@3.60GHz, and Nvidia RTX. The FPS numbers of each rendering option are reported below. These numbers are estimated on the Door environment with IIWA robot and Joint Velocity controller and 256x256 image size. In the table, R2T means render2tensor and R2N means render2numpy, which are two modes offered by the iGibson renderer.

|                   | mujoco-py | iGibson
(R2T optimized) | iGibson
(R2T) | iGibson
(R2N) | NVISII |
|-------------------|:---------:|:---------------------------------:|:-----------------------:|:----------------------:|:------:|
| Simulation + rendering | 62 | 64 | 58 | 45 | 0.5 |
| Rendering only         | 508 | 1392 | 285 | 271 | 0.5 |

For the same environment setup, we profiled the renderer on a machine with Ubuntu 18.04, Intel Core i7-8700K CPU@3.70GHz
and Nvidia GTX 1080ti.

|                   | mujoco-py | iGibson
(R2T optimized) | iGibson
(R2T) | iGibson
(R2N) | NVISII |
|-------------------|:---------:|:---------------------------------:|:-----------------------:|:----------------------:|:------:|
| Simulation + rendering | 65 | 62 | 45 | 41 | 0.4 |
| Rendering only         | 1000 | 1500 | 250 | 205 | 0.4 |

In practice, both mujoco-py and iGibson renderers are well-suited for vision-based policy learning. In comparison, iGibson offers a faster rendering speed and additional functionalities for perception research. You might also find that iGibson has better cross-platform compatibility than the generic mujoco-py renderer, but it requires iGibson as a dependency. NVISII is best suited for photorealistic rendering; however, the ray-tracing computation substantially slows down its rendering speed compared to the other two renderers. It is mainly intended for perception tasks and qualitative visualizations, rather than online policy training.


text:
SYNONYM

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
Symb. bot. 2:106. 1791

#### Original name
null

### Remarks
null


text:
@class PEUserSerializer;

@interface PELoginSerializer : HCHalJsonSerializerExtensionSupport

- (id)initWithMediaType:(HCMediaType *)mediaType
                charset:(HCCharset *)charset
         userSerializer:(PEUserSerializer *)userSerializer;

@end


text:
<?php

namespace PHPExiftool\Driver\Tag\DICOM;

use JMS\Serializer\Annotation\ExclusionPolicy;
use PHPExiftool\Driver\AbstractTag;

/**
 * @ExclusionPolicy("all")
 */
class ViewingDistance extends AbstractTag
{

    protected $Id = '0046,0106';

    protected $Name = 'ViewingDistance';

    protected $FullName = 'DICOM::Main';

    protected $GroupName = 'DICOM';

    protected $g0 = 'DICOM';

    protected $g1 = 'DICOM';

    protected $g2 = 'Image';

    protected $Type = '?';

    protected $Writable = false;

    protected $Description = 'Viewing Distance';

}


text:
<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">

  <title>pyglet.text.DocumentDecoder</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />

      Trees

      Indices

          pyglet . text . DocumentDecoder

        Toggle frames

Class pyglet.text.DocumentDecoder

Known Subclasses:

    formats.structured.StructuredTextDecoder,
    formats.plaintext.PlainTextDecoder,
    formats.attributed.AttributedTextDecoder

Abstract document decoder.

Methods

      AbstractDocument

        decode(self,
        text,
        location=None)

Decode document text.

Method Details

decode

    decode(self,
        text,
        location=None)

  Decode document text.

Parameters:

text : str

Text to decode

location : Location

Location to use as base path for additional resources
referenced within the document (for example, HTML images).

Returns: AbstractDocument

      Trees

      Indices

          pyglet . text . DocumentDecoder

        Toggle frames

    Generated by Epydoc 3.0beta1 on Thu Dec 31 17:58:19 2009

      http://epydoc.sourceforge.net


text:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aspose.imaging.examples.ManipulatingPNGImages;

import com.aspose.imaging.Image;
import com.aspose.imaging.examples.Logger;
import com.aspose.imaging.examples.Utils;
import com.aspose.imaging.imageoptions.JpegOptions;

/**
 * @author mfazi
 */
public class ReadLargePNGFile
{
    public static void main(String[] args)
    {
        Logger.startExample("ReadLargePNGFile");

        String dataDir = Utils.getSharedDataDir() + "ManipulatingPNGImages/";

        // load image with size more or equals to 500Mb
        try (Image image = Image.load(dataDir + "halfGigImage.png"))
        {
            // Create an instance of JpegOptions
            JpegOptions options = new JpegOptions();

            image.save(Utils.getOutDir() + "halfGigImage.jpg", options);
        }

        Logger.endExample();
    }
}


text:
import { ObjectUtility } from './../common/utils/object-util';
import { padEnd } from './../helpers/string/pad-end';

export function includePolyfill(): void {
  if (!ObjectUtility.get(String, 'prototype.padEnd')) {
    (String as any).prototype.padEnd = function(...args) {
      return padEnd(this, ...args);
    };
  }
}

includePolyfill();


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>
Uses of Class org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TITLE (hadoop-yarn-common 2.3.0 API)
</TITLE>

<META NAME="date" CONTENT="2015-03-06">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../../../stylesheet.css" TITLE="Style">

      Overview
      Package
      Class
    Use
      Tree
      Deprecated
      Index
      Help

 PREV
 NEXT

  FRAMES
 NO FRAMES

  All Classes

Uses of Class
org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TITLE

Packages that use Hamlet.TITLE

org.apache.hadoop.yarn.webapp.hamlet

Uses of Hamlet.TITLE in org.apache.hadoop.yarn.webapp.hamlet

Methods in org.apache.hadoop.yarn.webapp.hamlet that return Hamlet.TITLE

 Hamlet.TITLE<T>
Hamlet.TITLE._(Object... lines)

 Hamlet.TITLE<T>
Hamlet.TITLE._r(Object... lines)

 Hamlet.TITLE<T>
Hamlet.TITLE.$dir(HamletSpec.Dir value)

 Hamlet.TITLE<T>
Hamlet.TITLE.$lang(String value)

 Hamlet.TITLE<Hamlet>
Hamlet.title()

 Hamlet.TITLE<Hamlet.HTML<T>>
Hamlet.HTML.title()

 Hamlet.TITLE<Hamlet.HEAD<T>>
Hamlet.HEAD.title()

      Overview
      Package
      Class
    Use
      Tree
      Deprecated
      Index
      Help

 PREV
 NEXT

  FRAMES
 NO FRAMES

  All Classes

Copyright © 2015 Apache Software Foundation. All Rights Reserved.


text:
<?php  if ( ! defined('ROOT')) exit('Script access is forbidden');

	/*
	 * Inevy Dispersion -  main configuration file
	 *
	 * @version : 1.0
	 * @file    : application/config/config.php
	 *
	 * --------------------------------------------
	 */

	/** Configure database options
	 *
	 * driver   : only 'mysql' is available for now
	 * database : the database you want to use
	 * host     : the name of the host ( this is ussually 'localhost' )
	 * user     : the username to connect with
	 * password : password for the user
	 */
	Config::db( 'driver',       'mysql' );
	Config::db( 'database',     '' );
	Config::db( 'host',         '' );
	Config::db( 'user',         '' );
	Config::db( 'password',     '' );
	Config::db( 'table_prefix', '' );

	/** Set up the base url of your application
	 *
	 * @example
	 * Config::baseurl('http://localhost/')
	 *
	 *
	 * To add custom urls to your application as well
	 *
	 * @example
	 * Config::url( 'images', 'http://localhost/images');
	 */
	Config::baseurl('');

	/** Set the default timezone
	 *
	 * @example
	 * Config::timezone( 'America/Los_Angeles' )
	 */
	Config::timezone('America/Los_Angeles');

	/** The default controller to load if none is specified in the url.
	 *
	 * @example
	 * Load the 'home' controller.
	 * Config::autoload( 'defaultcontroller', 'home' );
	 */
	Config::autoload( 'defaultcontroller', 'home' );

	/** These are the standard view files to be loaded throughout your application. These view
	 * files can be eliminated for custom pages through the controller with $this->emptyView().
	 * The view files will be loaded in the order you set them. The custom locations where you
	 * can add your own files should be replaced by a number. All the numbers will be ignored
	 * when rendering the files.

	 * @example :
	 * Config::autoload( 'viewfiles', array(0, 'header', 1, 'footer') );
	 *
	 * The '0' represents the first place where you can add a file, for example you might use
	 * that to add the head of the page, and you can set the content in place of '1', depending
	 * on the page.
	 * @note Make sure the numbers you add are consecutive. Their order matters.
	 */
	Config::autoload( 'viewfiles', array( 0 ) );

	/** By default, the framework loads the model with the same name as the controller. To change
	 * that, you can map each controller to a model the way you want, or you can disable them by
	 * adding the controller name with an empty field after.
	 *
	 * @example
	 * This will load 'usermodel' for the 'users' controller
	 * Config::models( 'users' , 'usermodel' );
	 */
	Config::models( 'home', '' );

	/** The framework is set up to load a model for each controller. If you don't want to, or
	 * you don't like having empty models, you can disable them in 2 ways. First is adding them
	 * to the list of models above, with an empty string as their value, but to make things
	 * more organised and easier to read, you can just add them to the list below.
	 *
	 * @example
	 * Config::models( 'home', '' );
	 *
	 * @example
	 * Config::disablemodels( array( 'users' ) );
	 */
	Config::disablemodels( array() );

	/** The libraries to be loaded throughout your application. These can be both the libraries
	 * provided by the framework and the libraries added by you in your application/libraries
	 * directory.
	 *
	 * @note The libraries you will want to autoload must have a no-argument constructor.
	 *
	 * @example :
	 * Config::autoload( 'libraries', array('session') )
	 *
	 * If you will be using sessions within your application, you can just add the session
	 * library like above, and you will be able to access it anywhere with $this->session.
	 */
	Config::autoload('libraries', array() );

	/** Configure routes. The standard way the framework handles a route is
	 * /controller/action/parameter1/parameter2/parameter3
	 *
	 * You can change that by adding new routes to the config class. A route is added by
	 * specifying a string to match the url in the browser, and an array of strings containing
	 * the controller, action, and parameters to activate when the matched url is found. You can
	 * use the symbol '[*]' to match any number of parameters in the url.
	 *
	 * @example
	 * This will match routes like 'home/photos/albums', 'home/music/categories' and send it to
	 * 'mycollections' controller, 'get' method, with parameters 'photos', 'albums' or 'music',
	 * 'categories'
	 * Config::addRoute( 'home/[*]', array('mycollections', 'get', '[*] ) );
	 *
	 * You can also limit the number of parameters
	 *
	 * @example
	 * Minimum 2
	 * Config::addRoute( 'home/[*>2]', array('mycollections', 'get', '[*] ) );
	 *
	 * @example
	 * Maximum 2
	 * Config::addRoute( 'home/[*<2]', array('mycollections', 'get', '[*] ) );
	 *
	 * @example
	 * Exactly 2
	 * Config::addRoute( 'home/[*2]', array('mycollections', 'get', '[*] ) );
	 *
	 * @example
	 * Between 2 and 5
	 * Config::addRoute( 'home/[*>2]/[*<5]', array('mycollections', 'get', '[*] ) );
	 *
	 * For a full documentation on adding routes check the documentation online at the
	 * configuration section.
	 */


text:
require "jsduck/tag/tag"
require "jsduck/util/html"

module JsDuck::Tag
  # There is no @default tag.
  #
  # Default values are detected from syntax like this:
  #
  #     @cfg [blah=somedefault]
  #
  # This tag class exists to generate the "Defaults to:" text in final
  # HTML.
  class Default < Tag
    def initialize
      @tagname = :default
      @html_position = POS_DEFAULT
    end

    def to_html(m)
      return if m[:default] == "undefined"

      "
Defaults to: " + JsDuck::Util::HTML.escape(m[:default]) + "
"
    end
  end
end