<commit_before>from django.shortcuts import render
from rest_framework.views import APIView
from popit_search.utils.search import SerializerSearch
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from rest_framework.exceptions import ParseError
import logging
from popit.views.base import BasePopitView
from popit.models import Organization
from popit.models import Person
from popit.models import Post
from popit.models import Membership
from popit.models import Identifier
from popit.models import ContactDetail
from popit.models import OtherName
from popit.models import Link
from popit.serializers import OrganizationSerializer
from popit.serializers import PersonSerializer
from popit.serializers import PostSerializer
from popit.serializers import MembershipSerializer

ES_MODEL_MAP = {
    "organizations": Organization,
    "persons": Person,
    "posts": Post,
    "memberships": Membership,
    "identifiers": Identifier,
    "other_names": OtherName,
    "links": Link,
    "contact_details": ContactDetail,
    "parent": Organization,
    "other_labels": OtherName
}

ES_SERIALIZER_MAP = {
    "organizations": OrganizationSerializer,
    "persons": PersonSerializer,
    "posts": PostSerializer,
    "memberships": MembershipSerializer,
}

class ResultFilters(object):
    def filter_result(self, result, index_name, language):
        entity = ES_MODEL_MAP.get(index_name)
        if not entity:
            raise EntityNotIndexedException("Entity not indexed or entity is not valid")
        output = []

        for item in result:

            instance = self.filter_instance(entity, item["id"], language)
            if instance:
                serializer_class = ES_SERIALIZER_MAP[index_name]
                serializer = serializer_class(instance, language=language)
                output.append(serializer.data)

        return output

    def filter_instance(self, entity, instance_id, language):
        try:
            instance = entity.objects.language(language).get(id=instance_id)
            return instance
        except entity.DoesNotExist:
            return None

    def filter_nested(self, item, language):
        for key in item:
            if key in ES_MODEL_MAP:
                if type(item[key]) is list:
                    temp = []
                    for entry in item[key]:
                        entity = ES_MODEL_MAP[key]
                        instance = self.filter_instance(entity, entry["id"], language)
                        if instance:
                            temp.append(entry)
                    item[key] = temp
                elif type(item[key]) is dict:
                    entity = ES_MODEL_MAP[key]
                    instance = self.filter_instance(entity, item[key]["id"], language)
                    if not instance:
                        item[key] = {}
        return item

    # This is used on cleaned data
    def drop_result(self, entry, query):
        keys, value = self.parse_query(query)
        check = entry
        for key in keys:

            if type(check) is list:
                matched = False
                for item in check:
                    if item[key].lower() == value.lower():
                        matched = True
                if not matched:
                    return True
                else:
                    return False

            elif issubclass(type(check), dict):
                # we are not sure if the next item is a list or not. Should not because I limit the depth
                check = entry[key]

        # Because last key in the dict. Loop will end, so check for value
        if check.lower() != value.lower():
            return True
        return False

    def parse_query(self, query):

        key, value = query.split(":")
        keys = key.split(".")
        return keys, value

# Create your views here.
class GenericSearchView(BasePopitView, ResultFilters):
    index = None

    def get(self, request, language, index_name, **kwargs):
        search = SerializerSearch(index_name)

        q = request.GET.get("q")
        logging.warn(q)
        if not q:
            raise ParseError("q parameter is required, data format can be found at https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html")

        result = search.search(query=q, language=language)
        output = []
        logging.warn(result)
        temp = self.filter_result(result, index_name, language)
        for entry in temp:
            data = self.filter_nested(entry, language)
            if not self.drop_result(data, q):
                output.append(data)

        page = self.paginator.paginate_queryset(output, request, view=self)
        return self.paginator.get_paginated_response(page)

class EntityNotIndexedException(Exception):
    pass

class OperationNotSupportedException(Exception):
    pass<commit_msg>use in instead of == for value checking #117<commit_after>from django.shortcuts import render
from rest_framework.views import APIView
from popit_search.utils.search import SerializerSearch
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from rest_framework.exceptions import ParseError
import logging
from popit.views.base import BasePopitView
from popit.models import Organization
from popit.models import Person
from popit.models import Post
from popit.models import Membership
from popit.models import Identifier
from popit.models import ContactDetail
from popit.models import OtherName
from popit.models import Link
from popit.serializers import OrganizationSerializer
from popit.serializers import PersonSerializer
from popit.serializers import PostSerializer
from popit.serializers import MembershipSerializer

ES_MODEL_MAP = {
    "organizations": Organization,
    "persons": Person,
    "posts": Post,
    "memberships": Membership,
    "identifiers": Identifier,
    "other_names": OtherName,
    "links": Link,
    "contact_details": ContactDetail,
    "parent": Organization,
    "other_labels": OtherName
}

ES_SERIALIZER_MAP = {
    "organizations": OrganizationSerializer,
    "persons": PersonSerializer,
    "posts": PostSerializer,
    "memberships": MembershipSerializer,
}

class ResultFilters(object):
    def filter_result(self, result, index_name, language):
        entity = ES_MODEL_MAP.get(index_name)
        if not entity:
            raise EntityNotIndexedException("Entity not indexed or entity is not valid")
        output = []

        for item in result:

            instance = self.filter_instance(entity, item["id"], language)
            if instance:
                serializer_class = ES_SERIALIZER_MAP[index_name]
                serializer = serializer_class(instance, language=language)
                output.append(serializer.data)

        return output

    def filter_instance(self, entity, instance_id, language):
        try:
            instance = entity.objects.language(language).get(id=instance_id)
            return instance
        except entity.DoesNotExist:
            return None

    def filter_nested(self, item, language):
        for key in item:
            if key in ES_MODEL_MAP:
                if type(item[key]) is list:
                    temp = []
                    for entry in item[key]:
                        entity = ES_MODEL_MAP[key]
                        instance = self.filter_instance(entity, entry["id"], language)
                        if instance:
                            temp.append(entry)
                    item[key] = temp
                elif type(item[key]) is dict:
                    entity = ES_MODEL_MAP[key]
                    instance = self.filter_instance(entity, item[key]["id"], language)
                    if not instance:
                        item[key] = {}
        return item

    # This is used on cleaned data
    def drop_result(self, entry, query):
        keys, value = self.parse_query(query)
        check = entry
        for key in keys:

            if type(check) is list:
                matched = False
                for item in check:
                    if value.lower() in item[key].lower():
                        matched = True
                if not matched:
                    return True
                else:
                    return False

            elif issubclass(type(check), dict):
                # we are not sure if the next item is a list or not. Should not because I limit the depth
                check = entry[key]

        # Because last key in the dict. Loop will end, so check for value
        if value.lower() not in check.lower():
            return True
        return False

    def parse_query(self, query):

        key, value = query.split(":")
        keys = key.split(".")
        return keys, value

# Create your views here.
class GenericSearchView(BasePopitView, ResultFilters):
    index = None

    def get(self, request, language, index_name, **kwargs):
        search = SerializerSearch(index_name)

        q = request.GET.get("q")
        logging.warn(q)
        if not q:
            raise ParseError("q parameter is required, data format can be found at https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html")

        result = search.search(query=q, language=language)
        output = []
        logging.warn(result)
        temp = self.filter_result(result, index_name, language)
        for entry in temp:
            data = self.filter_nested(entry, language)
            if not self.drop_result(data, q):
                output.append(data)

        page = self.paginator.paginate_queryset(output, request, view=self)
        return self.paginator.get_paginated_response(page)

class EntityNotIndexedException(Exception):
    pass

class OperationNotSupportedException(Exception):
    pass<|endoftext|>


<commit_before># -*- coding: utf-8 -*-
from __future__ import unicode_literals

import logging

from blinker import Signal
from datetime import date, datetime

log = logging.getLogger(__name__)

__all__ = ('Metric', 'MetricMetaClass')

metric_catalog = {}

from udata.models import db

class MetricMetaClass(type):
    '''Ensure any child class dispatch the signals'''
    def __new__(cls, name, bases, attrs):
        from .tasks import update_metric, archive_metric

        # Ensure any child class dispatch the signals
        new_class = super(MetricMetaClass, cls).__new__(cls, name, bases, attrs)
        if new_class.model and new_class.name:
            new_class.need_update = Signal()
            new_class.need_update.connect(update_metric.delay)
            new_class.updated = Signal()
            new_class.updated.connect(archive_metric.delay)
            # register the class in the catalog
            if not new_class.model in metric_catalog:
                metric_catalog[new_class.model] = {}
            metric_catalog[new_class.model][new_class.name] = new_class
        return new_class

class Metric(object):
    model = None
    name = None
    display_name = None
    value = None
    default = 0
    value_type = int

    __metaclass__ = MetricMetaClass

    def __init__(self, target, data=None):
        self.target = target
        self.data = data

    @property
    def objects(self):
        return self.model.objects(id=self.target.id)

    def compute(self):
        log.debug('Computing value for %s(%s) metric', self.name, self.target)
        self.value = self.get_value()
        if isinstance(self.target, db.Document):
            cmd = {'set__metrics__{0}'.format(self.name): self.value}
            self.model.objects(id=self.target.id).update_one(**cmd)
        self.notify_update()

    def store(self):
        from .models import Metrics
        log.debug('Storing metric %s(%s)', self.name, self.target)
        kwargs = {self.name: self.value}
        Metrics.objects.update_daily(self.target, **kwargs)

    def get_value(self):
        '''
        This method encapsulate the metric computing logic

        Implement this method when you inherit this class.
        '''
        raise NotImplementedError

    def aggregate(self, start, end):
        '''
        This method encpsualte the metric aggregation logic.
        Override this method when you inherit this class.
        By default, it takes the last value.
        '''
        last = self.objects(level='daily', date__lte=self.iso(end), date__gte=self.iso(start)).order_by('-date').first()
        return last.values[self.name]

    def iso(self, value):
        if isinstance(value, basestring):
            return value
        elif isinstance(value, datetime):
            return value.date().isoformat()
        elif isinstance(value, date):
            return value.isoformat()
        else:
            raise ValueError('Unsupported format: {0} ({1})'.format(value, type(value)))

    def trigger_update(self):
        self.need_update.send(self)

    def notify_update(self):
        self.updated.send(self)

    @classmethod
    def aggregate_monthly(cls, queryset, month):
        raise NotImplementedError

    @classmethod
    def get_for(cls, model):
        return metric_catalog.get(model, {})

    @classmethod
    def connect(cls, *signals):
        def callback(sender, **kwargs):
            cls(sender).trigger_update()
        for signal in signals:
            signal.connect(callback, weak=False)

def init_app(app):
    # Load all core metrics
    import udata.core.site.metrics
    import udata.core.user.metrics
    import udata.core.dataset.metrics
    import udata.core.reuse.metrics
    import udata.core.organization.metrics
    import udata.core.followers.metrics

    # Load plugins API
    for plugin in app.config['PLUGINS']:
        name = 'udata.ext.{0}.metrics'.format(plugin)
        try:
            __import__(name)
        except ImportError:
            pass
        except Exception as e:
            log.error('Error importing %s: %s', name, e)
<commit_msg>Allow metrics without get_value method result<commit_after># -*- coding: utf-8 -*-
from __future__ import unicode_literals

import logging

from blinker import Signal
from datetime import date, datetime

log = logging.getLogger(__name__)

__all__ = ('Metric', 'MetricMetaClass')

metric_catalog = {}

from udata.models import db

class MetricMetaClass(type):
    '''Ensure any child class dispatch the signals'''
    def __new__(cls, name, bases, attrs):
        from .tasks import update_metric, archive_metric

        # Ensure any child class dispatch the signals
        new_class = super(MetricMetaClass, cls).__new__(cls, name, bases, attrs)
        if new_class.model and new_class.name:
            new_class.need_update = Signal()
            new_class.need_update.connect(update_metric.delay)
            new_class.updated = Signal()
            new_class.updated.connect(archive_metric.delay)
            # register the class in the catalog
            if not new_class.model in metric_catalog:
                metric_catalog[new_class.model] = {}
            metric_catalog[new_class.model][new_class.name] = new_class
        return new_class

class Metric(object):
    model = None
    name = None
    display_name = None
    value = None
    default = 0
    value_type = int

    __metaclass__ = MetricMetaClass

    def __init__(self, target, data=None):
        self.target = target
        self.data = data

    @property
    def objects(self):
        return self.model.objects(id=self.target.id)

    def compute(self):
        log.debug('Computing value for %s(%s) metric', self.name, self.target)
        self.value = self.get_value()
        if self.value is not None:
            if isinstance(self.target, db.Document):
                cmd = {'set__metrics__{0}'.format(self.name): self.value}
                self.model.objects(id=self.target.id).update_one(**cmd)
            self.notify_update()

    def store(self):
        from .models import Metrics
        log.debug('Storing metric %s(%s)', self.name, self.target)
        kwargs = {self.name: self.value}
        Metrics.objects.update_daily(self.target, **kwargs)

    def get_value(self):
        '''
        This method encapsulate the metric computing logic

        Implement this method when you inherit this class.
        '''
        raise NotImplementedError

    def aggregate(self, start, end):
        '''
        This method encpsualte the metric aggregation logic.
        Override this method when you inherit this class.
        By default, it takes the last value.
        '''
        last = self.objects(level='daily', date__lte=self.iso(end), date__gte=self.iso(start)).order_by('-date').first()
        return last.values[self.name]

    def iso(self, value):
        if isinstance(value, basestring):
            return value
        elif isinstance(value, datetime):
            return value.date().isoformat()
        elif isinstance(value, date):
            return value.isoformat()
        else:
            raise ValueError('Unsupported format: {0} ({1})'.format(value, type(value)))

    def trigger_update(self):
        self.need_update.send(self)

    def notify_update(self):
        self.updated.send(self)

    @classmethod
    def aggregate_monthly(cls, queryset, month):
        raise NotImplementedError

    @classmethod
    def get_for(cls, model):
        return metric_catalog.get(model, {})

    @classmethod
    def connect(cls, *signals):
        def callback(sender, **kwargs):
            cls(sender).trigger_update()
        for signal in signals:
            signal.connect(callback, weak=False)

def init_app(app):
    # Load all core metrics
    import udata.core.site.metrics
    import udata.core.user.metrics
    import udata.core.dataset.metrics
    import udata.core.reuse.metrics
    import udata.core.organization.metrics
    import udata.core.followers.metrics

    # Load plugins API
    for plugin in app.config['PLUGINS']:
        name = 'udata.ext.{0}.metrics'.format(plugin)
        try:
            __import__(name)
        except ImportError:
            pass
        except Exception as e:
            log.error('Error importing %s: %s', name, e)
<|endoftext|>


<commit_before>"""
Created on 05/18/2016.

@Ronak Shah

"""
import argparse
import os
import sys
import time
import glob
import pandas as pd
from subprocess import Popen, PIPE
import shlex
import re
# import multiprocessing as mp
from Queue import *
# from threading import Thread, Lock
from gridmap import Job, process_jobs

def main():
    parser = argparse.ArgumentParser(
        prog='iCallSV_dmp_wrapper.py',
        description='Run iCallSV on selected pools using MSK data',
        usage='%(prog)s [options]')
    parser.add_argument(
        "-fl",
        "--folderList",
        action="store",
        dest="folderList",
        required=True,
        metavar='folders.fof',
        help="Full path folders file of files.")
    parser.add_argument(
        "-qc",
        "--qcLocation",
        action="store",
        dest="qcLocation",
        required=True,
        metavar='/some/path/qcLocation',
        help="Full path qc files.")
    parser.add_argument(
        "-b",
        "--bamLocation",
        action="store",
        dest="bamLocation",
        required=True,
        metavar='/some/path/bamlocation',
        help="Full path bam files.")
    parser.add_argument(
        "-P",
        "--python",
        action="store",
        dest="python",
        required=False,
        default='/dmp/resources/prod/tools/system/python/production/bin/python',
        metavar='/somepath/python',
        help="Full path Pyhton executables.")
    parser.add_argument(
        "-icsv",
        "--iCallSV",
        action="store",
        dest="icsv",
        required=False,
        default='/home/shahr2/git/iCallSV-master/iCallSV/iCallSV.py',
        metavar='/somepath/iCallSV.py',
        help="Full path iCallSV.py executables.")
    parser.add_argument(
        "-conf",
        "--iCallSVconf",
        action="store",
        dest="conf",
        required=False,
        default='/home/shahr2/git/iCallSV-master/iCallSV/configuration/template_dmp.ini',
        metavar='/somepath/template.ini',
        help="Full path configuration file to run iCallSV")
    parser.add_argument(
        "-q",
        "--queue",
        action="store",
        dest="queue",
        required=False,
        default='test.q',
        metavar='all.q or clin.q',
        help="Name of the SGE queue")
    parser.add_argument(
        "-qsub",
        "--qsubPath",
        action="store",
        dest="qsub",
        required=False,
        default='/common/sge/bin/lx-amd64/qsub',
        metavar='/somepath/qsub',
        help="Full Path to the qsub executables of SGE.")
    parser.add_argument(
        "-t",
        "--threads",
        action="store",
        dest="threads",
        required=False,
        default='5',
        metavar='5',
        help="Number of Threads to be used to run iCallSV")
    parser.add_argument(
        "-v",
        "--verbose",
        action="store_true",
        dest="verbose",
        default=True,
        help="make lots of noise [default]")
    parser.add_argument(
        "-o",
        "--outDir",
        action="store",
        dest="outDir",
        required=True,
        metavar='/somepath/output',
        help="Full Path to the output dir.")

    args = parser.parse_args()
    if(args.verbose):
        print "Starting the Process to Run iCallSV."
        with open(args.folderList, 'r') as filecontent:
            for line in filecontent:
                poolName = line.rstrip()
                # print poolName
                if poolName:
                    if(args.verbose):
                        print "####Processing data for:", poolName
                    (titleFile,
                     outdir,
                     HSmetricsFileList,
                     bamFileList,
                     segmentFileList) = SetupRun(poolName,
                                                 args)
                    RunPerPool(
                        titleFile,
                        outdir,
                        HSmetricsFileList,
                        bamFileList,
                        segmentFileList,
                        args)

    if(args.verbose):
        print "Finished the Process to Run iCallSV."

def SetupRun(poolName, args):

    bamlocation = args.bamLocation + "/" + poolName
    # Get the qc data location
    baseqclocation = args.qcLocation + "/" + poolName + "/*"
    # print bamlocation,baseqclocation
    all_qc_subdirs = getSubDirs(baseqclocation)
    # print all_qc_subdirs
    qclocation = max(all_qc_subdirs, key=os.path.getmtime)
    if(os.path.isdir(bamlocation)):
        if(args.verbose):
            print "\tBAM Location:", bamlocation, "\n"
    else:
        if(args.verbose):
            print "\tBAM LOCATION", bamlocation, " DOES NOT EXISTS!!!, Please Review you bamLocation INPUT\n"
        sys.exit()
    if(os.path.isdir(qclocation)):
        if(args.verbose):
            print "\tQC Location:", qclocation, "\n"
    else:
        if(args.verbose):
            print "\tQC LOCATION", qclocation, " DOES NOT EXISTS!!!, Please Review you qcLocation INPUT\n"
    titleFile = poolName.replace("/", "")
    titleFile = qclocation + "/" + titleFile + "_title.txt"
    if(os.path.isfile(titleFile)):
        if(args.verbose):
            print "\tTitleFile:", titleFile, "\n"
    else:
        if(args.verbose):
            print "\tTitleFile:", titleFile, " DOSE NOT EXISITS!!!, Please make sure that all qcLocation have title file\n"

    segFile = qclocation + "/*_copynumber.seg"
    segFileList = glob.glob(segFile)
    if(args.verbose):
        print "\tAllSegFiles:\n"
    for file in segFileList:
        if(os.path.isfile(file)):
            if(args.verbose):
                print"\t\t", file, "\n"
        else:
            if(args.verbose):
                print "\t\t", file, "Does Not Exist!!!, Please make sure qcLocation have all segments files\n"

    HSmetricsFile = qclocation + "/*.HSmetrics.txt"
    HSmetricsFileList = glob.glob(HSmetricsFile)
    if(args.verbose):
        print "\tAllHSmetricsFiles:\n"
    for file in HSmetricsFileList:
        if(os.path.isfile(file)):
            if(args.verbose):
                print"\t\t", file, "\n"
        else:
            if(args.verbose):
                print "\t\t", file, "Does Not Exist!!!, Please make sure qcLocation have all HSmetrics.txt files\n"

    bamFile = bamlocation + "/*.bam"
    bamFileList = glob.glob(bamFile)
    if(args.verbose):
        print "\tAllBamFiles:\n"
    for file in bamFileList:
        if(os.path.isfile(file)):
            if(args.verbose):
                print"\t\t", file, "\n"
        else:
            if(args.verbose):
                print "\t\t", file, "Does Not Exist!!!, Please make sure bamLocation have all bam files\n"
    outdir = poolName.replace("/", "")
    outdir = args.outDir + "/" + outdir
    return(titleFile, outdir, HSmetricsFileList, bamFileList, segFileList)

def RunPerPool(titleFile, outdir, HSmetricsFileList, bamFileList, segmentFileList, args):
    # Run Preprocess
    titleFileDF = pd.read_csv(titleFile, sep='\t', header=0, keep_default_na='True')
    groupByPatientId = titleFileDF.groupby('Patient_ID')
    baseNames = {}
    jobs = []
    poolidRegXcompile = re.compile('.*[PoolNormal|PooledNormal].*')
    poolHsmetricsFile = filter(poolidRegXcompile.match, HSmetricsFileList).pop()
    poolbamFile = filter(poolidRegXcompile.match, bamFileList).pop()
    for patientID, group in groupByPatientId:
        print patientID, ":"
        tsampleId = ''
        tBamFile = ''
        nBamFile = ''
        basename = ''
        nsampleId = ''
        if(os.path.isdir(outdir)):
            if(args.verbose):
                print "Pool Output Dir:", outdir, "exists!!!"
        else:
            os.mkdir(outdir)
            os.chmod(outdir, 0o755)
        for count, row in group.iterrows():
            sampleId = row.loc['Sample_ID']
            patientId = row.loc['Patient_ID']
            sampleClass = row.loc['Class']
            idRegXcompile = re.compile('.*' + sampleId + '.*')
            if(sampleClass == "Tumor"):
                basename = sampleId
                tBamFile = filter(idRegXcompile.match, bamFileList).pop()
                tsampleId = sampleId
            if(sampleClass == "Normal"):
                nBamFile = filter(idRegXcompile.match, bamFileList).pop()
                nsampleId = sampleId
                nHSmetricsFile = filter(idRegXcompile.match, HSmetricsFileList).pop()
                (decision) = SelectNormal(nHSmetricsFile, poolHsmetricsFile)
                if(decision == 'UnMatched'):
                    nBamFile = poolbamFile
                else:
                    if(args.verbose):
                        print "Matched Sample\n"
        if(os.path.isfile(tBamFile) and (os.path.isfile(nBamFile))):
            jobId = "iCallSV_" + str(count) + "_" + str(basename)
            cmdList = []
            cmd = args.python + " " + args.icsv + " -sc " + args.conf + " -bbam " + nBamFile + " -abam " + \
                tBamFile + " -aId " + tsampleId + " -bId " + nsampleId + " -op " + tsampleId + " -o " + outdir
            # cmd = str(cmd)
            threads = int(args.threads)
            threads = threads + 1
            qsub_cmd = args.qsub + " -q " + args.queue + " -N " + jobId + " -o " + jobId + ".stdout" + " -e " + jobId + ".stderr" + \
                " -V -l h_vmem=6G,virtual_free=6G -pe smp " + str(threads) + " -wd " + outdir + " -sync y " + " -b y " + cmd
            print "qsub_cmd:", qsub_cmd, "\n"
            cmdList.append(qsub_cmd)
            job = Job(
                RunJob,
                cmdList,
                kwlist=None,
                cleanup=True,
                mem_free="2G",
                name=jobId,
                num_slots=1,
                queue=args.queue)
            jobs.append(job)
    print("sending function jobs to cluster")
    print("")

    job_outputs = process_jobs(
        jobs,
        max_processes=10,
        temp_dir='/dmp/analysis/SCRATCH/',
        white_list=None,
        quiet=False,
        local=False)

    print("results from each job")
    for (i, result) in enumerate(job_outputs):
        print("Job {0}- result: {1}".format(i, result))

    return

def RunJob(cmd):
    args = shlex.split(cmd)
    proc = Popen(args)
    proc.wait()
    retcode = proc.returncode
    if(retcode >= 0):
        print "I have finished running process using SGE"

'''
    #iterate over jobs and put each into the queue in sequence
    for job in jobs:
        print "inserting job into the queue: %s"%(job)
        jobqueue.put(job)
    #start some threads, each one will process one job from the queue#
    for i in range(mp.cpu_count()-1):
        th = Thread(target=processor,args = (i,jobqueue))
        th.setDaemon(True)
        th.start()
    #wait until all jobs are processed before quitting
    jobqueue.join()
    with jobqueue.mutex:
        jobqueue.queue.clear()
'''

def SelectNormal(normal, poolnormal):
    filesToProcess = [normal, poolnormal]
    fcount = 0
    coveragePerFile = []
    covgIndex = 0
    decision = ''
    for file in filesToProcess:

        with open(file, 'r') as filecontent:
            coverageForSample = 0
            linecount = 0
            for line in filecontent:
                line = line.rstrip()
                if line:
                    if line.startswith("#"):
                        linecount = linecount + 1
                        continue
                    # print linecount,line
                    data = line.rstrip('\n').split('\t')
                    if(fcount == 0):
                        if(data[0] == "BAIT_SET"):
                            for content in data:
                                # print linecount,content ,"C\n"
                                if(content == 'MEAN_TARGET_COVERAGE'):
                                    covgIndex = covgIndex
                                    # print covgIndex,"CI\n"
                                    break
                                else:
                                    covgIndex = covgIndex + 1
                        else:
                            # print fcount,covgIndex,data,"Inside\n"
                            coverageForSample = data[covgIndex]
                    if(fcount > 0):
                        if(data[0] == "BAIT_SET"):
                            continue
                        # print fcount,covgIndex,data,"All\n"
                        coverageForSample = data[covgIndex]
                    linecount = linecount + 1
        fcount = fcount + 1
        coveragePerFile.append(coverageForSample)
    mnormalCovg = coveragePerFile[0]
    umnormalCovg = coveragePerFile[1]
    if(float(mnormalCovg) > 50.0):
        decision = 'Matched'
    else:
        decision = 'UnMatched'
    return(decision)

def getSubDirs(dirLocation):
    dirs = []
    for d in glob.glob(dirLocation):
        if os.path.isdir(d):
            dirs.append(d)
    return(dirs)

def processor(i, jobqueue):
    devnull = open('/dev/null', 'w')
    if jobqueue.empty():
        print "the Queue is empty!"
        sys.exit(1)
    try:
        job = jobqueue.get()
        print "I'm operating on job item: %s\n" % i, job
        qsub_args = shlex.split(job)
        p = Popen(qsub_args, stdout=PIPE, stderr=devnull)
        jobqueue.task_done()
    except:
        print "Failed to operate on job\n"

if __name__ == "__main__":
    start_time = time.time()
    # mp.freeze_support()
    main()
    end_time = time.time()
    print("Elapsed time was %g seconds" % (end_time - start_time))
<commit_msg>Code Cleanup<commit_after>"""
Created on 05/18/2016.

@Ronak Shah

"""
import argparse
import os
import sys
import time
import glob
import pandas as pd
from subprocess import Popen, PIPE
import shlex
import re
# import multiprocessing as mp
from Queue import *
# from threading import Thread, Lock
from gridmap import Job, process_jobs

def main():
    parser = argparse.ArgumentParser(
        prog='iCallSV_dmp_wrapper.py',
        description='Run iCallSV on selected pools using MSK data',
        usage='%(prog)s [options]')
    parser.add_argument(
        "-fl",
        "--folderList",
        action="store",
        dest="folderList",
        required=True,
        metavar='folders.fof',
        help="Full path folders file of files.")
    parser.add_argument(
        "-qc",
        "--qcLocation",
        action="store",
        dest="qcLocation",
        required=True,
        metavar='/some/path/qcLocation',
        help="Full path qc files.")
    parser.add_argument(
        "-b",
        "--bamLocation",
        action="store",
        dest="bamLocation",
        required=True,
        metavar='/some/path/bamlocation',
        help="Full path bam files.")
    parser.add_argument(
        "-P",
        "--python",
        action="store",
        dest="python",
        required=False,
        default='/dmp/resources/prod/tools/system/python/production/bin/python',
        metavar='/somepath/python',
        help="Full path Pyhton executables.")
    parser.add_argument(
        "-icsv",
        "--iCallSV",
        action="store",
        dest="icsv",
        required=False,
        default='/home/shahr2/git/iCallSV-master/iCallSV/iCallSV.py',
        metavar='/somepath/iCallSV.py',
        help="Full path iCallSV.py executables.")
    parser.add_argument(
        "-conf",
        "--iCallSVconf",
        action="store",
        dest="conf",
        required=False,
        default='/home/shahr2/git/iCallSV-master/iCallSV/configuration/template_dmp.ini',
        metavar='/somepath/template.ini',
        help="Full path configuration file to run iCallSV")
    parser.add_argument(
        "-q",
        "--queue",
        action="store",
        dest="queue",
        required=False,
        default='test.q',
        metavar='all.q or clin.q',
        help="Name of the SGE queue")
    parser.add_argument(
        "-qsub",
        "--qsubPath",
        action="store",
        dest="qsub",
        required=False,
        default='/common/sge/bin/lx-amd64/qsub',
        metavar='/somepath/qsub',
        help="Full Path to the qsub executables of SGE.")
    parser.add_argument(
        "-t",
        "--threads",
        action="store",
        dest="threads",
        required=False,
        default='5',
        metavar='5',
        help="Number of Threads to be used to run iCallSV")
    parser.add_argument(
        "-v",
        "--verbose",
        action="store_true",
        dest="verbose",
        default=True,
        help="make lots of noise [default]")
    parser.add_argument(
        "-o",
        "--outDir",
        action="store",
        dest="outDir",
        required=True,
        metavar='/somepath/output',
        help="Full Path to the output dir.")

    args = parser.parse_args()
    if(args.verbose):
        print "Starting the Process to Run iCallSV."
        with open(args.folderList, 'r') as filecontent:
            for line in filecontent:
                poolName = line.rstrip()
                # print poolName
                if poolName:
                    if(args.verbose):
                        print "####Processing data for:", poolName
                    (titleFile,
                     outdir,
                     HSmetricsFileList,
                     bamFileList,
                     segmentFileList) = SetupRun(poolName,
                                                 args)
                    RunPerPool(
                        titleFile,
                        outdir,
                        HSmetricsFileList,
                        bamFileList,
                        args)

    if(args.verbose):
        print "Finished the Process to Run iCallSV."

def SetupRun(poolName, args):

    bamlocation = args.bamLocation + "/" + poolName
    # Get the qc data location
    baseqclocation = args.qcLocation + "/" + poolName + "/*"
    # print bamlocation,baseqclocation
    all_qc_subdirs = getSubDirs(baseqclocation)
    # print all_qc_subdirs
    qclocation = max(all_qc_subdirs, key=os.path.getmtime)
    if(os.path.isdir(bamlocation)):
        if(args.verbose):
            print "\tBAM Location:", bamlocation, "\n"
    else:
        if(args.verbose):
            print "\tBAM LOCATION", bamlocation, " DOES NOT EXISTS!!!, Please Review you bamLocation INPUT\n"
        sys.exit()
    if(os.path.isdir(qclocation)):
        if(args.verbose):
            print "\tQC Location:", qclocation, "\n"
    else:
        if(args.verbose):
            print "\tQC LOCATION", qclocation, " DOES NOT EXISTS!!!, Please Review you qcLocation INPUT\n"
    titleFile = poolName.replace("/", "")
    titleFile = qclocation + "/" + titleFile + "_title.txt"
    if(os.path.isfile(titleFile)):
        if(args.verbose):
            print "\tTitleFile:", titleFile, "\n"
    else:
        if(args.verbose):
            print "\tTitleFile:", titleFile, " DOSE NOT EXISITS!!!, Please make sure that all qcLocation have title file\n"

    HSmetricsFile = qclocation + "/*.HSmetrics.txt"
    HSmetricsFileList = glob.glob(HSmetricsFile)
    if(args.verbose):
        print "\tAllHSmetricsFiles:\n"
    for file in HSmetricsFileList:
        if(os.path.isfile(file)):
            if(args.verbose):
                print"\t\t", file, "\n"
        else:
            if(args.verbose):
                print "\t\t", file, "Does Not Exist!!!, Please make sure qcLocation have all HSmetrics.txt files\n"

    bamFile = bamlocation + "/*.bam"
    bamFileList = glob.glob(bamFile)
    if(args.verbose):
        print "\tAllBamFiles:\n"
    for file in bamFileList:
        if(os.path.isfile(file)):
            if(args.verbose):
                print"\t\t", file, "\n"
        else:
            if(args.verbose):
                print "\t\t", file, "Does Not Exist!!!, Please make sure bamLocation have all bam files\n"
    outdir = poolName.replace("/", "")
    outdir = args.outDir + "/" + outdir
    return(titleFile, outdir, HSmetricsFileList, bamFileList)

def RunPerPool(titleFile, outdir, HSmetricsFileList, bamFileList, args):
    # Run Preprocess
    titleFileDF = pd.read_csv(titleFile, sep='\t', header=0, keep_default_na='True')
    groupByPatientId = titleFileDF.groupby('Patient_ID')
    baseNames = {}
    jobs = []
    poolidRegXcompile = re.compile('.*[PoolNormal|PooledNormal].*')
    poolHsmetricsFile = filter(poolidRegXcompile.match, HSmetricsFileList).pop()
    poolbamFile = filter(poolidRegXcompile.match, bamFileList).pop()
    for patientID, group in groupByPatientId:
        print patientID, ":"
        tsampleId = ''
        tBamFile = ''
        nBamFile = ''
        basename = ''
        nsampleId = ''
        if(os.path.isdir(outdir)):
            if(args.verbose):
                print "Pool Output Dir:", outdir, "exists!!!"
        else:
            os.mkdir(outdir)
            os.chmod(outdir, 0o755)
        for count, row in group.iterrows():
            sampleId = row.loc['Sample_ID']
            patientId = row.loc['Patient_ID']
            sampleClass = row.loc['Class']
            idRegXcompile = re.compile('.*' + sampleId + '.*')
            if(sampleClass == "Tumor"):
                basename = sampleId
                tBamFile = filter(idRegXcompile.match, bamFileList).pop()
                tsampleId = sampleId
            if(sampleClass == "Normal"):
                nBamFile = filter(idRegXcompile.match, bamFileList).pop()
                nsampleId = sampleId
                nHSmetricsFile = filter(idRegXcompile.match, HSmetricsFileList).pop()
                (decision) = SelectNormal(nHSmetricsFile, poolHsmetricsFile)
                if(decision == 'UnMatched'):
                    nBamFile = poolbamFile
                else:
                    if(args.verbose):
                        print "Matched Sample\n"
        if(os.path.isfile(tBamFile) and (os.path.isfile(nBamFile))):
            jobId = "iCallSV_" + str(count) + "_" + str(basename)
            cmdList = []
            cmd = args.python + " " + args.icsv + " -sc " + args.conf + " -bbam " + nBamFile + " -abam " + \
                tBamFile + " -aId " + tsampleId + " -bId " + nsampleId + " -op " + tsampleId + " -o " + outdir
            # cmd = str(cmd)
            threads = int(args.threads)
            threads = threads + 1
            qsub_cmd = args.qsub + " -q " + args.queue + " -N " + jobId + " -o " + jobId + ".stdout" + " -e " + jobId + ".stderr" + \
                " -V -l h_vmem=6G,virtual_free=6G -pe smp " + str(threads) + " -wd " + outdir + " -sync y " + " -b y " + cmd
            print "qsub_cmd:", qsub_cmd, "\n"
            cmdList.append(qsub_cmd)
            job = Job(
                RunJob,
                cmdList,
                kwlist=None,
                cleanup=True,
                mem_free="2G",
                name=jobId,
                num_slots=1,
                queue=args.queue)
            jobs.append(job)
    print("sending function jobs to cluster")
    print("")

    job_outputs = process_jobs(
        jobs,
        max_processes=10,
        temp_dir='/dmp/analysis/SCRATCH/',
        white_list=None,
        quiet=False,
        local=False)

    print("results from each job")
    for (i, result) in enumerate(job_outputs):
        print("Job {0}- result: {1}".format(i, result))

    return

def RunJob(cmd):
    args = shlex.split(cmd)
    proc = Popen(args)
    proc.wait()
    retcode = proc.returncode
    if(retcode >= 0):
        print "I have finished running process using SGE"

'''
    #iterate over jobs and put each into the queue in sequence
    for job in jobs:
        print "inserting job into the queue: %s"%(job)
        jobqueue.put(job)
    #start some threads, each one will process one job from the queue#
    for i in range(mp.cpu_count()-1):
        th = Thread(target=processor,args = (i,jobqueue))
        th.setDaemon(True)
        th.start()
    #wait until all jobs are processed before quitting
    jobqueue.join()
    with jobqueue.mutex:
        jobqueue.queue.clear()
'''

def SelectNormal(normal, poolnormal):
    filesToProcess = [normal, poolnormal]
    fcount = 0
    coveragePerFile = []
    covgIndex = 0
    decision = ''
    for file in filesToProcess:

        with open(file, 'r') as filecontent:
            coverageForSample = 0
            linecount = 0
            for line in filecontent:
                line = line.rstrip()
                if line:
                    if line.startswith("#"):
                        linecount = linecount + 1
                        continue
                    # print linecount,line
                    data = line.rstrip('\n').split('\t')
                    if(fcount == 0):
                        if(data[0] == "BAIT_SET"):
                            for content in data:
                                # print linecount,content ,"C\n"
                                if(content == 'MEAN_TARGET_COVERAGE'):
                                    covgIndex = covgIndex
                                    # print covgIndex,"CI\n"
                                    break
                                else:
                                    covgIndex = covgIndex + 1
                        else:
                            # print fcount,covgIndex,data,"Inside\n"
                            coverageForSample = data[covgIndex]
                    if(fcount > 0):
                        if(data[0] == "BAIT_SET"):
                            continue
                        # print fcount,covgIndex,data,"All\n"
                        coverageForSample = data[covgIndex]
                    linecount = linecount + 1
        fcount = fcount + 1
        coveragePerFile.append(coverageForSample)
    mnormalCovg = coveragePerFile[0]
    umnormalCovg = coveragePerFile[1]
    if(float(mnormalCovg) > 50.0):
        decision = 'Matched'
    else:
        decision = 'UnMatched'
    return(decision)

def getSubDirs(dirLocation):
    dirs = []
    for d in glob.glob(dirLocation):
        if os.path.isdir(d):
            dirs.append(d)
    return(dirs)

def processor(i, jobqueue):
    devnull = open('/dev/null', 'w')
    if jobqueue.empty():
        print "the Queue is empty!"
        sys.exit(1)
    try:
        job = jobqueue.get()
        print "I'm operating on job item: %s\n" % i, job
        qsub_args = shlex.split(job)
        p = Popen(qsub_args, stdout=PIPE, stderr=devnull)
        jobqueue.task_done()
    except:
        print "Failed to operate on job\n"

if __name__ == "__main__":
    start_time = time.time()
    # mp.freeze_support()
    main()
    end_time = time.time()
    print("Elapsed time was %g seconds" % (end_time - start_time))
<|endoftext|>


<commit_before>from setuptools import setup

setup(name='fhem',
      version='0.2.0',
      description='Python API for FHEM home automation server',
      long_description='Uses socket or http(s) communication to set and get states from FHEM home automation server with optional SSL encryption and password support',
      classifiers=[
        'Development Status :: 3 - Beta',
        'License :: OSI Approved :: MIT License',
      ],
      keywords='fhem home automation',
      url='http://github.com/domschl/python-fhem',
      author='Dominik Schloesser',
      author_email='dsc@dosc.net',
      license='MIT',
      packages=['fhem'],
      zip_safe=False)
<commit_msg>setup.py version classifier fix<commit_after>from setuptools import setup

setup(name='fhem',
      version='0.2.1',
      description='Python API for FHEM home automation server',
      long_description='Uses socket or http(s) communication to set and get states from FHEM home automation server with optional SSL encryption and password support',
      classifiers=[
        'Development Status :: 4 - Beta',
        'License :: OSI Approved :: MIT License',
      ],
      keywords='fhem home automation',
      url='http://github.com/domschl/python-fhem',
      author='Dominik Schloesser',
      author_email='dsc@dosc.net',
      license='MIT',
      packages=['fhem'],
      zip_safe=False)
<|endoftext|>


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

import pyglet
from pyglet.window import Window, key
from pyglet.gl import *
import math
from basicgraphics import *
from numpy import *
#from simplui import *

pyglet.options['debug_gl'] = False
window = Window(640,640, caption = 'FieldLines', vsync = True)

#themes = [Theme('../simplui-1.0.4/themes/macos'), Theme('../simplui-1.0.4/themes/pywidget')]
#theme = 0
#frame = Frame(themes[theme], w=640, h=640)
#window.push_handlers(frame)

#dialogue = Dialogue('Inspector', x=200, y=500, content=
## add a vertical layout to hold the window contents
#    VLayout(autosizex=True, hpadding=0, children=[
#    # now add some folding boxes
#        FoldingBox('stats', content=
#        # each box needs a content layout
#            VLayout(children=[
#            # add a text label, note that this element is named...
#                Label('0.0 fps', name='fps_label')
#                ])
#            ),
#        FoldingBox('settings', content=
#            VLayout(children=[
#            # a clickable button to change the theme
#                Button('Change GUI Theme'),
#            # a slider, with label
#                HLayout(children=[
#                    Label('Segments', halign='right'),
#                    Slider(w=100, min=0.0, max=1000, name='grid'),
#                    ]),
#                Checkbox('Lines', h=100, name='vectlines'),
#                Checkbox('Grid', h=100, name='vectgrid')
#                ])
#            ),
#        ])
#    )
## add the dialogue to the frame
#frame.add( dialogue )

held_objects = set()
hovered = None
Buttons = []
fps_display = pyglet.clock.ClockDisplay()

mouseX = window.width/2
mouseY = window.height/2
update = True

zoom = 10.0
grid = 50
scale = 10

vectlines = True
vectgrid = False
useC = True

try:
    import ctypes
    clib = ctypes.CDLL("./drawlines.so")
    class vec2(ctypes.Structure):
            _fields_ = [("x", c_double),
                        ("y", c_double)]
    class pointcharge(ctypes.Structure):
            _fields_ = [("x", c_double),
                        ("y", c_double),
                        ("charge",c_double)]
    clib.field.restype = vec2
except ImportError:
    print "Ctypes not installed, switching to python (slow)"
    useC = False
except:
    print "Couldn't find drawlines.so, try running make. switching to python (slow)"
    useC = False

class Button(object):
    def __init__(self, x, y, radii, halo_colour = None, held_colour=None, charge=1.0):
        self.x, self.y = int(x), int(y)
        self.radii = radii
        self.sqradii = self.radii ** 2

        self.held = False
        self.hovered = False

        self.halo_colour = halo_colour or rand_colour()
        self.held_colour = held_colour or rand_colour()

        self.haloshape = Circle(self.radii, colour=self.halo_colour)
        self.handleshape = Circle(self.radii, colour=self.held_colour)
        self.charge = charge
    def mouse_press(self, x, y, button, modifiers):
        if self.hovered:
            held_objects.add(self)
            self.held = True
            return True

    def mouse_drag(self, x, y, dx, dy, but, mod):
        self.x += dx
        self.y += dy
        self.x = self.x % window.width
        self.y = self.y % window.height
    def mouse_release(self, x, y, button, modifiers):
        self.held = False
    def mouse_motion(self, x, y, dx, dy):
        if ((x-self.x)**2 + (y-self.y)**2) <= self.sqradii:
            global hovered
            hovered = self
            self.hovered = True
            return True
        else:
            self.hovered = False
            if hovered == self:
                hovered = None
                return True

    def key_press(self, symbol, mods):
        if self.hovered and symbol == key.DELETE:
                Buttons.remove(self)
                del self

    def draw(self):
        if self.held:
            self.handleshape.draw(self.x,self.y)
        elif self is hovered:
            self.haloshape.draw(self.x,self.y)
        point(self.x, self.y)

class ButtonEventHandler(object):
    def on_mouse_motion(self, *args):
        global mouseX
        global mouseY
        mouseX, mouseY = args[:2]
        hovered = None
        for button in Buttons:
            if button.mouse_motion(*args):
                global update
                update = True
                break

    def on_mouse_press(self, *args):
        if hovered:
            hovered.mouse_press(*args)

    def on_mouse_release(self, *args):
        for object in held_objects:
            object.mouse_release(*args)
        held_objects.clear()

    def on_draw(self):
        global update
        if update:
            glPushMatrix()
            window.clear()
            fps_display.draw()
            for button in Buttons:
                button.draw()
            if vectgrid: drawvectorfield()
            if vectlines: Cdrawfieldlines() if useC else drawfieldlines()
            glPopMatrix()
            update = False
    def on_mouse_drag(self, *args):
        global update
        for object in held_objects:
            object.mouse_drag(*args)
        update = True

    def on_key_press(self, *args):
        global vectlines; global vectgrid; global update; global useC
        global Buttons
        if args[0] == key.P:print Buttons
        if args[0] == key.C: useC = not useC
        if args[0] == key.L: vectlines = not vectlines
        if args[0] == key.G: vectgrid = not vectgrid
        if args[0] == key.B:
            Buttons.append(Button(mouseX, mouseY, 20))
        if args[0] == key.N:
            Buttons.append(Button(mouseX, mouseY, 20, charge=-1))
        elif hovered:
                hovered.key_press(*args)
        update = True

def EfieldB(pos):
    vect = [0, 0]
    for Button in Buttons:
        mousevect = (pos[0] - Button.x, pos[1] - Button.y)
        mag = sqrt(mousevect[0]**2 + mousevect[1]**2)
        scale = (Button.charge/(mag*zoom)**2)
        mousevect = (mousevect[0]/mag * scale, mousevect[1]/mag * scale)
        vect[0] += mousevect[0]
        vect[1] += mousevect[1]
    return array(vect)

def EfieldC(pos):
    pointsarray = pointcharge * len(Buttons)
    pos = vec2(*pos)
    points = pointsarray(*(pointcharge(button.x, button.y, button.charge) for button in Buttons))
    force = clib.field(pos, ctypes.c_int(len(points)), points)
    return array((force.x, force.y))

def drawvectorfield():
    for x in range(0, window.width, grid):
        for y in range(0, window.height, grid):
            vect = EfieldC(array((x,y))) if useC else EfieldB(array((x,y)))
            vect = vect/sqrt(vect.dot(vect)) * grid
            line(x, y, x+vect[0], y+vect[1])

def Cdrawfieldlines():
    pointsarray = pointcharge * len(Buttons)
    points = pointsarray(*(pointcharge(button.x, button.y, button.charge) for button in Buttons))
    numofButtons = len(Buttons)
    datatype = ((ctypes.c_double * 200)*12)*numofButtons
    data = datatype()
    clib.vectorline(ctypes.c_int(len(Buttons)),points,data)
    for cbutton,pbutton in zip(data, Buttons):
        for list in cbutton:
            #print "after",list[:10]
            line(*list, colour=pbutton.halo_colour)

def drawfieldlines():
    linesperbutton = 12
    maxits = 50
    ini = 1
    step = 20
    anglestep = (2*pi/linesperbutton)
    angles = [(math.cos(i*anglestep),math.sin(i*anglestep)) for i in range(linesperbutton)]
    points = [int() for i in range(maxits * 2)]
    for Button in Buttons:
        for angle in angles:
            end = None
            pos = array((Button.x + angle[0],angle[1] + Button.y))
            for i in range(maxits):
                points[2*i], points[(2*i)+1] = pos[0], pos[1]
                field = EfieldC(pos) if useC else EfieldB(pos)
                vect = field/sqrt(field.dot(field)) * Button.charge
                pos += vect * step
                if offscreen(pos) or nearbutton(pos):
                    end = (i+1)*2
                    break
            line(*points[:end or maxits*2], colour=Button.halo_colour)

def nearbutton(pos):
    for Button in Buttons:
        if ((Button.x-10 < pos[0] < Button.x+10) and (Button.y-10 < pos[1] < Button.y+10)): return True
    return False
def offscreen(pos):
    return not ((0 < pos[0] < window.width) and (0 < pos[1] < window.height))

window.push_handlers(ButtonEventHandler())
pyglet.app.run()
<commit_msg>added movement<commit_after>#!/usr/bin/env python

import pyglet
from pyglet.window import Window, key
from pyglet.gl import *
import math
from basicgraphics import *
from numpy import *
#from simplui import *

pyglet.options['debug_gl'] = False
window = Window(640,640, caption = 'FieldLines', vsync = True)

#themes = [Theme('../simplui-1.0.4/themes/macos'), Theme('../simplui-1.0.4/themes/pywidget')]
#theme = 0
#frame = Frame(themes[theme], w=640, h=640)
#window.push_handlers(frame)

#dialogue = Dialogue('Inspector', x=200, y=500, content=
## add a vertical layout to hold the window contents
#    VLayout(autosizex=True, hpadding=0, children=[
#    # now add some folding boxes
#        FoldingBox('stats', content=
#        # each box needs a content layout
#            VLayout(children=[
#            # add a text label, note that this element is named...
#                Label('0.0 fps', name='fps_label')
#                ])
#            ),
#        FoldingBox('settings', content=
#            VLayout(children=[
#            # a clickable button to change the theme
#                Button('Change GUI Theme'),
#            # a slider, with label
#                HLayout(children=[
#                    Label('Segments', halign='right'),
#                    Slider(w=100, min=0.0, max=1000, name='grid'),
#                    ]),
#                Checkbox('Lines', h=100, name='vectlines'),
#                Checkbox('Grid', h=100, name='vectgrid')
#                ])
#            ),
#        ])
#    )
## add the dialogue to the frame
#frame.add( dialogue )

fps_display = pyglet.clock.ClockDisplay()

Buttons = []

mouseX = window.width/2
mouseY = window.height/2
update = True

zoom = 10.0
grid = 50
scale = 10

vectlines = True
vectgrid = False
useC = True

try:
    import ctypes
    clib = ctypes.CDLL("./drawlines.so")
    class vec2(ctypes.Structure):
            _fields_ = [("x", c_double),
                        ("y", c_double)]
    class pointcharge(ctypes.Structure):
            _fields_ = [("x", c_double),
                        ("y", c_double),
                        ("charge",c_double)]
    clib.field.restype = vec2
except ImportError:
    print "Ctypes not installed, switching to python (slow)"
    useC = False
except:
    print "Couldn't find drawlines.so, try running make. switching to python (slow)"
    useC = False
class Link(object):
    def __init__(self, button1, button2, strength, length, damp=0.8):
        self.button1 = button1
        self.button2 = button2
        self.strength = strength
        self.length = length
        self.damp = damp
    def compute(self, dt):
        deltap = (self.button1.x - self.button2.x, self.button1.y - self.button2.y)
        distance = math.sqrt(deltap[0]**2 + deltap[1]**2)
        direction = (deltap[0] / distance, deltap[1] / distance)
        displacement = distance - self.length
        force = (displacement * direction[0] * self.strength - self.damp * displacement , displacement * direction[1] * self.strength - self.damp * displacement )

        self.button2.acc = (self.button1.acc[0] + force[0] * dt,self.button1.acc[0] + force[1] * dt)
        self.button1.acc = (self.button2.acc[0] + (-1.0) * force[0] * dt,self.button2.acc[1] + -1.0 * force[1] * dt)
        line(self.button1.x, self.button1.y, self.button2.x, self.button2.y)

class Button(object):
    def __init__(self, x, y, radii, halo_colour = None, held_colour=None, charge=1.0, mass = 1.0):
        self.x, self.y = int(x), int(y)
        self.radii = radii
        self.sqradii = self.radii ** 2

        self.held = False
        self.hovered = False

        self.halo_colour = halo_colour or rand_colour()
        self.held_colour = held_colour or rand_colour()

        self.haloshape = Circle(self.radii, colour=self.halo_colour)
        self.handleshape = Circle(self.radii, colour=self.held_colour)
        self.charge = charge

        self.invmass = 1.0 / mass
        self.pos = (int(x), int(y))
        self.vel = (0,0)
        self.acc = (0,0)
    def mouse_press(self, x, y, button, modifiers):
        if self.hovered:
            held_objects.add(self)
            self.held = True
            return True

    def mouse_drag(self, x, y, dx, dy, but, mod):
        self.x += dx
        self.y += dy
        self.x = self.x % window.width
        self.y = self.y % window.height
    def mouse_release(self, x, y, button, modifiers):
        self.held = False
    def mouse_motion(self, x, y, dx, dy):
        if ((x-self.x)**2 + (y-self.y)**2) <= self.sqradii:
            global hovered
            hovered = self
            self.hovered = True
            return True
        else:
            self.hovered = False
            if hovered == self:
                hovered = None
                return True

    def key_press(self, symbol, mods):
        if self.hovered and symbol == key.DELETE:
                Buttons.remove(self)
                del self

    def draw(self, dt = 1.0/20.0):
        print (self.charge * 100000 * EfieldC((self.x, self.y), [button for button in Buttons if button is not self]) * self.invmass)
        self.acc += (self.charge * 100000 * EfieldC((self.x, self.y), [button for button in Buttons if button is not self]) * self.invmass)
        #print 'acc ' ,self.acc
        self.vel += self.acc * dt
        #print 'old pos ', self.x, self.y
        self.x, self.y = (self.x, self.y) + (self.vel * dt)
        #print 'new pos ', self.x, self.y

        if self.held:
            self.handleshape.draw(self.x,self.y)
        elif self is hovered:
            self.haloshape.draw(self.x,self.y)
        self.acc = (0.0,0.0)

class ButtonEventHandler(object):
    def on_mouse_motion(self, *args):
        global mouseX
        global mouseY
        mouseX, mouseY = args[:2]
        hovered = None
        for button in Buttons:
            if button.mouse_motion(*args):
                global update
                update = True
                break

    def on_mouse_press(self, *args):
        if hovered:
            hovered.mouse_press(*args)

    def on_mouse_release(self, *args):
        for object in held_objects:
            object.mouse_release(*args)
        held_objects.clear()

    def compute(self, dt=1.0/20.0):
        global update
        update = True
        if update:
            #dt = pyglet.clock.tick()
            glPushMatrix()
            window.clear()
            fps_display.draw()
            for link in Links:
                link.compute(dt=dt)
            for button in Buttons:
                button.draw(dt=dt)
            if vectgrid: drawvectorfield()
            if vectlines: Cdrawfieldlines() if useC else drawfieldlines()
            glPopMatrix()
            update = False
    def on_mouse_drag(self, *args):
        global update
        for object in held_objects:
            object.mouse_drag(*args)
        update = True

    def on_key_press(self, *args):
        global vectlines; global vectgrid; global update; global useC
        global Buttons
        if args[0] == key.P:print Buttons
        if args[0] == key.C: useC = not useC
        if args[0] == key.L: vectlines = not vectlines
        if args[0] == key.G: vectgrid = not vectgrid
        if args[0] == key.B:
            Buttons.append(Button(mouseX, mouseY, 20))
        if args[0] == key.N:
            Buttons.append(Button(mouseX, mouseY, 20, charge=-1))
        elif hovered:
                hovered.key_press(*args)
        update = True

def EfieldB(pos):
    vect = [0, 0]
    for Button in Buttons:
        mousevect = (pos[0] - Button.x, pos[1] - Button.y)
        mag = sqrt(mousevect[0]**2 + mousevect[1]**2)
        scale = (Button.charge/(mag*zoom)**2)
        mousevect = (mousevect[0]/mag * scale, mousevect[1]/mag * scale)
        vect[0] += mousevect[0]
        vect[1] += mousevect[1]
    return array(vect)

def EfieldC(pos, buttons = Buttons):
    print 'EfieldC in', pos
    pointsarray = pointcharge * len(buttons)
    pos = vec2(*pos)
    points = pointsarray(*(pointcharge(button.x, button.y, button.charge) for button in buttons))
    force = clib.field(pos, ctypes.c_int(len(points)), points)
    print  'EfieldC out', array((force.x, force.y)), force.x, force.y
    return array((force.x, force.y))

def drawvectorfield():
    for x in range(0, window.width, grid):
        for y in range(0, window.height, grid):
            vect = EfieldC(array((x,y))) if useC else EfieldB(array((x,y)))
            vect = vect/sqrt(vect.dot(vect)) * grid
            line(x, y, x+vect[0], y+vect[1])

def Cdrawfieldlines():
    pointsarray = pointcharge * len(Buttons)
    points = pointsarray(*(pointcharge(button.x, button.y, button.charge) for button in Buttons))
    numofButtons = len(Buttons)
    datatype = ((ctypes.c_double * 200)*12)*numofButtons
    data = datatype()
    clib.vectorline(ctypes.c_int(len(Buttons)),points,data)
    for cbutton,pbutton in zip(data, Buttons):
        for list in cbutton:
            #print "after",list[:10]
            line(*list, colour=pbutton.halo_colour)

def drawfieldlines():
    linesperbutton = 12
    maxits = 50
    ini = 1
    step = 20
    anglestep = (2*pi/linesperbutton)
    angles = [(math.cos(i*anglestep),math.sin(i*anglestep)) for i in range(linesperbutton)]
    points = [int() for i in range(maxits * 2)]
    for Button in Buttons:
        for angle in angles:
            end = None
            pos = array((Button.x + angle[0],angle[1] + Button.y))
            for i in range(maxits):
                points[2*i], points[(2*i)+1] = pos[0], pos[1]
                field = EfieldC(pos) if useC else EfieldB(pos)
                vect = field/sqrt(field.dot(field)) * Button.charge
                pos += vect * step
                if offscreen(pos) or nearbutton(pos):
                    end = (i+1)*2
                    break
            line(*points[:end or maxits*2], colour=Button.halo_colour)

def nearbutton(pos):
    for Button in Buttons:
        if ((Button.x-10 < pos[0] < Button.x+10) and (Button.y-10 < pos[1] < Button.y+10)): return True
    return False
def offscreen(pos):
    return not ((0 < pos[0] < window.width) and (0 < pos[1] < window.height))

buttonevents = ButtonEventHandler()

window.push_handlers(buttonevents)
pyglet.clock.schedule_interval(buttonevents.compute, 1.0/20.0)

held_objects = set()
hovered = None
Buttons = [Button(mouseX, mouseY, 20), Button(mouseX, mouseY + 10, 20)]
Links = [Link(Buttons[0] , Buttons[1], 10.0, 100.0)]

pyglet.app.run()
<|endoftext|>


<commit_before>VERSION = (1, 0, 'beta_2')

def get_version():
    "Returns the version as a human-format string."
    v = '.'.join([str(i) for i in VERSION[:-1]])
    if VERSION[-1]:
        from django.utils.version import get_svn_revision
        v = '%s-%s-%s' % (v, VERSION[-1], get_svn_revision())
    return v
<commit_msg>Bumped version to rc1.<commit_after>VERSION = (1, 0, 'rc_1')

def get_version():
    "Returns the version as a human-format string."
    v = '.'.join([str(i) for i in VERSION[:-1]])
    if VERSION[-1]:
        from django.utils.version import get_svn_revision
        v = '%s-%s-%s' % (v, VERSION[-1], get_svn_revision())
    return v
<|endoftext|>


<commit_before>import os
# from excel_reader.openpyxl_reader import ExcelFile

from django.core.management.base import BaseCommand, CommandError
from django_excel_to_model.field_tools import get_valid_excel_field_name, get_target_field_name
from django_excel_to_model.reader import ExcelFile, XlsbFile
from ufs_tools.folder_file_processor import FolderFileProcessor
import re
import random

def rename_if_field_name_starts_with_number(model_attribute_name):
    if not (re.match("^[0-9].+", model_attribute_name) is None):
        model_attribute_name = "n" + model_attribute_name
    return model_attribute_name

class ModelCreator(object):
    reserved_keywords = ["type", "class", "for", "in", "while"]
    MAX_RECORD_LENGTH = 64000/4  # for utf8 there will be multiple byte for one char
    MAX_FIELD_NAME_LENGTH = (64-5)

    def __init__(self, full_path, header_row_start_from_0=0, sheet_index_numbered_from_0=0, class_name="YourClass"):
        super(ModelCreator, self).__init__()
        # self.mapping = mapping_dict
        # self.attr_order = attr_order_list
        self.field_num = 0
        self.indents = u" " * 4
        self.attr_list = []
        self.mapping_dict = {}
        self.model_code_lines = []
        self.invalid_field_name = u"__invalid"
        self.attr_list_code_lines = []
        self.mapping_code_lines = []
        try:
            excel_file = ExcelFile(full_path)
        except Exception:
            excel_file = XlsbFile(full_path)
        self.worksheet = excel_file.get_sheet(sheet_index_numbered_from_0)
        # self.header = self.worksheet.get_header_raw(header_row_start_from_0)
        self.header = self.worksheet.init_header_raw(header_row_start_from_0)
        self.class_name = class_name
        self.field_len_definition = 256

    def create_model(self, data_start_row=1):
        code = self.get_mapping_and_attr()
        attr_order = None
        mapping = None
        exec code

        res = [u"", u"", u"# @python_2_unicode_compatible",
               u"class %s(models.Model):" % self.class_name]
        for row_data_dict in self.worksheet.enumerate(data_start_row):
            for key in attr_order:
                if key == "":
                    continue
                help_text = get_valid_excel_field_name(key)

                first_part = u'%s%s = models.CharField(max_length=%s, help_text=_("""' % \
                             (self.indents, mapping[key], self.field_len_definition)
                declaration = first_part + help_text + u'"""), null=True, blank=True, verbose_name="""'+help_text+'""")'
                res.append(declaration)
            break
        res.append(self.indents + u'data_import_id = models.CharField(max_length=TEXT_LENGTH_128, '
                                  u'help_text=_("Id for this import"), null=True, blank=True)')
        res.append(self.indents + u'')
        res.append(self.indents + u'# def __str__(self):')
        res.append(self.indents + u'# ' + self.indents + u'return "%s" % self.name')
        self.model_code_lines = res
        return u"\n".join(res)

    def get_default_field_len_definition(self):
        max_len_for_each_field = int(self.MAX_RECORD_LENGTH / self.field_num)
        if max_len_for_each_field == 0:
            raise "Too many fields"
        max_target_len = 1024
        while (max_target_len & max_len_for_each_field) == 0:
            max_target_len >>= 1
        field_len_definition = u"TEXT_LENGTH_" + str(max_target_len)
        return field_len_definition

    def create_mapping(self, target_mapping_name="mapping"):
        self.mapping_code_lines = ["%s = {" % target_mapping_name, ]

        self.create_field_title_to_attr_name_mapping()

        for key in self.mapping_dict:
            self.mapping_code_lines.append(self.indents + 'u"""%s""": u"%s",' % (key, self.mapping_dict[key]))
            self.field_num += 1

        self.mapping_code_lines.append("}")

        self.field_len_definition = self.get_default_field_len_definition()

    def create_field_title_to_attr_name_mapping(self):
        for col in self.header:
            if col == "":
                self.mapping_dict[u""] = self.invalid_field_name
            else:
                field_title_str = get_valid_excel_field_name(col)
                model_attribute_name = self.get_attribute_name(col)
                self.mapping_dict[field_title_str] = model_attribute_name

    def get_attribute_name(self, col):
        model_attribute_name = get_target_field_name(col).lower()
        model_attribute_name = self.rename_if_field_name_is_keyword(model_attribute_name)
        model_attribute_name = self.trim_if_field_name_too_long(model_attribute_name)
        model_attribute_name = model_attribute_name.strip("_")
        model_attribute_name = self.add_number_suffix_if_duplicated_field_name(model_attribute_name)
        model_attribute_name = rename_if_field_name_starts_with_number(model_attribute_name)
        return model_attribute_name

    def rename_if_field_name_is_keyword(self, model_attribute_name):
        if model_attribute_name in self.reserved_keywords:
            model_attribute_name += "item_"
        return model_attribute_name

    def trim_if_field_name_too_long(self, model_attribute_name):
        if len(model_attribute_name) > self.MAX_FIELD_NAME_LENGTH:
            model_attribute_name = model_attribute_name[0:self.MAX_FIELD_NAME_LENGTH]
        return model_attribute_name

    def add_number_suffix_if_duplicated_field_name(self, model_attribute_name):
        if model_attribute_name in self.mapping_dict:
            model_attribute_name += "_%d" % random.randint(0, 999)
        return model_attribute_name

    def create_attr_list_code_lines(self):
        self.attr_list_code_lines.append("attr_order = [")
        for col in self.header:
            name = get_valid_excel_field_name(unicode(col))
            if not (name in self.attr_list):
                self.attr_list.append(name)
                self.attr_list_code_lines.append(self.indents + 'u"""%s""",' % name)

        self.attr_list_code_lines.append("]")

    def get_mapping_and_attr(self):
        res = [u"from django.db import models",
               u"from django.utils.translation import ugettext as _",
               u"from six import python_2_unicode_compatible",
               u"from djangoautoconf.model_utils.len_definitions import %s, TEXT_LENGTH_128" % self.field_len_definition,
               u"",
               u""]
        res += self.mapping_code_lines + ["", ""]
        res += self.attr_list_code_lines
        return "\n".join(res)

    def create_mapping_for_excel(self):
        self.create_mapping("mapping")
        self.create_attr_list_code_lines()
        return self.get_mapping_and_attr()

class ExcelFileProcessor(FolderFileProcessor):
    def __init__(self, files_folder=""):
        super(ExcelFileProcessor, self).__init__(files_folder)
        self.has_processed_once = False

    def is_need_process(self, file_path):
        return (not self.has_processed_once) and (not ("~" in file_path))

    def process_file(self, full_path):
        self.has_processed_once = True
        m = ModelCreator(full_path)
        print m.create_mapping_for_excel()
        print m.create_model()

def create_model_and_import_script():
    processor = ExcelFileProcessor(os.sep.join(["data", "dumping_excel_file"]))
    processor.process_files()

class Command(BaseCommand):
    help = 'Create model script from excel'

    def handle(self, *args, **options):
        create_model_and_import_script()
<commit_msg>Fix issue when only title line for the spreadsheet is given.<commit_after>import os
# from excel_reader.openpyxl_reader import ExcelFile

from django.core.management.base import BaseCommand, CommandError
from django_excel_to_model.field_tools import get_valid_excel_field_name, get_target_field_name
from django_excel_to_model.reader import ExcelFile, XlsbFile
from ufs_tools.folder_file_processor import FolderFileProcessor
import re
import random

def rename_if_field_name_starts_with_number(model_attribute_name):
    if not (re.match("^[0-9].+", model_attribute_name) is None):
        model_attribute_name = "n" + model_attribute_name
    return model_attribute_name

class ModelCreator(object):
    reserved_keywords = ["type", "class", "for", "in", "while"]
    MAX_RECORD_LENGTH = 64000/4  # for utf8 there will be multiple byte for one char
    MAX_FIELD_NAME_LENGTH = (64-5)

    def __init__(self, full_path, header_row_start_from_0=0, sheet_index_numbered_from_0=0, class_name="YourClass"):
        super(ModelCreator, self).__init__()
        # self.mapping = mapping_dict
        # self.attr_order = attr_order_list
        self.field_num = 0
        self.indents = u" " * 4
        self.attr_list = []
        self.mapping_dict = {}
        self.model_code_lines = []
        self.invalid_field_name = u"__invalid"
        self.attr_list_code_lines = []
        self.mapping_code_lines = []
        try:
            excel_file = ExcelFile(full_path)
        except Exception:
            excel_file = XlsbFile(full_path)
        self.worksheet = excel_file.get_sheet(sheet_index_numbered_from_0)
        # self.header = self.worksheet.get_header_raw(header_row_start_from_0)
        self.header = self.worksheet.init_header_raw(header_row_start_from_0)
        self.class_name = class_name
        self.field_len_definition = 256

    def create_model(self, data_start_row=1):
        code = self.get_mapping_and_attr()
        attr_order = None
        mapping = None
        exec code

        res = [u"", u"", u"# @python_2_unicode_compatible",
               u"class %s(models.Model):" % self.class_name]

        for key in attr_order:
            if key == "":
                continue
            help_text = get_valid_excel_field_name(key)

            first_part = u'%s%s = models.CharField(max_length=%s, help_text=_("""' % \
                         (self.indents, mapping[key], self.field_len_definition)
            declaration = first_part + help_text + u'"""), null=True, blank=True, verbose_name="""'+help_text+'""")'
            res.append(declaration)

        res.append(self.indents + u'data_import_id = models.CharField(max_length=TEXT_LENGTH_128, '
                                  u'help_text=_("Id for this import"), null=True, blank=True)')
        res.append(self.indents + u'')
        res.append(self.indents + u'# def __str__(self):')
        res.append(self.indents + u'# ' + self.indents + u'return "%s" % self.name')
        self.model_code_lines = res
        return u"\n".join(res)

    def get_default_field_len_definition(self):
        max_len_for_each_field = int(self.MAX_RECORD_LENGTH / self.field_num)
        if max_len_for_each_field == 0:
            raise "Too many fields"
        max_target_len = 1024
        while (max_target_len & max_len_for_each_field) == 0:
            max_target_len >>= 1
        field_len_definition = u"TEXT_LENGTH_" + str(max_target_len)
        return field_len_definition

    def create_mapping(self, target_mapping_name="mapping"):
        self.mapping_code_lines = ["%s = {" % target_mapping_name, ]

        self.create_field_title_to_attr_name_mapping()

        for key in self.mapping_dict:
            self.mapping_code_lines.append(self.indents + 'u"""%s""": u"%s",' % (key, self.mapping_dict[key]))
            self.field_num += 1

        self.mapping_code_lines.append("}")

        self.field_len_definition = self.get_default_field_len_definition()

    def create_field_title_to_attr_name_mapping(self):
        for col in self.header:
            if col == "":
                self.mapping_dict[u""] = self.invalid_field_name
            else:
                field_title_str = get_valid_excel_field_name(col)
                model_attribute_name = self.get_attribute_name(col)
                self.mapping_dict[field_title_str] = model_attribute_name

    def get_attribute_name(self, col):
        model_attribute_name = get_target_field_name(col).lower()
        model_attribute_name = self.rename_if_field_name_is_keyword(model_attribute_name)
        model_attribute_name = self.trim_if_field_name_too_long(model_attribute_name)
        model_attribute_name = model_attribute_name.strip("_")
        model_attribute_name = self.add_number_suffix_if_duplicated_field_name(model_attribute_name)
        model_attribute_name = rename_if_field_name_starts_with_number(model_attribute_name)
        return model_attribute_name

    def rename_if_field_name_is_keyword(self, model_attribute_name):
        if model_attribute_name in self.reserved_keywords:
            model_attribute_name += "item_"
        return model_attribute_name

    def trim_if_field_name_too_long(self, model_attribute_name):
        if len(model_attribute_name) > self.MAX_FIELD_NAME_LENGTH:
            model_attribute_name = model_attribute_name[0:self.MAX_FIELD_NAME_LENGTH]
        return model_attribute_name

    def add_number_suffix_if_duplicated_field_name(self, model_attribute_name):
        if model_attribute_name in self.mapping_dict:
            model_attribute_name += "_%d" % random.randint(0, 999)
        return model_attribute_name

    def create_attr_list_code_lines(self):
        self.attr_list_code_lines.append("attr_order = [")
        for col in self.header:
            name = get_valid_excel_field_name(unicode(col))
            if not (name in self.attr_list):
                self.attr_list.append(name)
                self.attr_list_code_lines.append(self.indents + 'u"""%s""",' % name)

        self.attr_list_code_lines.append("]")

    def get_mapping_and_attr(self):
        res = [u"from django.db import models",
               u"from django.utils.translation import ugettext as _",
               u"from six import python_2_unicode_compatible",
               u"from djangoautoconf.model_utils.len_definitions import %s, TEXT_LENGTH_128" % self.field_len_definition,
               u"",
               u""]
        res += self.mapping_code_lines + ["", ""]
        res += self.attr_list_code_lines
        return "\n".join(res)

    def create_mapping_for_excel(self):
        self.create_mapping("mapping")
        self.create_attr_list_code_lines()
        return self.get_mapping_and_attr()

class ExcelFileProcessor(FolderFileProcessor):
    def __init__(self, files_folder=""):
        super(ExcelFileProcessor, self).__init__(files_folder)
        self.has_processed_once = False

    def is_need_process(self, file_path):
        return (not self.has_processed_once) and (not ("~" in file_path))

    def process_file(self, full_path):
        self.has_processed_once = True
        m = ModelCreator(full_path)
        print m.create_mapping_for_excel()
        print m.create_model()

def create_model_and_import_script():
    processor = ExcelFileProcessor(os.sep.join(["data", "dumping_excel_file"]))
    processor.process_files()

class Command(BaseCommand):
    help = 'Create model script from excel'

    def handle(self, *args, **options):
        create_model_and_import_script()
<|endoftext|>


<commit_before># Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""About information (version, etc) for Firebase Admin SDK."""

__version__ = '4.1.0'
__title__ = 'firebase_admin'
__author__ = 'Firebase'
__license__ = 'Apache License 2.0'
__url__ = 'https://firebase.google.com/docs/admin/setup/'
<commit_msg>[chore] Release 4.2.0 (#457)<commit_after># Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""About information (version, etc) for Firebase Admin SDK."""

__version__ = '4.2.0'
__title__ = 'firebase_admin'
__author__ = 'Firebase'
__license__ = 'Apache License 2.0'
__url__ = 'https://firebase.google.com/docs/admin/setup/'
<|endoftext|>