<commit_before>from os.path import dirname

from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill
from mycroft.util.log import getLogger

from urllib2 import urlopen
import paho.mqtt.client as mqtt

__author__ = 'jamiehoward430'

LOGGER = getLogger(__name__)

class mymqttskill(MycroftSkill):

    def __init__(self):
        super(mymqttskill, self).__init__(name="mymqttskill")

        self.protocol = self.config["protocol"]
	self.mqtthost = self.config["mqtt-host"]
	self.mqttport = self.config["mqtt-port"]
	self.mqttauth = self.config["mqtt-auth"]
	self.mqttuser = self.config["mqtt-user"]
	self.mqttpass = self.config["mqtt-pass"]

    def initialize(self):
        self.load_data_files(dirname(__file__))
        self. __build_single_command()

    def __build_single_command(self):
        intent = IntentBuilder("mymqttIntent").require("CommandKeyword").require("ModuleKeyword").require("ActionKeyword").build()
        self.register_intent(intent, self.handle_single_command)

    def handle_single_command(self, message):
        cmd_name = message.data.get("CommandKeyword")
        mdl_name = message.data.get("ModuleKeyword")
        act_name = message.data.get("ActionKeyword")
        dev_name = mdl_name.replace(' ', '_')

        if act_name:
            cmd_name += '_' + act_name

        if (self.protocol == "mqtt"):
	    mqttc = mqtt.Client("MycroftAI")
	    if (self.mqttauth == "yes"):
	        mqttc.username_pw_set(self.mqttuser,self.mqttpass)
            mqttc.connect(self.mqtthost,self.mqttport)
	    mqttc.publish("/mycroft/" + cmd_name + "/" + dev_name + "/" + act_name, act_name)
	    mqttc.disconnect()
	    self.speak_dialog("cmd.sent")
            LOGGER.info(dev_name + "-" + cmd_name)

	else:
            self.speak_dialog("not.found", {"command": cmd_name, "action": act_name, "module": dev_name})
            LOGGER.error("Error: {0}".format(e))

    def stop(self):
        pass

def create_skill():
    return mymqttskill()
<commit_msg>Added SSL\TLS support<commit_after>from os.path import dirname

from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill
from mycroft.util.log import getLogger

from urllib2 import urlopen
import paho.mqtt.client as mqtt

__author__ = 'jamiehoward430'

LOGGER = getLogger(__name__)

class mymqttskill(MycroftSkill):

    def __init__(self):
        super(mymqttskill, self).__init__(name="mymqttskill")

        self.protocol = self.config["protocol"]
	self.mqttssl = self.config["mqtt-ssl"]
	self.mqttca = self.config["mqtt-ca-cert"]
	self.mqtthost = self.config["mqtt-host"]
	self.mqttport = self.config["mqtt-port"]
	self.mqttauth = self.config["mqtt-auth"]
	self.mqttuser = self.config["mqtt-user"]
	self.mqttpass = self.config["mqtt-pass"]

    def initialize(self):
        self.load_data_files(dirname(__file__))
        self. __build_single_command()

    def __build_single_command(self):
        intent = IntentBuilder("mymqttIntent").require("CommandKeyword").require("ModuleKeyword").require("ActionKeyword").build()
        self.register_intent(intent, self.handle_single_command)

    def handle_single_command(self, message):
        cmd_name = message.data.get("CommandKeyword")
        mdl_name = message.data.get("ModuleKeyword")
        act_name = message.data.get("ActionKeyword")
        dev_name = mdl_name.replace(' ', '_')

        if act_name:
            cmd_name += '_' + act_name

        if (self.protocol == "mqtt"):
	    mqttc = mqtt.Client("MycroftAI")
	    if (self.mqttauth == "yes"):
	        mqttc.username_pw_set(self.mqttuser,self.mqttpass)
	    if (self.mqttssl == "yes"):
		mqttc.tls_set(self.mqttca) #/etc/ssl/certs/ca-certificates.crt
            mqttc.connect(self.mqtthost,self.mqttport)
	    mqttc.publish("/mycroft/" + cmd_name + "/" + dev_name + "/" + act_name, act_name)
	    mqttc.disconnect()
	    self.speak_dialog("cmd.sent")
            LOGGER.info(dev_name + "-" + cmd_name)

	else:
            self.speak_dialog("not.found", {"command": cmd_name, "action": act_name, "module": dev_name})
            LOGGER.error("Error: {0}".format(e))

    def stop(self):
        pass

def create_skill():
    return mymqttskill()
<|endoftext|>


<commit_before>#!/usr/bin/python

from OpenSSL import SSL
from flask import Flask, request, jsonify, make_response, abort
from flask_sslify import SSLify
import re, yaml, os.path

config = 'config.yaml'
yamldir = 'data/'
common = yamldir + 'common.yaml'

config_yaml = yaml.load(file('config.yaml', 'r'))
context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file(config_yaml['key'])
context.use_certificate_file(config_yaml['cert'])

app = Flask(__name__, static_url_path = "")
sslify = SSLify(app, subdomains=True)

@app.errorhandler(404)
def not_found(error):
    return make_response(jsonify({"error": "Unknown Endpoint, try '/metadata/common'"}), 404)

@app.errorhandler(400)
def bad_request(error):
    return make_response(jsonify({"error": "Unknown Environment, Missing YAML File"}), 400)

@app.route('/metadata/common', methods=["GET"])
def common_metadata():
    if os.path.isfile(common):
        return str(yaml.load(file(common, 'r'))).replace(',', ',\n').replace('{', ' ').replace('}', '\n')
    else:
        abort(400)

@app.route('/metadata/env', methods=["GET"])
def all_metadata():
    ipaddy = re.match(r'(\d+\.\d+)',request.remote_addr).groups()[0]
    yamlconfig = yamldir + ipaddy + '.yaml'
    if os.path.isfile(yamlconfig):
        return str(yaml.load(file(yamlconfig, 'r'))).replace(',', ',\n').replace('{', ' ').replace('}', '\n')
    else:
        abort(400)

@app.route('/metadata/<string:metadata>', methods=["GET"])
def get_metadata(metadata):
    ipaddy = re.match(r'(\d+\.\d+)',request.remote_addr).groups()[0]
    yamlconfig = yamldir + ipaddy + '.yaml'
    if os.path.isfile(yamlconfig) and metadata in open(yamlconfig).read():
        allmetadata = yaml.load(file(yamlconfig, 'r'))
        return(str(allmetadata[metadata]))
    if os.path.isfile(common) and metadata in open(common).read():
        allmetadata = yaml.load(file(common, 'r'))
        return(str(allmetadata[metadata]))
    else:
        abort(404)

if __name__ == '__main__':
    app.run(host = "0.0.0.0", port = config_yaml['port'], debug = False, ssl_context=context)
<commit_msg>Added API reference docs and optional SSL support<commit_after>#!/usr/bin/python

from OpenSSL import SSL
from flask import Flask, request, jsonify, make_response, abort
from flask_sslify import SSLify
import re, yaml, os.path

config = 'config.yaml'
yamldir = 'data/'
common = yamldir + 'common.yaml'

config_yaml = yaml.load(file('config.yaml', 'r'))
if config_yaml['key']:
   context = SSL.Context(SSL.SSLv23_METHOD)
   context.use_privatekey_file(config_yaml['key'])
   context.use_certificate_file(config_yaml['cert'])
   app = Flask(__name__, static_url_path = "")
   sslify = SSLify(app, subdomains=True)
else:
   app = Flask(__name__, static_url_path = "")

@app.errorhandler(404)
def not_found(error):
    return make_response(jsonify({"error": "Unknown Endpoint, try '/metadata/common'"}), 404)

@app.errorhandler(400)
def bad_request(error):
    return make_response(jsonify({"error": "Unknown Environment, Missing YAML File"}), 400)

@app.route('/', methods = ['GET'])
def api_doc():
    """API Endpoint Reference"""
    func_list = {}
    for rule in app.url_map.iter_rules():
        if rule.endpoint != 'static':
            func_list[rule.rule] = app.view_functions[rule.endpoint].__doc__
    return jsonify(func_list)

@app.route('/metadata/common', methods=["GET"])
def common_metadata():
    """Common Data for All Environments Defined"""
    if os.path.isfile(common):
        return str(yaml.load(file(common, 'r'))).replace(',', ',\n').replace('{', ' ').replace('}', '\n')
    else:
        abort(400)

@app.route('/metadata/env', methods=["GET"])
def all_metadata():
    """All Environment Data Defined By Incoming Request"""
    ipaddy = re.match(r'(\d+\.\d+)',request.remote_addr).groups()[0]
    yamlconfig = yamldir + ipaddy + '.yaml'
    if os.path.isfile(yamlconfig):
        return str(yaml.load(file(yamlconfig, 'r'))).replace(',', ',\n').replace('{', ' ').replace('}', '\n')
    else:
        abort(400)

@app.route('/metadata/<string:metadata>', methods=["GET"])
def get_metadata(metadata):
    """Requested Key Data by Defined Environment"""
    ipaddy = re.match(r'(\d+\.\d+)',request.remote_addr).groups()[0]
    yamlconfig = yamldir + ipaddy + '.yaml'
    if os.path.isfile(yamlconfig) and metadata in open(yamlconfig).read():
        allmetadata = yaml.load(file(yamlconfig, 'r'))
        return(str(allmetadata[metadata]))
    if os.path.isfile(common) and metadata in open(common).read():
        allmetadata = yaml.load(file(common, 'r'))
        return(str(allmetadata[metadata]))
    else:
        abort(404)

if __name__ == '__main__':
    if config_yaml['key']:
    	app.run(host = "0.0.0.0", port = config_yaml['port'], debug = False, ssl_context=context)
    else:
	app.run(host = "0.0.0.0", port = config_yaml['port'], debug = False)
<|endoftext|>


<commit_before>from django.utils.functional import lazy
from django.core.urlresolvers import reverse

# Workaround for using reverse with success_url in class based generic views
# because direct usage of it throws an exception.
reverse_lazy = lambda name=None, *args : lazy(reverse, str)(name, args=args)
<commit_msg>Added a resolve_class helper function for getting a class object based on absolute classpath<commit_after>from django.utils.functional import lazy
from django.core.urlresolvers import reverse

# Workaround for using reverse with success_url in class based generic views
# because direct usage of it throws an exception.
reverse_lazy = lambda name=None, *args : lazy(reverse, str)(name, args=args)

def resolve_class(class_path):
    """
    Load a class by a fully qualified class_path,
    eg. myapp.models.ModelName
    """
    modulepath, classname = class_path.rsplit('.', 1)
    module = __import__(modulepath, fromlist=[classname])
    return getattr(module, classname)
<|endoftext|>


<commit_before>"""EcoData Retriever Wizard

Running this module directly will launch the download wizard, allowing the user
to choose from all scripts.

The main() function can be used for bootstrapping.

"""
from __future__ import print_function
from __future__ import absolute_import
from builtins import str
from imp import reload
import os
import platform
import sys
# sys removes the setdefaultencoding method at startup; reload to get it back
reload(sys)
if hasattr(sys, 'setdefaultencoding'):
    # set default encoding to latin-1 to decode source text
    sys.setdefaultencoding('latin-1')
from retriever import VERSION, MASTER, SCRIPT_LIST, sample_script, current_platform
from retriever.engines import engine_list
from retriever.lib.repository import check_for_updates
from retriever.lib.lists import Category, get_lists
from retriever.lib.tools import choose_engine, name_matches, reset_retriever
from retriever.lib.get_opts import parser

def main():
    """This function launches the EcoData Retriever."""
    if len(sys.argv) == 1:
        # if no command line args are passed, show the help options
        parser.parse_args(['-h'])

    else:
        # otherwise, parse them

        script_list = SCRIPT_LIST()

        args = parser.parse_args()
        if args.quiet:
            sys.stdout = open(os.devnull, 'w')

        if args.command == 'help':
            parser.parse_args(['-h'])

        if hasattr(args, 'compile') and args.compile:
            script_list = SCRIPT_LIST(force_compile=True)

        if args.command == 'update':
            check_for_updates()
            script_list = SCRIPT_LIST()
            return

        elif args.command == 'citation':
            if args.dataset is None:
                citation_path = os.path.join(os.path.split(__file__)[0], '../CITATION')
                print("\nCitation for retriever:\n")
                with open(citation_path) as citation_file:
                    print(citation_file.read())
            else:
                scripts = name_matches(script_list, args.dataset)
                for dataset in scripts:
                    print("\nDataset:  {}".format(dataset.name))
                    print("Citation:   {}".format(dataset.citation))
                    print("Description:   {}\n".format(dataset.description))

            return

        elif args.command == 'new':
            f = open(args.filename, 'w')
            f.write(sample_script)
            f.close()

            return

        elif args.command == 'reset':
            reset_retriever(args.scope)
            return

        if args.command == 'ls' or args.dataset is None:

            # If scripts have never been downloaded there is nothing to list
            if not script_list:
                print("No scripts are currently available. Updating scripts now...")
                check_for_updates()
                print("\n\nScripts downloaded.\n")
                script_list = SCRIPT_LIST()

            all_scripts = []

            for script in script_list:
                if script.name:
                    if args.l!=None:
                        script_name = script.name + "\nShortname: " + script.shortname+"\n"
                        if script.tags:
                            script_name += "Tags: "+str([tag for tag in script.tags])+"\n"
                        not_found = 0
                        for term in args.l:
                            if script_name.lower().find(term.lower()) == -1:
                                not_found = 1
                                break
                        if not_found == 0:
                            all_scripts.append(script_name)
                    else:
                        script_name = script.shortname
                        all_scripts.append(script_name)

            all_scripts = sorted(all_scripts, key=lambda s: s.lower())

            print("Available datasets : {}\n".format(len(all_scripts)))

            if args.l==None:
                from retriever import lscolumns
                lscolumns.printls(sorted(all_scripts, key=lambda s: s.lower()))
            else:
                count = 1
                for script in all_scripts:
                    print ("%d. %s"%(count, script))
                    count += 1
            return

        engine = choose_engine(args.__dict__)

        if hasattr(args, 'debug') and args.debug:
            debug = True
        else:
            debug = False

        scripts = name_matches(script_list, args.dataset)
        if scripts:
            for dataset in scripts:
                print("=> Installing", dataset.name)
                try:
                    dataset.download(engine, debug=debug)
                    dataset.engine.final_cleanup()
                except KeyboardInterrupt:
                    pass
                except Exception as e:
                    print(e)
                    if debug: raise
            print("Done!")
        else:
            print("The dataset {} isn't currently available in the Retriever".format(args.dataset))
            print("Run 'retriever ls to see a list of currently available datasets")

if __name__ == "__main__":
    main()
<commit_msg>Correct behavior when empty dataset is specified<commit_after>"""EcoData Retriever Wizard

Running this module directly will launch the download wizard, allowing the user
to choose from all scripts.

The main() function can be used for bootstrapping.

"""
from __future__ import print_function
from __future__ import absolute_import
from builtins import str
from imp import reload
import os
import platform
import sys
# sys removes the setdefaultencoding method at startup; reload to get it back
reload(sys)
if hasattr(sys, 'setdefaultencoding'):
    # set default encoding to latin-1 to decode source text
    sys.setdefaultencoding('latin-1')
from retriever import VERSION, MASTER, SCRIPT_LIST, sample_script, current_platform
from retriever.engines import engine_list
from retriever.lib.repository import check_for_updates
from retriever.lib.lists import Category, get_lists
from retriever.lib.tools import choose_engine, name_matches, reset_retriever
from retriever.lib.get_opts import parser

def main():
    """This function launches the EcoData Retriever."""
    if len(sys.argv) == 1:
        # if no command line args are passed, show the help options
        parser.parse_args(['-h'])

    else:
        # otherwise, parse them

        script_list = SCRIPT_LIST()

        args = parser.parse_args()

        if args.quiet:
            sys.stdout = open(os.devnull, 'w')

        if args.command == 'help':
            parser.parse_args(['-h'])

        if hasattr(args, 'compile') and args.compile:
            script_list = SCRIPT_LIST(force_compile=True)

        if args.command == 'update':
            check_for_updates()
            script_list = SCRIPT_LIST()
            return

        elif args.command == 'citation':
            if args.dataset is None:
                citation_path = os.path.join(os.path.split(__file__)[0], '../CITATION')
                print("\nCitation for retriever:\n")
                with open(citation_path) as citation_file:
                    print(citation_file.read())
            else:
                scripts = name_matches(script_list, args.dataset)
                for dataset in scripts:
                    print("\nDataset:  {}".format(dataset.name))
                    print("Citation:   {}".format(dataset.citation))
                    print("Description:   {}\n".format(dataset.description))

            return

        elif args.command == 'new':
            f = open(args.filename, 'w')
            f.write(sample_script)
            f.close()

            return

        elif args.command == 'reset':
            reset_retriever(args.scope)
            return

        if args.command == 'ls':

            # If scripts have never been downloaded there is nothing to list
            if not script_list:
                print("No scripts are currently available. Updating scripts now...")
                check_for_updates()
                print("\n\nScripts downloaded.\n")
                script_list = SCRIPT_LIST()

            all_scripts = []

            for script in script_list:
                if script.name:
                    if args.l is not None:
                        script_name = script.name + "\nShortname: " + script.shortname+"\n"
                        if script.tags:
                            script_name += "Tags: "+str([tag for tag in script.tags])+"\n"
                        not_found = 0
                        for term in args.l:
                            if script_name.lower().find(term.lower()) == -1:
                                not_found = 1
                                break
                        if not_found == 0:
                            all_scripts.append(script_name)
                    else:
                        script_name = script.shortname
                        all_scripts.append(script_name)

            all_scripts = sorted(all_scripts, key=lambda s: s.lower())

            print("Available datasets : {}\n".format(len(all_scripts)))

            if args.l is None:
                from retriever import lscolumns
                lscolumns.printls(sorted(all_scripts, key=lambda s: s.lower()))
            else:
                count = 1
                for script in all_scripts:
                    print ("%d. %s"%(count, script))
                    count += 1
            return

        engine = choose_engine(args.__dict__)

        if hasattr(args, 'debug') and args.debug:
            debug = True
        else:
            debug = False
            sys.tracebacklimit = 0

        if args.dataset is not None:
            scripts = name_matches(script_list, args.dataset)
        else:
            raise Exception("no dataset specified.")
        if scripts:
            for dataset in scripts:
                print("=> Installing", dataset.name)
                try:
                    dataset.download(engine, debug=debug)
                    dataset.engine.final_cleanup()
                except KeyboardInterrupt:
                    pass
                except Exception as e:
                    print(e)
                    if debug: raise
            print("Done!")
        else:
            print("The dataset {} isn't currently available in the Retriever".format(args.dataset))
            print("Run 'retriever ls to see a list of currently available datasets")

if __name__ == "__main__":
    main()
<|endoftext|>


<commit_before>"""
Generate semantically interoperable genome annotations from GFF[1] files according to the RDF[2] specification.

References:
[1] Generic Feature Format specification, http://www.sequenceontology.org/gff3.shtml
[2] Resource Description Framework, https://www.w3.org/TR/rdf11-concepts/

Usage:
  siga.py -h | --help
  siga.py -v | --version
  siga.py [ -d DB_FILE | -e DB_FILE_EXT ] [ -o FORMAT ] GFF_FILE...

Arguments:
  GFF_FILE...      Input file(s) in GFF (versions 2/3).

Options:
  -h, --help
  -v, --version
  -d DB_FILE       Populate GFF database(s) in SQLite.
  -e DB_FILE_EXT   Database file extension [default: .db].
  -o FORMAT        Select RDF serialization/format [default: turtle].

"""

from __future__ import print_function
from docopt import docopt

import os
import gffutils as gff
import sqlite3 as sql

__author__  = 'Arnold Kuzniar'
__version__ = 0.1
__status__  = 'Prototype'
__license__ = 'Apache License, Version 2.0'

if __name__ == '__main__':
    args = docopt(__doc__, version=__version__)
    #print(args)

    def normalize_filext(s):
        dot = '.'
        if s.startswith(dot) is False:
            s = dot + s
        return s

    #def print_all_features(db):
    #    for ft in db.all_features():
    #        print(ft)

    for gff_file in args['GFF_FILE']:
        if args['-d']:
            # populate a single db from all GFF files
            db_file = args['-d']
            if os.path.exists(db_file):
                db = gff.FeatureDB(db_file)
                db.update(gff_file)
            else:
                db = gff.create_db(gff_file, db_file, force=False)
        else:
            # populate one db per GFF file
            base_name = os.path.splitext(gff_file)[0]
            db_file = base_name + normalize_filext(args['-e'])
            try:
                db = gff.create_db(gff_file, db_file, force=False)
                #print_all_features(db)
            except sql.OperationalError:
                raise IOError("Database file '%s' already exists." % db_file)
            except ValueError:
                raise IOError("GFF file '%s' not found." % gff_file)
<commit_msg>Add -V|--verbose option for debugging.<commit_after>"""
Generate semantically interoperable genome annotations from GFF[1] files according to the RDF[2] specification.

References:
[1] Generic Feature Format specification, http://www.sequenceontology.org/gff3.shtml
[2] Resource Description Framework, https://www.w3.org/TR/rdf11-concepts/

Usage:
  siga.py -h | --help
  siga.py -v | --version
  siga.py [-V ] [ -d DB_FILE | -e DB_FILE_EXT ] [ -o FORMAT ] GFF_FILE...

Arguments:
  GFF_FILE...      Input file(s) in GFF (versions 2/3).

Options:
  -h, --help
  -v, --version
  -V, --verbose    Use for debugging.
  -d DB_FILE       Populate GFF database(s) in SQLite.
  -e DB_FILE_EXT   Database file extension. [default: .db].
  -o FORMAT        Select RDF serialization/format. [default: turtle]

"""

from __future__ import print_function
from docopt import docopt

import os
import gffutils as gff
import sqlite3 as sql

__author__  = 'Arnold Kuzniar'
__version__ = 0.1
__status__  = 'Prototype'
__license__ = 'Apache License, Version 2.0'

if __name__ == '__main__':
    args = docopt(__doc__, version=__version__)
    #print(args)

    def normalize_filext(s):
        dot = '.'
        if s.startswith(dot) is False:
            s = dot + s
        return s

    #def print_all_features(db):
    #    for ft in db.all_features():
    #        print(ft)

    for gff_file in args['GFF_FILE']:
        if args['-d']:
            # populate a single db from all GFF files
            db_file = args['-d']
            if os.path.exists(db_file):
                db = gff.FeatureDB(db_file)
                db.update(gff_file)
            else:
                db = gff.create_db(gff_file, db_file, force=False)
        else:
            # populate one db per GFF file
            base_name = os.path.splitext(gff_file)[0]
            db_file = base_name + normalize_filext(args['-e'])
            try:
                db = gff.create_db(gff_file, db_file, verbose=args['--verbose'], force=False)
                #print_all_features(db)
            except sql.OperationalError:
                raise IOError("Database file '%s' already exists." % db_file)
            except ValueError:
                raise IOError("GFF file '%s' not found." % gff_file)
<|endoftext|>


<commit_before>"""

License: http://www.stsci.edu/resources/software_hardware/pyraf/LICENSE

"""
from __future__ import absolute_import, division, generators # confidence medium

from . import numerixenv
numerixenv.check()

import numpy as N

BUFSIZE = 1024*1000   # 1Mb cache size

__version__ = '0.2'

def ImageIter(imgarr, bufsize=None, overlap=0, copy=0):

    imgarr = N.asarray(imgarr)

    if bufsize is None:
        bufsize = BUFSIZE

    if len(imgarr.shape) == 1:
        if copy:
            yield imgarr.copy()
        else:
            yield imgarr

    else:
        nrows = int(bufsize / (imgarr.itemsize * imgarr.shape[1]))
        niter = int(imgarr.shape[0] / nrows) * nrows

        if copy:
            # Create a cache that will contain a copy of the input
            # not just a view...
            _cache = N.zeros((nrows, imgarr.shape[1]), dtype=imgarr.dtype.char)

        for pix in range(0, niter+1, nrows):
            if copy:
                _cache = imgarr[pix:pix+nrows].copy()
                yield _cache
            else:
                yield imgarr[pix:pix+nrows]

            if copy:
                _cache *= 0

            pix -= overlap

<commit_msg>Remove nimageiter module<commit_after><|endoftext|>


<commit_before>#!/usr/bin/env python

'''Read and access cell lineage data from Simi BioCell.

Small library to parse Simi*BioCell project files (.sbc and .sbd). It collects
all the relevant cell lineage data such as cell name, frame and coordinates,
and provides a programmatic interface to access the data. In this manner the
data can be analyzed by custom functions, or exported to different formats for
data analyses in more up-to-date cell lineage software.

Usage:

    # Load library.
    import simi

    # Parse a Simi BioCell .sbd file.
    s = simi.Sbd('lineage.sbd')

    # Access all cells.
    s.cells
    [<cell1>, <cell2>, <cell3>]

    # Access cell data.
    cell = s.cells[0]
    cell.generic_name
    '1b1'

    cell.frame
    198

    cell.spots
    [<spot1>, <spot2>, <spot3>]

'''

from collections import OrderedDict
from os.path import splitext

MATRIX_HEADER = 'embryo,quadrant,quartet,cell,frame,x,y,z,parent,fate\n'
MATRIX_ROW = '{embryo},{quadrant},{quartet},{cell},{frame},{x},{y},{z},{parent},{fate}\n'

class SimiProject:
    '''Simi BioCell project file.'''
    def __init__(self, sbc_file, sbd_file):
        self.sbc = Sbc(sbc_file)
        self.sbd = Sbd(sbd_file)

class Sbc:
    '''Settings file for Simi BioCell.'''
    def __init__(self, sbc_file):
        self.sbc_file = self.open_sbc(sbc_file)

        # Main dictionary with all settings.
        self.settings = {}

        # Parse data.
        self.parse_sbc()

    def open_sbc(self, filepath):
        '''Save abspath and try to read file.'''
        try:
            sbc_file = open(filepath)
            return sbc_file
        except:
            print('Could not load the file "{0}"'.format(filepath))

    def parse_sbc(self):
        '''Parse SBD information.'''
        # Stores the current setting.
        current_setting = u''
        # Read SBC file line by line.
        for line in self.sbc_file.readlines():
            if line.startswith(';') or line.startswith('\r'):
                continue
            else:
                if line.startswith('['):
                    current_setting = line.strip('[]\r\n')
                    self.settings[current_setting] = {}
                else:
                    splitted = line.split('=')
                    key = splitted[0]
                    value = splitted[1].strip('\r\n')
                    self.settings[current_setting][key] = value

class Sbd:
    '''Database file for Simi BioCell.'''
    def __init__(self, sbd_file):
        self.sbd_file = self.open_sbd(sbd_file)

        # Main dictionary with all cells.
        self.cells = OrderedDict()

        # Main dictionary with valid cells.
        self.valid_cells = OrderedDict()

        # Dictionary for invalid cells (=without spots).
        self.invalid_cells = OrderedDict()

        # Last frame of the recording.
        self.last_frame = 0  # TODO: get from sbc?

        # Parse file.
        self.parse_sbd()

        # Generate descendants.
        for name, cell in self.cells.iteritems():
            cell.get_descendants()

    def __str__(self):
        return self.sbd_file.name

    def open_sbd(self, filepath):
        '''Get user input, save abspath and try to read file.'''
        try:
            sbd_file = open(filepath)
            return sbd_file
        except:
            print('Could not load the file "{0}"'.format(filepath))

    def parse_sbd(self):
        '''Parse SBD information.'''
        # Temporary buffer for each line of a cell record.
        tmp_cell = ''
        # Temporary switches for parenthood.
        has_parent = False
        parent_cell = None
        # Store for generation birth time of right sibling cell.
        sister_cells = {}

        # Read SBD file line by line.
        for line in self.sbd_file.readlines()[7:]:  # skip headers
            if line.startswith('---'):
                if tmp_cell:
                    # Create cell instance with raw data.
                    cell = Cell(tmp_cell)
                    cell.sbd = self

                    # Define parent cell.
                    if has_parent:
                        cell.parent = parent_cell
                        cell.parent.daughters.append(cell)
                    else:
                        # If cell has a parent, but it's upstream in the lineage.
                        if cell.generation_birth_time in sister_cells.keys():
                            # Get common parent of sibling cells.
                            common_parent = sister_cells[cell.generation_birth_time].parent
                            cell.parent = common_parent
                            cell.parent.daughters.append(cell)

                    # If cell has a left daughter, turn switch on and define parent.
                    if cell.cells_left == 1:
                        has_parent = True
                        parent_cell = cell
                    elif cell.cells_left == 0:
                        has_parent = False
                        parent_cell = None

                    # If cell has a right daughter, add to the sibling dictionary.
                    if cell.cells_right == 1:
                        sister_cells[cell.generation_birth_time] = cell

                    # Add cell to main dictionary.
                    self.cells[cell.generic_name] = cell

                    # If cell is valid, add it to list.
                    if cell.valid:
                        self.valid_cells[cell.generic_name] = cell
                        self.update_last_frame(cell)
                    else:
                        self.invalid_cells[cell.generic_name] = cell

                    # Clean temporary cell.
                    tmp_cell = ''
            else:
                # Add next line to cell data.
                tmp_cell = tmp_cell + line

    def update_last_frame(self, cell):
        '''Updates the last_frame value for the simi instance.'''
        if cell.last_frame > self.last_frame:
            self.last_frame = cell.last_frame

    def get_cells_without_parent(self):
        '''Returns a list of valid cells that have no parent.'''
        no_parent = []
        for cell in self.list_of_cells:
            if not cell.parent:
                no_parent.append(cell)
        return no_parent

    def write_matrix(self, outfile):
        '''Output flat matrix files with all cells.'''
        matrix = open(outfile, 'w')
        # Write header.
        matrix.write(MATRIX_HEADER)
        for cell_key, cell in self.cells.items():
            if cell.valid:
                quadrant = cell.get_quadrant()
                quartet = cell.get_quartet()
                embryo = splitext(cell.sbd.sbd_file.name)[0]
                if cell.parent:
                    parent = cell.parent.generic_name
                else:
                    parent = ''
                for spot in cell.spots:
                    matrix.write(MATRIX_ROW.format(
                        embryo=embryo,
                        quadrant=quadrant,
                        quartet=quartet,
                        cell=cell.generic_name,
                        frame=spot.frame,
                        x=spot.x,
                        y=spot.y,
                        z=spot.z,
                        parent=parent,
                        fate=cell.wildtype,
                        ))
        matrix.close()

class Cell:
    '''Store all cell-related information'''
    def __init__(self, raw_data):
        self.raw_data = raw_data
        self.sbd = None
        self.sbc = None  # TODO: not defined yet.
        self.valid = False

        # Cell attributes line 1. Setting the default values to None because
        # the format uses 0 and -1 switches.
        self.cells_left = None
        self.cells_right = None
        self.active_cells_left = None
        self.active_cells_right = None
        self.generic_name = u''

        # Cell attributes line 2. Not sure what "generation" means, but it's
        # not really used anyway.
        self.generation_birth_time = None  # seconds (ms?)
        self.generation_level = None
        self.generation_wildtype = None
        self.generation_color = None
        self.generation_name = u''

        # Cell attributes line 3.
        self.birth_frame = None  # frame
        self.birth_level = None  # level (z) at mitosis
        self.wildtype = None  # fate of the cell, check .sbc for list
        self.size = None  # integer from BioCell
        self.shape = None  # integer from BioCell
        self.color = None  # decimal value #TODO convert to HEX.
        self.name = u''  # custom name defined by user

        # Cell attributes line 4.
        self.n_spots = None
        self.comment = u''

        # Cell attributes line 5 and beyond: please see class Spot. Spots are
        # stored in a list.
        self.spots = []

        # Additional attributes.
        self.last_frame = None
        self.parent = None
        self.daughters = []

        # Traverse values.
        self.parents = {}
        self.descendants = {}

        # Parse data, any error returns False (invalid).
        self.valid = self.parse_data()

    def __str__(self):
        return 'CELL={name}'.format(name=self.generic_name)

    def parse_data(self):
        '''Extract attributes from raw data.'''
        split_lines = self.raw_data.split('\n')

        # Line one values.
        try:
            line_one = split_lines[0]
            line_one_split = line_one.split()
            # Loop to capture values.
            for index, value in enumerate(line_one_split):
                if index == 0:
                    self.cells_left = int(value)
                elif index == 1:
                    self.cells_right = int(value)
                elif index == 2:
                    self.active_cells_left = int(value)
                elif index == 3:
                    self.active_cells_right = int(value)
                elif index == 4:
                    self.generic_name = value
        except:
            print('Error parsing line 1!')
            print(self.raw_data)
            return False

        # Line two values.
        try:
            line_two = split_lines[1]
            line_two_split = line_two.split()
            # Loop to capture values.
            for index, value in enumerate(line_two_split):
                if index == 0:
                    self.generation_birth_time = int(value)
                elif index == 1:
                    self.generation_level = int(value)
                elif index == 2:
                    self.generation_wildtype = int(value)
                elif index == 3:
                    self.generation_color = int(value)
                elif index == 4:
                    self.generation_name = value
        except:
            print('Error parsing line 2!')
            print(self.raw_data)
            return False

        # Line three values.
        try:
            line_three = split_lines[2]
            line_three_split = line_three.split()
            # Loop to capture values.
            for index, value in enumerate(line_three_split):
                if index == 0:
                    self.birth_frame = int(value)
                elif index == 1:
                    self.birth_level = int(value)
                elif index == 2:
                    self.wildtype = int(value)
                elif index == 3:
                    self.size = int(value)
                elif index == 4:
                    self.shape = int(value)
                elif index == 5:
                    self.color = int(value)
                elif index == 6:
                    self.name = value
        except:
            print('Error parsing line 3!')
            print(self.raw_data)
            return False

        # Line four values.
        try:
            line_four = split_lines[3]
            line_four_split = line_four.split()
            # Define variables.
            self.n_spots = int(line_four_split[0])
            # Remove first item to join comment string.
            line_four_split.pop(0)
            self.comment = ' '.join(line_four_split)
        except:
            print('Error parsing line 4!')
            print(self.raw_data)
            return False

        # If there are no spots, invalid cell.
        if self.n_spots == 0:
            return False
        else:
            # Get the list index of the last spot in split_lines.
            last_spot_index = 4 + self.n_spots
            # Use the index to add the exact number of spots.
            for spot_line in split_lines[4:last_spot_index]:
                new_spot = Spot(spot_line)
                new_spot.cell = self
                self.spots.append(new_spot)
                self.update_last_frame(new_spot)
            # Change status to valid.
            return True

    def update_last_frame(self, spot):
        '''Updates the last_frame value for the cell.'''
        if spot.frame > self.last_frame:
            self.last_frame = spot.frame

    def get_descendants(self):
        '''Returns the descendants.

        This function calculates the descendants for all the descendants
        recursively.  It can be used as an initial method to populate the
        descendants or to get the current descendants of a cell.

        A dictionary is returned.
        '''
        # Iterate through daughter cells.
        for child in self.daughters:
            # Add child to dictionary.
            self.descendants[child.generic_name] = child
            # Descend in the tree.
            self.descendants.update(child.get_descendants())
        return self.descendants

    def get_quadrant(self):
        '''Returns the quadrant of a cell.'''
        cell = self.generic_name.lower()
        if cell == 'ab' or cell == 'cd':
            return ''
        elif 'a' in cell:
            return 'A'
        elif 'b' in cell:
            return 'B'
        elif 'c' in cell:
            return 'C'
        elif 'd' in cell:
            return 'D'

    def get_quartet(self):
        '''Returns the quartet of a cell.'''
        cell = self.generic_name
        if cell == 'AB' or cell == 'CD':
            return ''
        quartet = ''
        if self.generic_name.islower():
            return cell.replace('a', 'q').replace('b', 'q').replace('c', 'q').replace('d', 'q')
        elif self.generic_name.isupper():
            return cell.replace('A', 'Q').replace('B', 'Q').replace('C', 'Q').replace('D', 'Q')
        else:
            return ''

    def print_data(self):
        '''Print out cell data.'''
        print('\nName: {0} ({1})\nFrame: {2}\nSpots: {3}'.format(
            self.name, self.generic_name, self.birth_frame, self.n_spots))
        print('\tframe\tx\ty\tz')
        for spot in self.spots:
            print('\t{0}\t{1}\t{2}\t{3}'.format(spot.frame, spot.x, spot.y, spot.z))

class Spot:
    '''A spot is a manually tracked point with x, y, z, t dimensions.'''
    def __init__(self, raw_data):
        self.raw_data = raw_data
        self.cell = None
        self.valid = False

        # Spot attributes.
        self.frame = 0
        self.x = 0
        self.y = 0
        self.z = 0

        # Parse and validate data.
        self.valid = self.parse_data()

    def __str__(self):
        return 'CELL={cell} FRAME={frame} X={x} Y={y} Z={z}'.format(
                cell=self.cell.generic_name, frame=self.frame, x=self.x, y=self.y, z=self.z)

    def parse_data(self):
        '''Parse spot coordinates.'''
        coordinates = self.raw_data.split()

        # Get attributes.
        self.frame = int(coordinates[0])
        self.x = int(coordinates[1])
        self.y = int(coordinates[2])
        self.z = int(coordinates[3])

        if self.frame:
            return True

<commit_msg>Cleanup description<commit_after>#!/usr/bin/env python

'''Read and access cell lineage data from Simi BioCell.

Small library to parse Simi*BioCell project files (.sbc and .sbd). It collects
all the relevant cell lineage data such as cell name, frame and coordinates,
and provides a programmatic interface to access the data. In this manner the
data can be analyzed by custom functions, or exported to different formats for
data analyses in more up-to-date cell lineage software.
'''

from collections import OrderedDict
from os.path import splitext

MATRIX_HEADER = 'embryo,quadrant,quartet,cell,frame,x,y,z,parent,fate\n'
MATRIX_ROW = '{embryo},{quadrant},{quartet},{cell},{frame},{x},{y},{z},{parent},{fate}\n'

class SimiProject:
    '''Simi BioCell project file.'''
    def __init__(self, sbc_file, sbd_file):
        self.sbc = Sbc(sbc_file)
        self.sbd = Sbd(sbd_file)

class Sbc:
    '''Settings file for Simi BioCell.'''
    def __init__(self, sbc_file):
        self.sbc_file = self.open_sbc(sbc_file)

        # Main dictionary with all settings.
        self.settings = {}

        # Parse data.
        self.parse_sbc()

    def open_sbc(self, filepath):
        '''Save abspath and try to read file.'''
        try:
            sbc_file = open(filepath)
            return sbc_file
        except:
            print('Could not load the file "{0}"'.format(filepath))

    def parse_sbc(self):
        '''Parse SBD information.'''
        # Stores the current setting.
        current_setting = u''
        # Read SBC file line by line.
        for line in self.sbc_file.readlines():
            if line.startswith(';') or line.startswith('\r'):
                continue
            else:
                if line.startswith('['):
                    current_setting = line.strip('[]\r\n')
                    self.settings[current_setting] = {}
                else:
                    splitted = line.split('=')
                    key = splitted[0]
                    value = splitted[1].strip('\r\n')
                    self.settings[current_setting][key] = value

class Sbd:
    '''Database file for Simi BioCell.'''
    def __init__(self, sbd_file):
        self.sbd_file = self.open_sbd(sbd_file)

        # Main dictionary with all cells.
        self.cells = OrderedDict()

        # Main dictionary with valid cells.
        self.valid_cells = OrderedDict()

        # Dictionary for invalid cells (=without spots).
        self.invalid_cells = OrderedDict()

        # Last frame of the recording.
        self.last_frame = 0  # TODO: get from sbc?

        # Parse file.
        self.parse_sbd()

        # Generate descendants.
        for name, cell in self.cells.iteritems():
            cell.get_descendants()

    def __str__(self):
        return self.sbd_file.name

    def open_sbd(self, filepath):
        '''Get user input, save abspath and try to read file.'''
        try:
            sbd_file = open(filepath)
            return sbd_file
        except:
            print('Could not load the file "{0}"'.format(filepath))

    def parse_sbd(self):
        '''Parse SBD information.'''
        # Temporary buffer for each line of a cell record.
        tmp_cell = ''
        # Temporary switches for parenthood.
        has_parent = False
        parent_cell = None
        # Store for generation birth time of right sibling cell.
        sister_cells = {}

        # Read SBD file line by line.
        for line in self.sbd_file.readlines()[7:]:  # skip headers
            if line.startswith('---'):
                if tmp_cell:
                    # Create cell instance with raw data.
                    cell = Cell(tmp_cell)
                    cell.sbd = self

                    # Define parent cell.
                    if has_parent:
                        cell.parent = parent_cell
                        cell.parent.daughters.append(cell)
                    else:
                        # If cell has a parent, but it's upstream in the lineage.
                        if cell.generation_birth_time in sister_cells.keys():
                            # Get common parent of sibling cells.
                            common_parent = sister_cells[cell.generation_birth_time].parent
                            cell.parent = common_parent
                            cell.parent.daughters.append(cell)

                    # If cell has a left daughter, turn switch on and define parent.
                    if cell.cells_left == 1:
                        has_parent = True
                        parent_cell = cell
                    elif cell.cells_left == 0:
                        has_parent = False
                        parent_cell = None

                    # If cell has a right daughter, add to the sibling dictionary.
                    if cell.cells_right == 1:
                        sister_cells[cell.generation_birth_time] = cell

                    # Add cell to main dictionary.
                    self.cells[cell.generic_name] = cell

                    # If cell is valid, add it to list.
                    if cell.valid:
                        self.valid_cells[cell.generic_name] = cell
                        self.update_last_frame(cell)
                    else:
                        self.invalid_cells[cell.generic_name] = cell

                    # Clean temporary cell.
                    tmp_cell = ''
            else:
                # Add next line to cell data.
                tmp_cell = tmp_cell + line

    def update_last_frame(self, cell):
        '''Updates the last_frame value for the simi instance.'''
        if cell.last_frame > self.last_frame:
            self.last_frame = cell.last_frame

    def get_cells_without_parent(self):
        '''Returns a list of valid cells that have no parent.'''
        no_parent = []
        for cell in self.list_of_cells:
            if not cell.parent:
                no_parent.append(cell)
        return no_parent

    def write_matrix(self, outfile):
        '''Output flat matrix files with all cells.'''
        matrix = open(outfile, 'w')
        # Write header.
        matrix.write(MATRIX_HEADER)
        for cell_key, cell in self.cells.items():
            if cell.valid:
                quadrant = cell.get_quadrant()
                quartet = cell.get_quartet()
                embryo = splitext(cell.sbd.sbd_file.name)[0]
                if cell.parent:
                    parent = cell.parent.generic_name
                else:
                    parent = ''
                for spot in cell.spots:
                    matrix.write(MATRIX_ROW.format(
                        embryo=embryo,
                        quadrant=quadrant,
                        quartet=quartet,
                        cell=cell.generic_name,
                        frame=spot.frame,
                        x=spot.x,
                        y=spot.y,
                        z=spot.z,
                        parent=parent,
                        fate=cell.wildtype,
                        ))
        matrix.close()

class Cell:
    '''Store all cell-related information'''
    def __init__(self, raw_data):
        self.raw_data = raw_data
        self.sbd = None
        self.sbc = None  # TODO: not defined yet.
        self.valid = False

        # Cell attributes line 1. Setting the default values to None because
        # the format uses 0 and -1 switches.
        self.cells_left = None
        self.cells_right = None
        self.active_cells_left = None
        self.active_cells_right = None
        self.generic_name = u''

        # Cell attributes line 2. Not sure what "generation" means, but it's
        # not really used anyway.
        self.generation_birth_time = None  # seconds (ms?)
        self.generation_level = None
        self.generation_wildtype = None
        self.generation_color = None
        self.generation_name = u''

        # Cell attributes line 3.
        self.birth_frame = None  # frame
        self.birth_level = None  # level (z) at mitosis
        self.wildtype = None  # fate of the cell, check .sbc for list
        self.size = None  # integer from BioCell
        self.shape = None  # integer from BioCell
        self.color = None  # decimal value #TODO convert to HEX.
        self.name = u''  # custom name defined by user

        # Cell attributes line 4.
        self.n_spots = None
        self.comment = u''

        # Cell attributes line 5 and beyond: please see class Spot. Spots are
        # stored in a list.
        self.spots = []

        # Additional attributes.
        self.last_frame = None
        self.parent = None
        self.daughters = []

        # Traverse values.
        self.parents = {}
        self.descendants = {}

        # Parse data, any error returns False (invalid).
        self.valid = self.parse_data()

    def __str__(self):
        return 'CELL={name}'.format(name=self.generic_name)

    def parse_data(self):
        '''Extract attributes from raw data.'''
        split_lines = self.raw_data.split('\n')

        # Line one values.
        try:
            line_one = split_lines[0]
            line_one_split = line_one.split()
            # Loop to capture values.
            for index, value in enumerate(line_one_split):
                if index == 0:
                    self.cells_left = int(value)
                elif index == 1:
                    self.cells_right = int(value)
                elif index == 2:
                    self.active_cells_left = int(value)
                elif index == 3:
                    self.active_cells_right = int(value)
                elif index == 4:
                    self.generic_name = value
        except:
            print('Error parsing line 1!')
            print(self.raw_data)
            return False

        # Line two values.
        try:
            line_two = split_lines[1]
            line_two_split = line_two.split()
            # Loop to capture values.
            for index, value in enumerate(line_two_split):
                if index == 0:
                    self.generation_birth_time = int(value)
                elif index == 1:
                    self.generation_level = int(value)
                elif index == 2:
                    self.generation_wildtype = int(value)
                elif index == 3:
                    self.generation_color = int(value)
                elif index == 4:
                    self.generation_name = value
        except:
            print('Error parsing line 2!')
            print(self.raw_data)
            return False

        # Line three values.
        try:
            line_three = split_lines[2]
            line_three_split = line_three.split()
            # Loop to capture values.
            for index, value in enumerate(line_three_split):
                if index == 0:
                    self.birth_frame = int(value)
                elif index == 1:
                    self.birth_level = int(value)
                elif index == 2:
                    self.wildtype = int(value)
                elif index == 3:
                    self.size = int(value)
                elif index == 4:
                    self.shape = int(value)
                elif index == 5:
                    self.color = int(value)
                elif index == 6:
                    self.name = value
        except:
            print('Error parsing line 3!')
            print(self.raw_data)
            return False

        # Line four values.
        try:
            line_four = split_lines[3]
            line_four_split = line_four.split()
            # Define variables.
            self.n_spots = int(line_four_split[0])
            # Remove first item to join comment string.
            line_four_split.pop(0)
            self.comment = ' '.join(line_four_split)
        except:
            print('Error parsing line 4!')
            print(self.raw_data)
            return False

        # If there are no spots, invalid cell.
        if self.n_spots == 0:
            return False
        else:
            # Get the list index of the last spot in split_lines.
            last_spot_index = 4 + self.n_spots
            # Use the index to add the exact number of spots.
            for spot_line in split_lines[4:last_spot_index]:
                new_spot = Spot(spot_line)
                new_spot.cell = self
                self.spots.append(new_spot)
                self.update_last_frame(new_spot)
            # Change status to valid.
            return True

    def update_last_frame(self, spot):
        '''Updates the last_frame value for the cell.'''
        if spot.frame > self.last_frame:
            self.last_frame = spot.frame

    def get_descendants(self):
        '''Returns the descendants.

        This function calculates the descendants for all the descendants
        recursively.  It can be used as an initial method to populate the
        descendants or to get the current descendants of a cell.

        A dictionary is returned.
        '''
        # Iterate through daughter cells.
        for child in self.daughters:
            # Add child to dictionary.
            self.descendants[child.generic_name] = child
            # Descend in the tree.
            self.descendants.update(child.get_descendants())
        return self.descendants

    def get_quadrant(self):
        '''Returns the quadrant of a cell.'''
        cell = self.generic_name.lower()
        if cell == 'ab' or cell == 'cd':
            return ''
        elif 'a' in cell:
            return 'A'
        elif 'b' in cell:
            return 'B'
        elif 'c' in cell:
            return 'C'
        elif 'd' in cell:
            return 'D'

    def get_quartet(self):
        '''Returns the quartet of a cell.'''
        cell = self.generic_name
        if cell == 'AB' or cell == 'CD':
            return ''
        quartet = ''
        if self.generic_name.islower():
            return cell.replace('a', 'q').replace('b', 'q').replace('c', 'q').replace('d', 'q')
        elif self.generic_name.isupper():
            return cell.replace('A', 'Q').replace('B', 'Q').replace('C', 'Q').replace('D', 'Q')
        else:
            return ''

    def print_data(self):
        '''Print out cell data.'''
        print('\nName: {0} ({1})\nFrame: {2}\nSpots: {3}'.format(
            self.name, self.generic_name, self.birth_frame, self.n_spots))
        print('\tframe\tx\ty\tz')
        for spot in self.spots:
            print('\t{0}\t{1}\t{2}\t{3}'.format(spot.frame, spot.x, spot.y, spot.z))

class Spot:
    '''A spot is a manually tracked point with x, y, z, t dimensions.'''
    def __init__(self, raw_data):
        self.raw_data = raw_data
        self.cell = None
        self.valid = False

        # Spot attributes.
        self.frame = 0
        self.x = 0
        self.y = 0
        self.z = 0

        # Parse and validate data.
        self.valid = self.parse_data()

    def __str__(self):
        return 'CELL={cell} FRAME={frame} X={x} Y={y} Z={z}'.format(
                cell=self.cell.generic_name, frame=self.frame, x=self.x, y=self.y, z=self.z)

    def parse_data(self):
        '''Parse spot coordinates.'''
        coordinates = self.raw_data.split()

        # Get attributes.
        self.frame = int(coordinates[0])
        self.x = int(coordinates[1])
        self.y = int(coordinates[2])
        self.z = int(coordinates[3])

        if self.frame:
            return True

<|endoftext|>


<commit_before># -*- coding: utf-8 -*-
cyrillic = set(u"АаБбВвГгДдЂђЕеЖжЗзИиЈјКкЛлЉљМмНнЊњОоПпРрСсТтЋћУуФфХхЦцЧчЏџШш")

def remove_cyrillic_comments(comments, labels, print_perc=True):
    clean_coms = []
    clean_labels = []

    for comment, label in zip(comments, labels):
        if not bool(set(comment.decode('utf8')).intersection(cyrillic)):
            clean_coms.append(comment)
            clean_labels.append(label)

    return clean_coms, clean_labels

def remove_serbian_accents(comments):
    bald = []
    for comment in comments:
        bald_comment = (comment.decode('utf8')) \
            .replace(u"ć", u"c") \
            .replace(u"č", u"c") \
            .replace(u"š", u"s") \
            .replace(u"đ", u"dj") \
            .replace(u"ž", u"z")

        bald.append(bald_comment)

    return bald

def remove_cyrillic_and_accents(comments, labels=None, remove_accents=True):
    if labels is None:
        _labels = range(len(comments))
    else:
        _labels = labels

    comments, _labels = remove_cyrillic_comments(comments, _labels)
    if remove_accents:
        comments = remove_serbian_accents(comments)

    if labels:
        return comments, _labels
    else:
        return comments
<commit_msg>removed bald_latin.py. Logic in text2words.py<commit_after><|endoftext|>


<commit_before>def make_images(prep):
    """
    parameters
    -----------
    prep: a preparator objects
        prep is a preparator object.  It contains the config info and can be
        used as a dict, in addition to methods

        e.g. it has prep['nwgint_flist'] available

    """
    maker=ImageMaker(prep)
    maker.go()

class ImageMaker(dict):
    """
    class to run galsim and make the new images
    """
    def __init__(self, prep):
        self.update(prep)

    def go(self):
        """
        make the images
        """
<commit_msg>added pass to sim.py<commit_after>def make_images(prep):
    """
    parameters
    -----------
    prep: a preparator objects
        prep is a preparator object.  It contains the config info and can be
        used as a dict, in addition to methods

        e.g. it has prep['nwgint_flist'] available

    """
    maker=ImageMaker(prep)
    maker.go()

class ImageMaker(dict):
    """
    class to run galsim and make the new images
    """
    def __init__(self, prep):
        self.update(prep)

    def go(self):
        """
        make the images
        """
        pass
<|endoftext|>


<commit_before>import re
import os
from datetime import datetime

import bottle
from bottle import (abort, default_app, request, response, route, run,
    jinja2_view as view)
from pyga.requests import Tracker, Page, Session, Visitor
from pytz import timezone
from rss2producer import RSS2Feed
import dataset
import sqlalchemy.sql

from settings import TABLE, PAGES

LIMIT = 50

ga_account = os.environ.get('GA_ACCOUNT')
ga_domain = os.environ.get('GA_DOMAIN')

# helpers
slug_to_name = {slug: name for slug, pk, name in PAGES}
slug_to_id = {slug: pk for slug, pk, name in PAGES}

def ping():
    """ping back to ga"""
    if not ga_account:
        return

    tracker = Tracker(ga_account, ga_domain)
    visitor = Visitor()
    visitor.ip_address = request.remote_addr
    session = Session()
    page = Page(request.path)
    if 'referer' in request.headers:
        page.referrer = request.headers['referer']
    tracker.track_pageview(page, session, visitor)

@route('/')
@view('home')
def index():
    return {
        'object_list': sorted(PAGES, key=lambda x: x[2]),
    }

@route('/<slug>/feed.xml')
def feed_detail(slug):
    ping()
    if slug != 'all' and slug not in slug_to_name:
        abort(404, 'No results for that Board or Commission')
    db = dataset.connect()  # uses DATABASE_URL
    tz = timezone('America/Chicago')
    # table = db.load_table(TABLE)  # don't allow dataset to create the table
    if slug == 'all':
        feed_info = dict(
            title='Boards and Commissions',
            link='http://www.austintexas.gov/department/boards-and-commissions-information-center',
            description='Feed of Boards and Commissions activity',
        )
    else:
        feed_info = dict(
            title=slug_to_name[slug],
            link=('http://www.austintexas.gov/cityclerk/boards_commissions/'
                'meetings/{}_1.htm'.format(slug_to_id[slug])),
            description='Feed of {} activity'.format(slug_to_name[slug]),
        )
    feed = RSS2Feed(**feed_info)
    # sql
    where_conditions = []
    where_values = {}
    if slug != 'all':
        where_conditions.append("bandc = :slug")
        where_values['slug'] = slug
    search = request.query.get('q')
    if search:
        # blog.lostpropertyhq.com/postgres-full-text-search-is-good-enough/
        table_sql = ("(SELECT *, to_tsvector(title || ' ' || text) as "
            "document from {}) p_search".format(TABLE))
        where_conditions.append("p_search.document @@ plainto_tsquery(:search)")
        where_values['search'] = '%{}%'.format(search)
        where_sql = 'WHERE {}'.format(' AND '.join(where_conditions))
    else:
        table_sql = TABLE
        where_sql = ''
        if where_values:
            where_sql = 'WHERE {}'.format(' AND '.join(where_conditions))
    # manually construct sql because `dataset` ordering isn't working for me
    sql = sqlalchemy.sql.text(
        'SELECT * FROM {} {} ORDER BY date DESC LIMIT {}'.format(
            table_sql,
            where_sql,
            LIMIT,
        )
    )
    results = db.query(sql, **where_values)
    for row in results:
        title = row['title'].decode('utf8') or row['type']
        if slug == 'all':
            title = u'[{}] {}'.format(slug_to_name[row['bandc'].decode('utf8')], title)
        text = row['text'] or ''
        text = text.strip().encode('ascii', 'ignore')[:600].strip()
        text = re.sub(r'\s+', ' ', text)[:500]
        if row['pdf_scraped'] and not text:
            text = '{} ({})'.format(row['type'], 'no text found in pdf')
        feed.append_item(
            title=title,
            link=row['url'],
            description=text if text else row['type'],
            # convert date into datetime
            pub_date=datetime(
                row['date'].year,
                row['date'].month,
                row['date'].day,
                tzinfo=tz,
            ),
        )
    response.content_type = 'application/rss+xml'
    return feed.get_xml()

BASE_DIR = os.path.dirname(__file__)
bottle.TEMPLATE_PATH.append(os.path.join(BASE_DIR, 'templates/'))
app = default_app()

if __name__ == '__main__':
    bottle.debug(True)
    run(host='localhost', port=8000, reloader=True)
<commit_msg>refactor result fetching from feed serving<commit_after>import re
import os
from datetime import datetime

import bottle
from bottle import (abort, default_app, request, response, route, run,
    jinja2_view as view)
from pyga.requests import Tracker, Page, Session, Visitor
from pytz import timezone
from rss2producer import RSS2Feed
import dataset
import sqlalchemy.sql

from settings import TABLE, PAGES

LIMIT = 50

ga_account = os.environ.get('GA_ACCOUNT')
ga_domain = os.environ.get('GA_DOMAIN')

# helpers
slug_to_name = {slug: name for slug, pk, name in PAGES}
slug_to_id = {slug: pk for slug, pk, name in PAGES}

def ping():
    """ping back to ga"""
    if not ga_account:
        return

    tracker = Tracker(ga_account, ga_domain)
    visitor = Visitor()
    visitor.ip_address = request.remote_addr
    session = Session()
    page = Page(request.path)
    if 'referer' in request.headers:
        page.referrer = request.headers['referer']
    tracker.track_pageview(page, session, visitor)

@route('/')
@view('home')
def index():
    return {
        'object_list': sorted(PAGES, key=lambda x: x[2]),
    }

def get_feed_queryset(slug):
    if slug != 'all' and slug not in slug_to_name:
        abort(404, 'No results for that Board or Commission')
    db = dataset.connect()  # uses DATABASE_URL
    # table = db.load_table(TABLE)  # don't allow dataset to create the table
    # sql
    where_conditions = []
    where_values = {}
    if slug != 'all':
        where_conditions.append("bandc = :slug")
        where_values['slug'] = slug
    search = request.query.get('q')
    if search:
        # blog.lostpropertyhq.com/postgres-full-text-search-is-good-enough/
        table_sql = ("(SELECT *, to_tsvector(title || ' ' || text) as "
            "document from {}) p_search".format(TABLE))
        where_conditions.append("p_search.document @@ plainto_tsquery(:search)")
        where_values['search'] = '%{}%'.format(search)
        where_sql = 'WHERE {}'.format(' AND '.join(where_conditions))
    else:
        table_sql = TABLE
        where_sql = ''
        if where_values:
            where_sql = 'WHERE {}'.format(' AND '.join(where_conditions))
    # manually construct sql because `dataset` ordering isn't working for me
    sql = sqlalchemy.sql.text(
        'SELECT * FROM {} {} ORDER BY date DESC LIMIT {}'.format(
            table_sql,
            where_sql,
            LIMIT,
        )
    )
    results = db.query(sql, **where_values)
    return results

@route('/<slug>/feed.xml')
def feed_detail(slug):
    ping()
    results = get_feed_queryset(slug)
    if slug == 'all':
        feed_info = dict(
            title='Boards and Commissions',
            link='http://www.austintexas.gov/department/boards-and-commissions-information-center',
            description='Feed of Boards and Commissions activity',
        )
    else:
        feed_info = dict(
            title=slug_to_name[slug],
            link=('http://www.austintexas.gov/cityclerk/boards_commissions/'
                'meetings/{}_1.htm'.format(slug_to_id[slug])),
            description='Feed of {} activity'.format(slug_to_name[slug]),
        )
    feed = RSS2Feed(**feed_info)
    tz = timezone('America/Chicago')
    for row in results:
        title = row['title'].decode('utf8') or row['type']
        if slug == 'all':
            title = u'[{}] {}'.format(slug_to_name[row['bandc'].decode('utf8')], title)
        text = row['text'] or ''
        text = text.strip().encode('ascii', 'ignore')[:600].strip()
        text = re.sub(r'\s+', ' ', text)[:500]
        if row['pdf_scraped'] and not text:
            text = '{} ({})'.format(row['type'], 'no text found in pdf')
        feed.append_item(
            title=title,
            link=row['url'],
            description=text if text else row['type'],
            # convert date into datetime
            pub_date=datetime(
                row['date'].year,
                row['date'].month,
                row['date'].day,
                tzinfo=tz,
            ),
        )
    response.content_type = 'application/rss+xml'
    return feed.get_xml()

BASE_DIR = os.path.dirname(__file__)
bottle.TEMPLATE_PATH.append(os.path.join(BASE_DIR, 'templates/'))
app = default_app()

if __name__ == '__main__':
    bottle.debug(True)
    run(host='localhost', port=8000, reloader=True)
<|endoftext|>


<commit_before># Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

{
  'variables': {
    'chromium_code': 1,
  },
  'includes': [
    'base.gypi',
  ],
  'targets': [
    {
      'target_name': 'base_i18n',
      'type': '<(library)',
      'msvs_guid': '968F3222-9798-4D21-BE08-15ECB5EF2994',
      'dependencies': [
        'base',
        '../third_party/icu/icu.gyp:icui18n',
        '../third_party/icu/icu.gyp:icuuc',
      ],
      'conditions': [
        ['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
          'dependencies': [
            # i18n/rtl.cc uses gtk
            '../build/linux/system.gyp:gtk',
          ],
        }],
      ],
      'export_dependent_settings': [
        'base',
      ],
      'sources': [
        'i18n/file_util_icu.cc',
        'i18n/file_util_icu.h',
        'i18n/icu_encoding_detection.cc',
        'i18n/icu_encoding_detection.h',
        'i18n/icu_string_conversions.cc',
        'i18n/icu_string_conversions.h',
        'i18n/icu_util.cc',
        'i18n/icu_util.h',
        'i18n/number_formatting.cc',
        'i18n/number_formatting.h',
        'i18n/rtl.cc',
        'i18n/rtl.h',
        'i18n/time_formatting.cc',
        'i18n/time_formatting.h',
        'i18n/word_iterator.cc',
        'i18n/word_iterator.h',
      ],
    },
    {
      'target_name': 'base_unittests',
      'type': 'executable',
      'msvs_guid': '27A30967-4BBA-48D1-8522-CDE95F7B1CEC',
      'sources': [
        # Infrastructure files.
        'multiprocess_test.h',
        'test/run_all_unittests.cc',

        # Tests.
        'at_exit_unittest.cc',
        'atomicops_unittest.cc',
        'base64_unittest.cc',
        'bits_unittest.cc',
        'callback_unittest.cc',
        'cancellation_flag_unittest.cc',
        'command_line_unittest.cc',
        'condition_variable_unittest.cc',
        'crypto/encryptor_unittest.cc',
        'crypto/rsa_private_key_unittest.cc',
        'crypto/rsa_private_key_nss_unittest.cc',
        'crypto/signature_creator_unittest.cc',
        'crypto/signature_verifier_unittest.cc',
        'crypto/symmetric_key_unittest.cc',
        'data_pack_unittest.cc',
        'debug_util_unittest.cc',
        'dir_reader_posix_unittest.cc',
        'environment_unittest.cc',
        'event_trace_consumer_win_unittest.cc',
        'event_trace_controller_win_unittest.cc',
        'event_trace_provider_win_unittest.cc',
        'field_trial_unittest.cc',
        'file_descriptor_shuffle_unittest.cc',
        'file_path_unittest.cc',
        'file_util_unittest.cc',
        'file_version_info_unittest.cc',
        'gmock_unittest.cc',
        'histogram_unittest.cc',
        'hmac_unittest.cc',
        'id_map_unittest.cc',
        'i18n/file_util_icu_unittest.cc',
        'i18n/icu_string_conversions_unittest.cc',
        'i18n/rtl_unittest.cc',
        'i18n/word_iterator_unittest.cc',
        'json/json_reader_unittest.cc',
        'json/json_writer_unittest.cc',
        'json/string_escape_unittest.cc',
        'lazy_instance_unittest.cc',
        'leak_tracker_unittest.cc',
        'linked_list_unittest.cc',
        'linked_ptr_unittest.cc',
        'lock_unittest.cc',
        'mac_util_unittest.mm',
        'message_loop_proxy_impl_unittest.cc',
        'message_loop_unittest.cc',
        'message_pump_glib_unittest.cc',
        'object_watcher_unittest.cc',
        'observer_list_unittest.cc',
        'path_service_unittest.cc',
        'pe_image_unittest.cc',
        'pickle_unittest.cc',
        'platform_thread_unittest.cc',
        'pr_time_unittest.cc',
        'process_util_unittest.cc',
        'process_util_unittest_mac.h',
        'process_util_unittest_mac.mm',
        'rand_util_unittest.cc',
        'ref_counted_unittest.cc',
	'registry_unittest.cc',
        'scoped_bstr_win_unittest.cc',
        'scoped_comptr_win_unittest.cc',
        'scoped_native_library_unittest.cc',
        'scoped_ptr_unittest.cc',
        'scoped_temp_dir_unittest.cc',
        'scoped_variant_win_unittest.cc',
        'sha1_unittest.cc',
        'sha2_unittest.cc',
        'shared_memory_unittest.cc',
        'simple_thread_unittest.cc',
        'singleton_unittest.cc',
        'stack_container_unittest.cc',
        'stats_table_unittest.cc',
        'string_number_conversions_unittest.cc',
        'string_piece_unittest.cc',
        'string_split_unittest.cc',
        'string_tokenizer_unittest.cc',
        'string_util_unittest.cc',
        'stringprintf_unittest.cc',
        'sys_info_unittest.cc',
        'sys_string_conversions_mac_unittest.mm',
        'sys_string_conversions_unittest.cc',
        'thread_collision_warner_unittest.cc',
        'thread_local_storage_unittest.cc',
        'thread_local_unittest.cc',
        'thread_unittest.cc',
        'time_unittest.cc',
        'time_win_unittest.cc',
        'timer_unittest.cc',
        'tools_sanity_unittest.cc',
        'trace_event_win_unittest.cc',
        'tracked_objects_unittest.cc',
        'tuple_unittest.cc',
        'utf_offset_string_conversions_unittest.cc',
        'utf_string_conversions_unittest.cc',
        'values_unittest.cc',
        'version_unittest.cc',
        'waitable_event_unittest.cc',
        'waitable_event_watcher_unittest.cc',
        'watchdog_unittest.cc',
        'weak_ptr_unittest.cc',
        'win_util_unittest.cc',
        'wmi_util_unittest.cc',
        'worker_pool_unittest.cc',
      ],
      'include_dirs': [
        # word_iterator.h (used by word_iterator_unittest.cc) leaks an ICU
        # #include for unicode/uchar.h.  This should probably be cleaned up.
        '../third_party/icu/public/common',
      ],
      'dependencies': [
        'base',
        'base_i18n',
        'test_support_base',
        '../testing/gmock.gyp:gmock',
        '../testing/gtest.gyp:gtest',
      ],
      'conditions': [
        ['OS == "linux" or OS == "freebsd" or OS == "openbsd" or OS == "solaris"', {
          'sources!': [
            'file_version_info_unittest.cc',
            'worker_pool_linux_unittest.cc',
          ],
          'sources': [
            'xdg_util_unittest.cc',
          ],
          'dependencies': [
            '../build/linux/system.gyp:gtk',
            '../build/linux/system.gyp:nss',
            '../tools/xdisplaycheck/xdisplaycheck.gyp:xdisplaycheck',
          ],
        }, {  # OS != "linux" and OS != "freebsd" and OS != "openbsd" and OS != "solaris"
          'sources!': [
            'message_pump_glib_unittest.cc',
            'crypto/rsa_private_key_nss_unittest.cc',
          ]
        }],
        # This is needed to trigger the dll copy step on windows.
        # TODO(mark): This should not be necessary.
        ['OS == "win"', {
          'dependencies': [
            '../third_party/icu/icu.gyp:icudata',
          ],
          'sources!': [
            'dir_reader_posix_unittest.cc',
            'file_descriptor_shuffle_unittest.cc',
          ],
        }, {  # OS != "win"
          'sources!': [
            'event_trace_consumer_win_unittest.cc',
            'event_trace_controller_win_unittest.cc',
            'event_trace_provider_win_unittest.cc',
            'object_watcher_unittest.cc',
            'pe_image_unittest.cc',
            'scoped_bstr_win_unittest.cc',
            'scoped_comptr_win_unittest.cc',
            'scoped_variant_win_unittest.cc',
            'system_monitor_unittest.cc',
            'time_win_unittest.cc',
            'trace_event_win_unittest.cc',
            'win_util_unittest.cc',
            'wmi_util_unittest.cc',
          ],
        }],
      ],
    },
    {
      'target_name': 'test_support_base',
      'type': '<(library)',
      'dependencies': [
        'base',
        'base_i18n',
        '../testing/gmock.gyp:gmock',
        '../testing/gtest.gyp:gtest',
      ],
      'conditions': [
        ['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
          'dependencies': [
            # test_suite initializes GTK.
            '../build/linux/system.gyp:gtk',
          ],
        }],
      ],
      'sources': [
        'test/test_file_util.h',
        'test/test_file_util_linux.cc',
        'test/test_file_util_mac.cc',
        'test/test_file_util_posix.cc',
        'test/test_file_util_win.cc',
        'test/test_suite.cc',
        'test/test_suite.h',
      ],
    },
    {
      'target_name': 'test_support_perf',
      'type': '<(library)',
      'dependencies': [
        'base',
        '../testing/gtest.gyp:gtest',
      ],
      'sources': [
        'perftimer.cc',
        'test/run_all_perftests.cc',
      ],
      'direct_dependent_settings': {
        'defines': [
          'PERF_TEST',
        ],
      },
      'conditions': [
        ['OS == "linux" or OS == "freebsd" or OS == "openbsd" or OS == "solaris"', {
          'dependencies': [
            # Needed to handle the #include chain:
            #   base/test/perf_test_suite.h
            #   base/test/test_suite.h
            #   gtk/gtk.h
            '../build/linux/system.gyp:gtk',
          ],
        }],
      ],
    },
  ],
  'conditions': [
    [ 'OS == "win"', {
      'targets': [
        {
          'target_name': 'debug_message',
          'type': 'executable',
          'sources': [
            'debug_message.cc',
          ],
          'msvs_settings': {
            'VCLinkerTool': {
              'SubSystem': '2',         # Set /SUBSYSTEM:WINDOWS
            },
          },
        },
      ],
    }],
  ],
}

# Local Variables:
# tab-width:2
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=2 shiftwidth=2:
<commit_msg>Fix for win and mac builds<commit_after># Copyright (c) 2010 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

{
  'variables': {
    'chromium_code': 1,
  },
  'includes': [
    'base.gypi',
  ],
  'targets': [
    {
      'target_name': 'base_i18n',
      'type': '<(library)',
      'msvs_guid': '968F3222-9798-4D21-BE08-15ECB5EF2994',
      'dependencies': [
        'base',
        '../third_party/icu/icu.gyp:icui18n',
        '../third_party/icu/icu.gyp:icuuc',
      ],
      'conditions': [
        ['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
          'dependencies': [
            # i18n/rtl.cc uses gtk
            '../build/linux/system.gyp:gtk',
          ],
        }],
      ],
      'export_dependent_settings': [
        'base',
      ],
      'sources': [
        'i18n/file_util_icu.cc',
        'i18n/file_util_icu.h',
        'i18n/icu_encoding_detection.cc',
        'i18n/icu_encoding_detection.h',
        'i18n/icu_string_conversions.cc',
        'i18n/icu_string_conversions.h',
        'i18n/icu_util.cc',
        'i18n/icu_util.h',
        'i18n/number_formatting.cc',
        'i18n/number_formatting.h',
        'i18n/rtl.cc',
        'i18n/rtl.h',
        'i18n/time_formatting.cc',
        'i18n/time_formatting.h',
        'i18n/word_iterator.cc',
        'i18n/word_iterator.h',
      ],
    },
    {
      'target_name': 'base_unittests',
      'type': 'executable',
      'msvs_guid': '27A30967-4BBA-48D1-8522-CDE95F7B1CEC',
      'sources': [
        # Infrastructure files.
        'multiprocess_test.h',
        'test/run_all_unittests.cc',

        # Tests.
        'at_exit_unittest.cc',
        'atomicops_unittest.cc',
        'base64_unittest.cc',
        'bits_unittest.cc',
        'callback_unittest.cc',
        'cancellation_flag_unittest.cc',
        'command_line_unittest.cc',
        'condition_variable_unittest.cc',
        'crypto/encryptor_unittest.cc',
        'crypto/rsa_private_key_unittest.cc',
        'crypto/rsa_private_key_nss_unittest.cc',
        'crypto/signature_creator_unittest.cc',
        'crypto/signature_verifier_unittest.cc',
        'crypto/symmetric_key_unittest.cc',
        'data_pack_unittest.cc',
        'debug_util_unittest.cc',
        'dir_reader_posix_unittest.cc',
        'environment_unittest.cc',
        'event_trace_consumer_win_unittest.cc',
        'event_trace_controller_win_unittest.cc',
        'event_trace_provider_win_unittest.cc',
        'field_trial_unittest.cc',
        'file_descriptor_shuffle_unittest.cc',
        'file_path_unittest.cc',
        'file_util_unittest.cc',
        'file_version_info_unittest.cc',
        'gmock_unittest.cc',
        'histogram_unittest.cc',
        'hmac_unittest.cc',
        'id_map_unittest.cc',
        'i18n/file_util_icu_unittest.cc',
        'i18n/icu_string_conversions_unittest.cc',
        'i18n/rtl_unittest.cc',
        'i18n/word_iterator_unittest.cc',
        'json/json_reader_unittest.cc',
        'json/json_writer_unittest.cc',
        'json/string_escape_unittest.cc',
        'lazy_instance_unittest.cc',
        'leak_tracker_unittest.cc',
        'linked_list_unittest.cc',
        'linked_ptr_unittest.cc',
        'lock_unittest.cc',
        'mac_util_unittest.mm',
        'message_loop_proxy_impl_unittest.cc',
        'message_loop_unittest.cc',
        'message_pump_glib_unittest.cc',
        'object_watcher_unittest.cc',
        'observer_list_unittest.cc',
        'path_service_unittest.cc',
        'pe_image_unittest.cc',
        'pickle_unittest.cc',
        'platform_thread_unittest.cc',
        'pr_time_unittest.cc',
        'process_util_unittest.cc',
        'process_util_unittest_mac.h',
        'process_util_unittest_mac.mm',
        'rand_util_unittest.cc',
        'ref_counted_unittest.cc',
	'registry_unittest.cc',
        'scoped_bstr_win_unittest.cc',
        'scoped_comptr_win_unittest.cc',
        'scoped_native_library_unittest.cc',
        'scoped_ptr_unittest.cc',
        'scoped_temp_dir_unittest.cc',
        'scoped_variant_win_unittest.cc',
        'sha1_unittest.cc',
        'sha2_unittest.cc',
        'shared_memory_unittest.cc',
        'simple_thread_unittest.cc',
        'singleton_unittest.cc',
        'stack_container_unittest.cc',
        'stats_table_unittest.cc',
        'string_number_conversions_unittest.cc',
        'string_piece_unittest.cc',
        'string_split_unittest.cc',
        'string_tokenizer_unittest.cc',
        'string_util_unittest.cc',
        'stringprintf_unittest.cc',
        'sys_info_unittest.cc',
        'sys_string_conversions_mac_unittest.mm',
        'sys_string_conversions_unittest.cc',
        'thread_collision_warner_unittest.cc',
        'thread_local_storage_unittest.cc',
        'thread_local_unittest.cc',
        'thread_unittest.cc',
        'time_unittest.cc',
        'time_win_unittest.cc',
        'timer_unittest.cc',
        'tools_sanity_unittest.cc',
        'trace_event_win_unittest.cc',
        'tracked_objects_unittest.cc',
        'tuple_unittest.cc',
        'utf_offset_string_conversions_unittest.cc',
        'utf_string_conversions_unittest.cc',
        'values_unittest.cc',
        'version_unittest.cc',
        'waitable_event_unittest.cc',
        'waitable_event_watcher_unittest.cc',
        'watchdog_unittest.cc',
        'weak_ptr_unittest.cc',
        'win_util_unittest.cc',
        'wmi_util_unittest.cc',
        'worker_pool_unittest.cc',
      ],
      'include_dirs': [
        # word_iterator.h (used by word_iterator_unittest.cc) leaks an ICU
        # #include for unicode/uchar.h.  This should probably be cleaned up.
        '../third_party/icu/public/common',
      ],
      'dependencies': [
        'base',
        'base_i18n',
        'test_support_base',
        '../testing/gmock.gyp:gmock',
        '../testing/gtest.gyp:gtest',
      ],
      'conditions': [
        ['OS == "linux" or OS == "freebsd" or OS == "openbsd" or OS == "solaris"', {
          'sources!': [
            'file_version_info_unittest.cc',
            'worker_pool_linux_unittest.cc',
          ],
          'sources': [
            'xdg_util_unittest.cc',
          ],
          'dependencies': [
            '../build/linux/system.gyp:gtk',
            '../build/linux/system.gyp:nss',
            '../tools/xdisplaycheck/xdisplaycheck.gyp:xdisplaycheck',
          ],
        }, {  # OS != "linux" and OS != "freebsd" and OS != "openbsd" and OS != "solaris"
          'sources!': [
            'message_pump_glib_unittest.cc',
            'crypto/rsa_private_key_nss_unittest.cc',
          ]
        }],
        # This is needed to trigger the dll copy step on windows.
        # TODO(mark): This should not be necessary.
        ['OS == "win"', {
          'dependencies': [
            '../third_party/icu/icu.gyp:icudata',
          ],
          'sources!': [
            'dir_reader_posix_unittest.cc',
            'file_descriptor_shuffle_unittest.cc',
          ],
        }, {  # OS != "win"
          'sources!': [
            'event_trace_consumer_win_unittest.cc',
            'event_trace_controller_win_unittest.cc',
            'event_trace_provider_win_unittest.cc',
            'object_watcher_unittest.cc',
            'pe_image_unittest.cc',
	    'registry_unittest.cc',
            'scoped_bstr_win_unittest.cc',
            'scoped_comptr_win_unittest.cc',
            'scoped_variant_win_unittest.cc',
            'system_monitor_unittest.cc',
            'time_win_unittest.cc',
            'trace_event_win_unittest.cc',
            'win_util_unittest.cc',
            'wmi_util_unittest.cc',
          ],
        }],
      ],
    },
    {
      'target_name': 'test_support_base',
      'type': '<(library)',
      'dependencies': [
        'base',
        'base_i18n',
        '../testing/gmock.gyp:gmock',
        '../testing/gtest.gyp:gtest',
      ],
      'conditions': [
        ['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
          'dependencies': [
            # test_suite initializes GTK.
            '../build/linux/system.gyp:gtk',
          ],
        }],
      ],
      'sources': [
        'test/test_file_util.h',
        'test/test_file_util_linux.cc',
        'test/test_file_util_mac.cc',
        'test/test_file_util_posix.cc',
        'test/test_file_util_win.cc',
        'test/test_suite.cc',
        'test/test_suite.h',
      ],
    },
    {
      'target_name': 'test_support_perf',
      'type': '<(library)',
      'dependencies': [
        'base',
        '../testing/gtest.gyp:gtest',
      ],
      'sources': [
        'perftimer.cc',
        'test/run_all_perftests.cc',
      ],
      'direct_dependent_settings': {
        'defines': [
          'PERF_TEST',
        ],
      },
      'conditions': [
        ['OS == "linux" or OS == "freebsd" or OS == "openbsd" or OS == "solaris"', {
          'dependencies': [
            # Needed to handle the #include chain:
            #   base/test/perf_test_suite.h
            #   base/test/test_suite.h
            #   gtk/gtk.h
            '../build/linux/system.gyp:gtk',
          ],
        }],
      ],
    },
  ],
  'conditions': [
    [ 'OS == "win"', {
      'targets': [
        {
          'target_name': 'debug_message',
          'type': 'executable',
          'sources': [
            'debug_message.cc',
          ],
          'msvs_settings': {
            'VCLinkerTool': {
              'SubSystem': '2',         # Set /SUBSYSTEM:WINDOWS
            },
          },
        },
      ],
    }],
  ],
}

# Local Variables:
# tab-width:2
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=2 shiftwidth=2:
<|endoftext|>