<commit_before>import os
import sys
import time
import operator
import logging
import requests
import json
import re
import docx
import subprocess
import codecs

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from watchdog.events import FileModifiedEvent
from watchdog.events import FileCreatedEvent

from pdfminer.pdfpage import PDFPage
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument

from nltk.stem import WordNetLemmatizer

class GamificationHandler(FileSystemEventHandler):

    def __init__(self, paper_filename, publish_url, paper_id):
        FileSystemEventHandler.__init__(self) # super init

        self.paper_filename = paper_filename
        self.publish_url = publish_url
        self.paper_id = paper_id

        self.reset_stats()

        logging.info("Creating a GamificationHandler with paper: " + paper_filename +
            " publish_url: " + publish_url +
            " and paper id: " + paper_id
        )

    def reset_stats(self):
        self.stats = {}
        self.words = {}
        self.paragraphs = []
        self.num_words = 0
        self.total_word_len = 0
        self.pages = None

    def on_created(self, event):
        # MAIN CALLBACK - a file got created
        logging.info("Create event occurred: " + event.src_path )
        if type(event) == FileCreatedEvent:
            logging.info("A file was created: " + event.src_path)

            self.analyze_file_event(event)

    def on_modified(self, event):
        # MAIN CALLBACK - a file got modified
        logging.info("Modify event occurred: " + event.src_path)
        if type(event) == FileModifiedEvent:
            logging.info("A file was modified: " + event.src_path)

            self.analyze_file_event(event)

    def analyze_file_event(self, event):
        paper_path = os.path.abspath(self.paper_filename)
        logging.info("Checking if it was the paper: " + paper_path)

        if paper_path == event.src_path:
            logging.info("Paper change detected, calculating statistics ...")
            self.analyze_paper()

    def analyze_paper(self):
        self.calculate_statistics()
        logging.info("Publishing ...")
        self.publish()
        logging.info("Published!")

    def parse_paragraphs(self, text):
        # Will only work for markdown elements
        #   divided by '##' markers
        #   or for pdf like chapters, e.g. \n\n 2 Conclusion \n\n
        is_markdown = False
        is_pdf = False

        lines = text.split('\n')
        for index, line in enumerate(lines):
            if line.startswith('## '):
                is_markdown = True
                break
        if self.paper_filename.endswith('.pdf'):
            is_pdf = True

            headlines = []
            with open(self.paper_filename, 'rb') as pdf:
                parser = PDFParser(pdf)
                document = PDFDocument(parser)

                # Get the outlines of the document.
                outlines = document.get_outlines()

                for (level, title, _, _, _) in outlines:
                    if level == 1:
                        headlines.append(title)

            compressed_headlines = list(h.replace(' ', '').lower()\
                for h in headlines)

        if not (is_pdf or is_markdown):
            return

        old_headline = ""
        lines = text.split('\n')
        for index, line in enumerate(lines):
            compressed_line = line.replace(' ', '').lower()
            # Check for a headline in either markdown or pdf
            if ( (is_markdown and line.startswith('## ')) or
                (is_pdf and compressed_line in compressed_headlines and
                    lines[index-1].strip() == "" and
                    lines[index+1].strip() == "" ) ):

                if old_headline != "":
                    # Count previous paragraph
                    paragraph = text.split(old_headline)[1].split(line)[0]
                    if is_pdf:
                        old_headline = headlines[compressed_headlines.index(
                            old_headline.replace(' ', '').lower())]
                    self.count_paragraph_words(old_headline, paragraph)
                old_headline = line

        # Count last paragraph
        if old_headline != "":
            paragraph = text.split(old_headline)[1]
            if is_pdf:
                old_headline = headlines[compressed_headlines.index(
                    old_headline.replace(' ', '').lower())]
            self.count_paragraph_words(old_headline, paragraph)

    def count_paragraph_words(self, line, paragraph):
        num_words = len(re.findall(r"[\w']+", paragraph))
        self.paragraphs.append((line.replace('#', '').strip(), num_words))

    def parse_text_statistics(self, text):
        wnl = WordNetLemmatizer()
        for w in text:
            word = wnl.lemmatize(w.strip().lower())

            # Add to total_word_len
            # to determine average word length later
            self.total_word_len += len(word)

            # Count distinct words with occurrences
            if word not in self.words:
                self.words[word] = 0
            self.words[word] += 1

            # Count all words
            self.num_words += 1

    def get_pages(self):
        fp = open(self.paper_filename, 'rb')
        self.pages = 0
        for page in PDFPage.get_pages(fp):
            self.pages += 1
        fp.close()

    def parse_pdf_file(self):
        # Convert pdf to txt
        tmp_filename = "tmpExtracted.txt"
        returnval = subprocess.call(["pdf2txt.py", "-o", tmp_filename, self.paper_filename])
        if returnval == 0:
            # Analyse plain text
            logging.info("Successfully converted pdf to txt")
            text = self.analyze_file(tmp_filename)
            self.parse_paragraphs(text)
            self.get_pages()

    def parse_word_file(self):
        # Read file
        document = docx.Document(self.paper_filename)
        text = ""
        for p in document.paragraphs:
            text += p.text + '\n'

        word_split = re.findall(r"[\w']+", text)

        # Analyse
        self.parse_text_statistics(word_split)

    def parse_text_file(self):
        text = self.analyze_file(self.paper_filename)
        self.parse_paragraphs(text)

    def analyze_file(self, filename):
        f = codecs.open(filename, "r", "utf-8")
        text = ""
        for line in f.readlines():
            text += line
            word_split = re.findall(r"[\w']+", line)
            # Analyse
            self.parse_text_statistics(word_split)

        f.close()
        return text

    def parse_file(self):
        logging.info("\tParsing the paper ...")
        if self.paper_filename.endswith(".docx"):
            logging.info("\t\tusing docx parser ...")
            self.parse_word_file()
        elif self.paper_filename.endswith(".pdf"):
            logging.info("\t\tusing pdf parser ...")
            self.parse_pdf_file()
        else:
            logging.info("\t\tusing txt parser ...")
            self.parse_text_file()

    def calculate_statistics(self):
        self.reset_stats()
        self.parse_file()

        # By now, text-statistics should be saved in instance variables

        # Determine interesting words
        logging.info("\tCalculating interesting words ...")
        interesting_words = self.get_interesting_words(40)

        # Determine average word length
        logging.info("\tCalculating average word length ...")
        avg_len = float(self.total_word_len) / float(self.num_words)

        # Determine Oxford coverage
        logging.info("\tCalculating oxford coverage ...")
        oxford_coverage = self.get_coverage("./oxford.txt")

        # Determine Fancy word coverage
        logging.info("\tCalculating fancy words coverage ...")
        fancy_coverage = self.get_coverage("./fancy.txt")

        # Determine academic word list coverage
        logging.info("\tCalculating academic word list coverage ...")
        awl_coverage = self.get_awl_coverage("./awl.txt")

        # Build stats together
        logging.info("\tBuilding stats together ...")

        self.stats = {
            "num_words" : self.num_words,
            "different_words" : len(self.words),
            "avg_len" : avg_len,
            "paragraphs": self.paragraphs,
            "interesting_words": interesting_words,
            "oxford_coverage" : {
                "total" : oxford_coverage["total"],
                "num_hits": len(oxford_coverage["hits"])
            },
            "fancy_coverage" : {
                "total" : fancy_coverage["total"],
                "num_hits": len(fancy_coverage["hits"])
            },
            "awl_coverage" : {
                "words_total": awl_coverage["words_total"],
                "words_hits": awl_coverage["words_hits"],
                "category_total": awl_coverage["category_total"],
                "category_num_hits": awl_coverage["category_num_hits"],
                "category_hits": awl_coverage["category_hits"]
            }
        }

        if self.pages != None:
            self.stats["pages"] = self.pages

        logging.info("\tStats: " + str(self.stats))

    def get_interesting_words(self, num):
        sorted_words = sorted(self.words.iteritems(), key=operator.itemgetter(1), reverse=True)
        interesting_words = []

        num = min(num, len(sorted_words))
        min_len = 10

        while len(interesting_words) != num: # As long as we don't have as many words as we want
            for word in sorted_words:
                if len(word[0]) >= min_len:
                    if word[1] == 1:
                        # Word only occurs once in the text
                        # -> since sorted_words is sorted by occurrence:
                        #    break and go down with min word length
                        break
                    if word not in interesting_words:
                        interesting_words.append(word)
                if len(interesting_words) == num:
                    # Got enough words, break will break both loops
                    break
            min_len -= 1
            if min_len < 2: # Text contains really few words, we just have to add them, until we have enough
                for word in sorted_words:
                    if word not in interesting_words:
                        interesting_words.append(word)
                        if len(interesting_words) == num:
                            # Got enough words, break will break both loops
                            break

        # Sort result and return
        interesting_words = sorted(interesting_words, key=operator.itemgetter(1), reverse=True)
        return interesting_words

    def get_coverage(self, filename):
        """ Reads a list of words and compares it to the own words"""
        words = []
        num_words = 0
        # Count and compare
        f = open(filename)
        for word in f.readlines():
            if word.strip() != "":
                words.append(word.strip().lower())
                num_words += 1
        f.close()

        hits = set(words).intersection(set(self.words.keys()))

        return { "total": num_words, "hits": list(hits)}

    def get_awl_coverage(self, filename):
        words = {}
        f = open(filename)

        category = ""
        for word in f.readlines():
            if not word.startswith('\t'):
                category = word.strip()
            words[word.strip()] = category

        hits = set(words.keys()).intersection(set(self.words.keys()))

        category_hits = {}
        for category in set(words.values()):
            category_hits[category] = 0

        for hit in hits:
            category_hits[words[hit]] += 1

        category_num_hits = 0
        for key in category_hits.keys():
            if category_hits[key] > 0:
                category_num_hits += 1

        return {
            "words_total": len(words),
            "words_hits": len(list(hits)),
            "category_total": len(list(set(words.values()))),
            "category_num_hits": category_num_hits,
            "category_hits": category_hits
        }

    def publish(self):
        payload = {"stats" : json.dumps(self.stats)}
        r = requests.put(self.publish_url + "/papers/" + self.paper_id + ".json", data=payload)

def set_paper_alive(publish_url, paper_id, alive):
    payload = {"alive" : str(alive).lower()}
    r = requests.put(publish_url + "/papers/" + paper_id + ".json", params=payload)

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')
    if len(sys.argv) != 4:
        print "Usage: python tracker.py <paper-file> <publish-host> <paper-id>"
        sys.exit()

    # Parse command line params
    filename = sys.argv[1]
    publish_url = sys.argv[2]
    paper_id = sys.argv[3]

    path = os.path.dirname(os.path.abspath(filename))

    # Enable "Currently writing..."
    set_paper_alive(publish_url, paper_id, True);

    # Observer setup
    event_handler = GamificationHandler(filename, publish_url, paper_id)
    observer = Observer()
    logging.info("Starting observer with watch path: " + path)
    observer.schedule(event_handler, path=path, recursive=True)
    # Observer start
    observer.start()
    logging.info("Observer started.")

    # Trigger an initial paper analysis
    event_handler.analyze_paper()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        # Disable "Currently writing..."
        set_paper_alive(publish_url, paper_id, False);
        observer.stop()
        observer.join()
<commit_msg>Refactor paragraph parsing<commit_after>import os
import sys
import time
import operator
import logging
import requests
import json
import re
import docx
import subprocess
import codecs

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from watchdog.events import FileModifiedEvent
from watchdog.events import FileCreatedEvent

from pdfminer.pdfpage import PDFPage
from pdfminer.pdfparser import PDFParser
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfdocument import PDFNoOutlines

from nltk.stem import WordNetLemmatizer

class GamificationHandler(FileSystemEventHandler):

    def __init__(self, paper_filename, publish_url, paper_id):
        FileSystemEventHandler.__init__(self) # super init

        self.paper_filename = paper_filename
        self.is_pdf = paper_filename.endswith('pdf')

        self.publish_url = publish_url
        self.paper_id = paper_id

        self.reset_stats()

        logging.info("Creating a GamificationHandler with paper: " + paper_filename +
            " publish_url: " + publish_url +
            " and paper id: " + paper_id
        )

    def reset_stats(self):
        self.stats = {}
        self.words = {}
        self.paragraphs = []
        self.num_words = 0
        self.total_word_len = 0
        self.pages = None

    def on_created(self, event):
        # MAIN CALLBACK - a file got created
        logging.info("Create event occurred: " + event.src_path )
        if type(event) == FileCreatedEvent:
            logging.info("A file was created: " + event.src_path)

            self.analyze_file_event(event)

    def on_modified(self, event):
        # MAIN CALLBACK - a file got modified
        logging.info("Modify event occurred: " + event.src_path)
        if type(event) == FileModifiedEvent:
            logging.info("A file was modified: " + event.src_path)

            self.analyze_file_event(event)

    def analyze_file_event(self, event):
        paper_path = os.path.abspath(self.paper_filename)
        logging.info("Checking if it was the paper: " + paper_path)

        if paper_path == event.src_path:
            logging.info("Paper change detected, calculating statistics ...")
            self.analyze_paper()

    def analyze_paper(self):
        self.reset_stats()
        self.parse_file()
        self.calculate_statistics()
        logging.info("Publishing ...")
        self.publish()
        logging.info("Published!")

    def parse_paragraphs(self, text):
        # Will only work for markdown elements
        #   divided by '##' markers
        #   or for pdf like chapters, e.g. \n\n 2 Conclusion \n\n
        lines = text.split('\n')
        headlines = []

        if self.is_pdf:
            with open(self.paper_filename, 'rb') as pdf:
                parser = PDFParser(pdf)
                document = PDFDocument(parser)

                try:
                    outlines = document.get_outlines()
                    for (level, title, _, _, _) in outlines:
                        if level == 1:
                            headlines.append(title)
                except PDFNoOutlines:
                    logging.info("No outline found -> skipping paragraph search...")
        else: # check markdown headlines
            for index, line in enumerate(lines):
                if line.startswith('## '):
                    headlines.append(line)

        if len(headlines) > 0:
            self.count_paragraphs(text, lines, headlines)

    def compress_line(self, line):
        return line.replace(' ', '').lower()

    def count_paragraphs(self, text, lines, headlines):
        old_headline = ""
        compressed_headlines = list(self.compress_line(h) for h in headlines)

        for line in lines:
            compressed_line = self.compress_line(line)

            if line in headlines or compressed_line in compressed_headlines:
                if old_headline != "":
                    # Count previous paragraph
                    paragraph = text.split(old_headline)[1].split(line)[0]
                    if self.is_pdf:
                        old_headline = headlines[compressed_headlines.index(compressed_line) - 1]
                    self.count_paragraph_words(old_headline, paragraph)
                old_headline = line

        # Count last paragraph
        if old_headline != "":
            paragraph = text.split(old_headline)[1]
            if self.is_pdf:
                old_headline = headlines[-1]
            self.count_paragraph_words(old_headline, paragraph)

    def count_paragraph_words(self, line, paragraph):
        num_words = len(re.findall(r"[\w']+", paragraph))
        self.paragraphs.append((line.replace('#', '').strip(), num_words))

    def parse_text_statistics(self, text):
        wnl = WordNetLemmatizer()
        for w in text:
            word = wnl.lemmatize(w.strip().lower())

            # Add to total_word_len
            # to determine average word length later
            self.total_word_len += len(word)

            # Count distinct words with occurrences
            if word not in self.words:
                self.words[word] = 0
            self.words[word] += 1

            # Count all words
            self.num_words += 1

    def get_pages(self):
        fp = open(self.paper_filename, 'rb')
        self.pages = 0
        for page in PDFPage.get_pages(fp):
            self.pages += 1
        fp.close()

    def parse_pdf_file(self):
        # Convert pdf to txt
        tmp_filename = "tmpExtracted.txt"
        pdf_convert_exit_id = subprocess.call(["pdf2txt.py", "-o", tmp_filename, self.paper_filename])
        if pdf_convert_exit_id == 0:
            logging.info("\t\t\tSuccessfully converted pdf to txt")
            # Analyse plain text
            logging.info("\t\t\tAnalyzing file")
            text = self.analyze_file(tmp_filename)
            logging.info("\t\t\tParsing paragraphs ...")
            self.parse_paragraphs(text)
            logging.info("\t\t\tGetting pages ...")
            self.get_pages()

    def parse_word_file(self):
        # Read file
        document = docx.Document(self.paper_filename)
        text = ""
        for p in document.paragraphs:
            text += p.text + '\n'

        word_split = re.findall(r"[\w']+", text)

        # Analyse
        self.parse_text_statistics(word_split)

    def parse_text_file(self):
        text = self.analyze_file(self.paper_filename)
        self.parse_paragraphs(text)

    def analyze_file(self, filename):
        f = codecs.open(filename, "r", "utf-8")
        text = ""
        for line in f.readlines():
            text += line
            word_split = re.findall(r"[\w']+", line)
            # Analyse
            self.parse_text_statistics(word_split)

        f.close()
        return text

    def parse_file(self):
        logging.info("\tParsing the paper ...")
        if self.paper_filename.endswith(".docx"):
            logging.info("\t\tusing docx parser ...")
            self.parse_word_file()
        elif self.paper_filename.endswith(".pdf"):
            logging.info("\t\tusing pdf parser ...")
            self.parse_pdf_file()
        else:
            logging.info("\t\tusing txt parser ...")
            self.parse_text_file()

    def calculate_statistics(self):
        # By now, text-statistics should be saved in instance variables

        # Determine interesting words
        logging.info("\tCalculating interesting words ...")
        interesting_words = self.get_interesting_words(40)

        # Determine average word length
        logging.info("\tCalculating average word length ...")
        avg_len = float(self.total_word_len) / float(self.num_words)

        # Determine Oxford coverage
        logging.info("\tCalculating oxford coverage ...")
        oxford_coverage = self.get_coverage("./oxford.txt")

        # Determine Fancy word coverage
        logging.info("\tCalculating fancy words coverage ...")
        fancy_coverage = self.get_coverage("./fancy.txt")

        # Determine academic word list coverage
        logging.info("\tCalculating academic word list coverage ...")
        awl_coverage = self.get_awl_coverage("./awl.txt")

        # Build stats together
        logging.info("\tBuilding stats together ...")

        self.stats = {
            "num_words" : self.num_words,
            "different_words" : len(self.words),
            "avg_len" : avg_len,
            "paragraphs": self.paragraphs,
            "interesting_words": interesting_words,
            "oxford_coverage" : {
                "total" : oxford_coverage["total"],
                "num_hits": len(oxford_coverage["hits"])
            },
            "fancy_coverage" : {
                "total" : fancy_coverage["total"],
                "num_hits": len(fancy_coverage["hits"])
            },
            "awl_coverage" : {
                "words_total": awl_coverage["words_total"],
                "words_hits": awl_coverage["words_hits"],
                "category_total": awl_coverage["category_total"],
                "category_num_hits": awl_coverage["category_num_hits"],
                "category_hits": awl_coverage["category_hits"]
            }
        }

        if self.pages != None:
            self.stats["pages"] = self.pages

        logging.info("\tStats: " + str(self.stats))

    def get_interesting_words(self, num):
        sorted_words = sorted(self.words.iteritems(), key=operator.itemgetter(1), reverse=True)
        interesting_words = []

        num = min(num, len(sorted_words))
        min_len = 10

        while len(interesting_words) != num: # As long as we don't have as many words as we want
            for word in sorted_words:
                if len(word[0]) >= min_len:
                    if word[1] == 1:
                        # Word only occurs once in the text
                        # -> since sorted_words is sorted by occurrence:
                        #    break and go down with min word length
                        break
                    if word not in interesting_words:
                        interesting_words.append(word)
                if len(interesting_words) == num:
                    # Got enough words, break will break both loops
                    break
            min_len -= 1
            if min_len < 2: # Text contains really few words, we just have to add them, until we have enough
                for word in sorted_words:
                    if word not in interesting_words:
                        interesting_words.append(word)
                        if len(interesting_words) == num:
                            # Got enough words, break will break both loops
                            break

        # Sort result and return
        interesting_words = sorted(interesting_words, key=operator.itemgetter(1), reverse=True)
        return interesting_words

    def get_coverage(self, filename):
        """ Reads a list of words and compares it to the own words"""
        words = []
        num_words = 0
        # Count and compare
        f = open(filename)
        for word in f.readlines():
            if word.strip() != "":
                words.append(word.strip().lower())
                num_words += 1
        f.close()

        hits = set(words).intersection(set(self.words.keys()))

        return { "total": num_words, "hits": list(hits)}

    def get_awl_coverage(self, filename):
        words = {}
        f = open(filename)

        category = ""
        for word in f.readlines():
            if not word.startswith('\t'):
                category = word.strip()
            words[word.strip()] = category

        hits = set(words.keys()).intersection(set(self.words.keys()))

        category_hits = {}
        for category in set(words.values()):
            category_hits[category] = 0

        for hit in hits:
            category_hits[words[hit]] += 1

        category_num_hits = 0
        for key in category_hits.keys():
            if category_hits[key] > 0:
                category_num_hits += 1

        return {
            "words_total": len(words),
            "words_hits": len(list(hits)),
            "category_total": len(list(set(words.values()))),
            "category_num_hits": category_num_hits,
            "category_hits": category_hits
        }

    def publish(self):
        payload = {"stats" : json.dumps(self.stats)}
        r = requests.put(self.publish_url + "/papers/" + self.paper_id + ".json", data=payload)

def set_paper_alive(publish_url, paper_id, alive):
    payload = {"alive" : str(alive).lower()}
    r = requests.put(publish_url + "/papers/" + paper_id + ".json", params=payload)

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S')
    if len(sys.argv) != 4:
        print "Usage: python tracker.py <paper-file> <publish-host> <paper-id>"
        sys.exit()

    # Parse command line params
    filename = sys.argv[1]
    publish_url = sys.argv[2]
    paper_id = sys.argv[3]

    path = os.path.dirname(os.path.abspath(filename))

    # Enable "Currently writing..."
    set_paper_alive(publish_url, paper_id, True);

    # Observer setup
    event_handler = GamificationHandler(filename, publish_url, paper_id)
    observer = Observer()
    logging.info("Starting observer with watch path: " + path)
    observer.schedule(event_handler, path=path, recursive=True)
    # Observer start
    observer.start()
    logging.info("Observer started.")

    # Trigger an initial paper analysis
    event_handler.analyze_paper()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        # Disable "Currently writing..."
        set_paper_alive(publish_url, paper_id, False);
        observer.stop()
        observer.join()
<|endoftext|>


<commit_before>from django.contrib.auth.models import User

from rest_framework import serializers

from reviews_manager.models import ROIsAnnotation, ROIsAnnotationStep,\
    ClinicalAnnotation, ClinicalAnnotationStep, Review, ReviewStep
from rois_manager.serializers import SlideROIsTreeSerializer

class ReviewSerializer(serializers.ModelSerializer):
    reviewer = serializers.SlugRelatedField(
        slug_field='username',
        queryset=User.objects.all()
    )
    steps_count = serializers.SerializerMethodField()

    class Meta:
        model = Review

        fields = ('id', 'reviewer', 'case', 'creation_date', 'start_date',
                  'completion_date', 'type', 'steps_count')
        read_only_fields = ('id', 'creation_date', 'steps_count',)

    def get_steps_count(self, obj):
        return obj.steps.count()

class ReviewStepSerializer(serializers.ModelSerializer):
    review_type = serializers.SerializerMethodField(read_only=True)

    class Meta:
        model = ReviewStep

        fields = ('id', 'review', 'review_type', 'slide', 'creation_date',
                  'start_date', 'completion_date', 'notes')
        read_only_fields = ('id', 'creation_date',)

    def get_review_type(self, obj):
        rev = obj.review
        return rev.type

class ReviewDetailsSerializer(serializers.ModelSerializer):
    reviewer = serializers.SlugRelatedField(
        slug_field='username',
        queryset=User.objects.all()
    )
    steps = ReviewStepSerializer(many=True, read_only=True)

    class Meta:
        model = Review

        fields = ('id', 'reviewer', 'case', 'creation_date', 'start_date',
                  'completion_date', 'type', 'steps')
        read_only_fields = ('id', 'creation_date')

class ROIsAnnotationSerializer(serializers.ModelSerializer):
    reviewer = serializers.SlugRelatedField(
        slug_field='username',
        queryset=User.objects.all()
    )
    steps_count = serializers.SerializerMethodField()

    class Meta:
        model = ROIsAnnotation

        fields = ('id', 'reviewer', 'case', 'creation_date', 'start_date',
                  'completion_date', 'steps_count')
        read_only_fields = ('id', 'creation_date', 'steps_count')

    def get_steps_count(self, obj):
        return obj.steps.count()

class ROIsAnnotationsStepSerializer(serializers.ModelSerializer):
    class Meta:
        model = ROIsAnnotationStep

        fields = ('id', 'rois_annotation', 'slide', 'creation_date',
                  'start_date', 'completion_date')
        read_only_fields = ('id', 'creation_date')

class ROIsAnnotationsStepDetailsSerializer(ROIsAnnotationsStepSerializer):
    slide = SlideROIsTreeSerializer(many=True, read_only=True)

class ROIsAnnotationDetailsSerializer(serializers.ModelSerializer):
    reviewer = serializers.SlugRelatedField(
        slug_field='username',
        queryset=User.objects.all()
    )
    steps = ROIsAnnotationsStepSerializer(many=True, read_only=True)

    class Meta:
        model = ROIsAnnotation

        fields = ('id', 'reviewer', 'case', 'creation_date', 'start_date',
                  'completion_date', 'steps')
        read_only_fields = ('id', 'creation_date')

class ClinicalAnnotationSerializer(serializers.ModelSerializer):
    reviewer = serializers.SlugRelatedField(
        slug_field='username',
        queryset=User.objects.all()
    )
    steps_count = serializers.SerializerMethodField()

    class Meta:
        model = ClinicalAnnotation

        fields = ('id', 'reviewer', 'case', 'rois_review', 'creation_date',
                  'start_date', 'completion_date', 'steps_count')
        read_only_fields = ('id', 'creation_date', 'steps_count')

    def get_steps_count(self, obj):
        return obj.steps.count()

class ClinicalAnnotationStepSerializer(serializers.ModelSerializer):
    class Meta:
        model = ClinicalAnnotationStep

        fields = ('id', 'clinical_annotation', 'slide', 'rois_review_step',
                  'creation_date', 'start_date', 'completion_date', 'notes')
        read_only_fields = ('id', 'creation_date')

class ClinicalAnnotationDetailsSerializer(serializers.ModelSerializer):
    reviewer = serializers.SlugRelatedField(
        slug_field='username',
        queryset=User.objects.all()
    )
    steps = ClinicalAnnotationStepSerializer(many=True, read_only=True)

    class Meta:
        model = ClinicalAnnotation

        fields = ('id', 'reviewer', 'case', 'rois_review', 'creation_date',
                  'start_date', 'completion_date', 'steps_count')
        read_only_fields = ('id', 'creation_date', 'steps_count')
<commit_msg>fixed name<commit_after>from django.contrib.auth.models import User

from rest_framework import serializers

from reviews_manager.models import ROIsAnnotation, ROIsAnnotationStep,\
    ClinicalAnnotation, ClinicalAnnotationStep, Review, ReviewStep
from rois_manager.serializers import SlideROIsTreeSerializer

class ReviewSerializer(serializers.ModelSerializer):
    reviewer = serializers.SlugRelatedField(
        slug_field='username',
        queryset=User.objects.all()
    )
    steps_count = serializers.SerializerMethodField()

    class Meta:
        model = Review

        fields = ('id', 'reviewer', 'case', 'creation_date', 'start_date',
                  'completion_date', 'type', 'steps_count')
        read_only_fields = ('id', 'creation_date', 'steps_count',)

    def get_steps_count(self, obj):
        return obj.steps.count()

class ReviewStepSerializer(serializers.ModelSerializer):
    review_type = serializers.SerializerMethodField(read_only=True)

    class Meta:
        model = ReviewStep

        fields = ('id', 'review', 'review_type', 'slide', 'creation_date',
                  'start_date', 'completion_date', 'notes')
        read_only_fields = ('id', 'creation_date',)

    def get_review_type(self, obj):
        rev = obj.review
        return rev.type

class ReviewDetailsSerializer(serializers.ModelSerializer):
    reviewer = serializers.SlugRelatedField(
        slug_field='username',
        queryset=User.objects.all()
    )
    steps = ReviewStepSerializer(many=True, read_only=True)

    class Meta:
        model = Review

        fields = ('id', 'reviewer', 'case', 'creation_date', 'start_date',
                  'completion_date', 'type', 'steps')
        read_only_fields = ('id', 'creation_date')

class ROIsAnnotationSerializer(serializers.ModelSerializer):
    reviewer = serializers.SlugRelatedField(
        slug_field='username',
        queryset=User.objects.all()
    )
    steps_count = serializers.SerializerMethodField()

    class Meta:
        model = ROIsAnnotation

        fields = ('id', 'reviewer', 'case', 'creation_date', 'start_date',
                  'completion_date', 'steps_count')
        read_only_fields = ('id', 'creation_date', 'steps_count')

    def get_steps_count(self, obj):
        return obj.steps.count()

class ROIsAnnotationStepSerializer(serializers.ModelSerializer):
    class Meta:
        model = ROIsAnnotationStep

        fields = ('id', 'rois_annotation', 'slide', 'creation_date',
                  'start_date', 'completion_date')
        read_only_fields = ('id', 'creation_date')

class ROIsAnnotationStepDetailsSerializer(ROIsAnnotationsStepSerializer):
    slide = SlideROIsTreeSerializer(many=True, read_only=True)

class ROIsAnnotationDetailsSerializer(serializers.ModelSerializer):
    reviewer = serializers.SlugRelatedField(
        slug_field='username',
        queryset=User.objects.all()
    )
    steps = ROIsAnnotationStepSerializer(many=True, read_only=True)

    class Meta:
        model = ROIsAnnotation

        fields = ('id', 'reviewer', 'case', 'creation_date', 'start_date',
                  'completion_date', 'steps')
        read_only_fields = ('id', 'creation_date')

class ClinicalAnnotationSerializer(serializers.ModelSerializer):
    reviewer = serializers.SlugRelatedField(
        slug_field='username',
        queryset=User.objects.all()
    )
    steps_count = serializers.SerializerMethodField()

    class Meta:
        model = ClinicalAnnotation

        fields = ('id', 'reviewer', 'case', 'rois_review', 'creation_date',
                  'start_date', 'completion_date', 'steps_count')
        read_only_fields = ('id', 'creation_date', 'steps_count')

    def get_steps_count(self, obj):
        return obj.steps.count()

class ClinicalAnnotationStepSerializer(serializers.ModelSerializer):
    class Meta:
        model = ClinicalAnnotationStep

        fields = ('id', 'clinical_annotation', 'slide', 'rois_review_step',
                  'creation_date', 'start_date', 'completion_date', 'notes')
        read_only_fields = ('id', 'creation_date')

class ClinicalAnnotationDetailsSerializer(serializers.ModelSerializer):
    reviewer = serializers.SlugRelatedField(
        slug_field='username',
        queryset=User.objects.all()
    )
    steps = ClinicalAnnotationStepSerializer(many=True, read_only=True)

    class Meta:
        model = ClinicalAnnotation

        fields = ('id', 'reviewer', 'case', 'rois_review', 'creation_date',
                  'start_date', 'completion_date', 'steps_count')
        read_only_fields = ('id', 'creation_date', 'steps_count')
<|endoftext|>


<commit_before># Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *

class Lapackpp(CMakePackage):
    """LAPACK++: C++ API for the Basic Linear Algebra Subroutines (University
    of Tennessee)"""

    homepage = "https://bitbucket.org/icl/lapackpp"
    hg       = "https://bitbucket.org/icl/lapackpp"
    maintainers = ['teonnik', 'Sely85']

    version('develop', hg=hg, revision="7ffa486")

    variant('shared', default=True,
            description='Build a shared version of the library')

    depends_on('blaspp')

    def cmake_args(self):
        spec = self.spec
        return [
            '-DBUILD_SHARED_LIBS:BOOL={0}'.format(
                'ON' if '+shared' in spec else 'OFF'),
            '-DBUILD_LAPACKPP_TESTS:BOOL={0}'.format(
                'ON' if self.run_tests else 'OFF')
        ]
<commit_msg>migrate to git and update commit (#17276)<commit_after># Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *

class Lapackpp(CMakePackage):
    """LAPACK++: C++ API for the Basic Linear Algebra Subroutines (University
    of Tennessee)"""

    homepage = "https://bitbucket.org/icl/lapackpp"
    git      = "https://bitbucket.org/icl/lapackpp"
    maintainers = ['teonnik', 'Sely85']

    version('develop', commit="f878fad")

    variant('shared', default=True,
            description='Build a shared version of the library')

    depends_on('blaspp')

    def cmake_args(self):
        spec = self.spec
        return [
            '-DBUILD_SHARED_LIBS:BOOL={0}'.format(
                'ON' if '+shared' in spec else 'OFF'),
            '-DBUILD_LAPACKPP_TESTS:BOOL={0}'.format(
                'ON' if self.run_tests else 'OFF')
        ]
<|endoftext|>


<commit_before>from collections import defaultdict
from signal import signal, SIGPIPE, SIG_DFL
from time import time
import argparse
import math
import os
import sys

from abridger.extraction_model import ExtractionModel
from abridger.extractor import Extractor
from abridger.generator import Generator
import abridger.config_file_loader
import abridger.database

class DbOutputter(object):
    def __init__(self, url, verbosity):
        self.verbosity = verbosity

        if verbosity > 0:
            print('Connecting to', url)
        self.database = abridger.database.load(url)
        self.connection = self.database.connection
        self.cursor = self.connection.cursor()

    def insert_row(self, row):
        self.database.insert_rows([row], cursor=self.cursor)

    def update_row(self, row):
        self.database.update_rows([row], cursor=self.cursor)

    def begin(self):
        pass

    def commit(self):
        self.connection.commit()

    def rollback(self):
        self.connection.rollback()

    def finish(self):
        self.database.disconnect()

class SqlOutputter(object):
    def __init__(self, src_database, path, verbosity):
        self.src_db = src_database
        self.verbosity = verbosity
        self.path = path
        self.cursor = self.src_db.connection.cursor()

        if path == '-':  # pragma: no cover
            # Coverage isn't measured since this the test is executed in a
            # subprocess
            self.file = os.fdopen(sys.stdout.fileno(), 'wb')
        else:
            self.file = open(path, 'wb')

    def insert_row(self, row):
        stmt = self.src_db.make_insert_stmt(self.cursor, row)
        self.file.write(stmt)
        self.file.write(b"\n")

    def update_row(self, row):
        stmt = self.src_db.make_update_stmt(self.cursor, row)
        self.file.write(stmt)
        self.file.write(b";\n")

    def begin(self):
        for stmt in self.src_db.make_begin_stmts():
            self.file.write(stmt)
            self.file.write(b"\n")

    def commit(self):
        for stmt in self.src_db.make_commit_stmts():
            self.file.write(stmt)
            self.file.write(b"\n")

    def rollback(self):
        pass

    def finish(self):
        self.file.close()

def main(args):
    parser = argparse.ArgumentParser(
        description='Minimize a database')
    parser.add_argument(dest='config_path', metavar='CONFIG_PATH',
                        help="path to extraction config file")
    parser.add_argument(dest='src_url', metavar='SRC_URL',
                        help="source database url")
    parser.add_argument('-u', dest='dst_url', metavar='URL',
                        help="destination database url")
    parser.add_argument('-f', dest='dst_file', metavar='FILE',
                        help="destination database file. Use - for stdout")
    parser.add_argument('-e', '--explain', dest='explain', action='store_true',
                        default=False,
                        help='explain where rows are coming from')
    parser.add_argument('-q', '--quiet', dest='quiet', action='store_true',
                        default=False,
                        help="Don't output anything")
    parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
                        default=False,
                        help="Verbose output")

    # Ignore SIG_PIPE and don't throw exceptions on it
    signal(SIGPIPE, SIG_DFL)

    args = parser.parse_args(args)

    verbosity = 1
    if args.quiet:
        verbosity = 0
    if args.verbose:
        verbosity = 2

    if (args.dst_url is None) == (args.dst_file is None):
        print('Either -u or -f must be passed')
        exit(1)

    if verbosity > 0:
        print('Connecting to', args.src_url)
    src_database = abridger.database.load(args.src_url)

    if args.dst_url is not None:
        outputter = DbOutputter(args.dst_url, verbosity)
        if not isinstance(src_database, type(outputter.database)):
            print('src and dst databases must be of the same type')
            exit(1)
    else:
        if not src_database.CAN_GENERATE_SQL_STATEMENTS:
            print("SQL generation isn't available for this type of database")
            exit(1)
        outputter = SqlOutputter(src_database, args.dst_file, verbosity)

    if verbosity > 0:
        print('Querying...')
    extraction_model_data = abridger.config_file_loader.load(args.config_path)
    extraction_model = ExtractionModel.load(src_database.schema,
                                            extraction_model_data)
    extractor = Extractor(src_database, extraction_model, explain=args.explain,
                          verbosity=verbosity)
    extractor.launch()

    if args.explain:
        exit(0)

    generator = Generator(src_database.schema, extractor)
    generator.generate_statements()

    if args.dst_url is not None:
        # The src database isn't needed any more
        src_database.disconnect()

    total_table_insert_counts = defaultdict(int)
    total_table_update_counts = defaultdict(int)
    table_insert_counts = defaultdict(int)
    table_update_counts = defaultdict(int)
    total_insert_count = len(generator.insert_statements)
    total_update_count = len(generator.update_statements)
    total_count = total_insert_count + total_update_count

    start_time = time()

    try:
        for insert_statement in generator.insert_statements:
            (table, values) = insert_statement
            total_table_insert_counts[table] += 1

        for update_statement in generator.update_statements:
            table = update_statement[0]
            total_table_update_counts[table] += 1

        if verbosity > 0:
            insert_tables = set(total_table_insert_counts.keys())
            update_tables = set(total_table_insert_counts.keys())
            tables = insert_tables | update_tables
            print('Performing %d inserts and %d updates to %d tables...' % (
                total_insert_count, total_update_count, len(tables)))

        insert_count = 0
        count = 0
        outputter.begin()
        for insert_statement in generator.insert_statements:
            (table, values) = insert_statement
            table_insert_counts[table] += 1
            insert_count += 1
            count += 1
            if verbosity > 1:
                percentage = math.floor(1000 * (count / total_count)) / 10
                print("%5.1f%% Inserting (%6d/%6d) row (%6d/%6d) in %s" % (
                    percentage,
                    insert_count, total_insert_count,
                    table_insert_counts[table],
                    total_table_insert_counts[table],
                    table))
            outputter
            outputter.insert_row(insert_statement)

        update_count = 0
        for update_statement in generator.update_statements:
            table = update_statement[0]
            table_update_counts[table] += 1
            update_count += 1
            count += 1
            if verbosity > 1:
                percentage = math.floor(1000 * (count / total_count)) / 10
                print("%5.1f%% Updating  (%6d/%6d) row (%6d/%6d) in %s" % (
                    percentage,
                    update_count, total_update_count,
                    total_table_update_counts[table],
                    table_update_counts[table],
                    table))
            outputter.update_row(update_statement)

        outputter.commit()
    finally:
        try:
            outputter.rollback()
        except Exception as e:
            print("Something went wrong while trying a rollback: %s" % str(e))

        src_database.disconnect()
        outputter.finish()

    if verbosity > 0:
        elapsed_time = time() - start_time
        print('Data loading completed in %0.1f seconds' % elapsed_time)
<commit_msg>Removed useless error reporting<commit_after>from collections import defaultdict
from signal import signal, SIGPIPE, SIG_DFL
from time import time
import argparse
import math
import os
import sys

from abridger.extraction_model import ExtractionModel
from abridger.extractor import Extractor
from abridger.generator import Generator
import abridger.config_file_loader
import abridger.database

class DbOutputter(object):
    def __init__(self, url, verbosity):
        self.verbosity = verbosity

        if verbosity > 0:
            print('Connecting to', url)
        self.database = abridger.database.load(url)
        self.connection = self.database.connection
        self.cursor = self.connection.cursor()

    def insert_row(self, row):
        self.database.insert_rows([row], cursor=self.cursor)

    def update_row(self, row):
        self.database.update_rows([row], cursor=self.cursor)

    def begin(self):
        pass

    def commit(self):
        self.connection.commit()

    def rollback(self):
        self.connection.rollback()

    def finish(self):
        self.database.disconnect()

class SqlOutputter(object):
    def __init__(self, src_database, path, verbosity):
        self.src_db = src_database
        self.verbosity = verbosity
        self.path = path
        self.cursor = self.src_db.connection.cursor()

        if path == '-':  # pragma: no cover
            # Coverage isn't measured since this the test is executed in a
            # subprocess
            self.file = os.fdopen(sys.stdout.fileno(), 'wb')
        else:
            self.file = open(path, 'wb')

    def insert_row(self, row):
        stmt = self.src_db.make_insert_stmt(self.cursor, row)
        self.file.write(stmt)
        self.file.write(b"\n")

    def update_row(self, row):
        stmt = self.src_db.make_update_stmt(self.cursor, row)
        self.file.write(stmt)
        self.file.write(b";\n")

    def begin(self):
        for stmt in self.src_db.make_begin_stmts():
            self.file.write(stmt)
            self.file.write(b"\n")

    def commit(self):
        for stmt in self.src_db.make_commit_stmts():
            self.file.write(stmt)
            self.file.write(b"\n")

    def rollback(self):
        pass

    def finish(self):
        self.file.close()

def main(args):
    parser = argparse.ArgumentParser(
        description='Minimize a database')
    parser.add_argument(dest='config_path', metavar='CONFIG_PATH',
                        help="path to extraction config file")
    parser.add_argument(dest='src_url', metavar='SRC_URL',
                        help="source database url")
    parser.add_argument('-u', dest='dst_url', metavar='URL',
                        help="destination database url")
    parser.add_argument('-f', dest='dst_file', metavar='FILE',
                        help="destination database file. Use - for stdout")
    parser.add_argument('-e', '--explain', dest='explain', action='store_true',
                        default=False,
                        help='explain where rows are coming from')
    parser.add_argument('-q', '--quiet', dest='quiet', action='store_true',
                        default=False,
                        help="Don't output anything")
    parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
                        default=False,
                        help="Verbose output")

    # Ignore SIG_PIPE and don't throw exceptions on it
    signal(SIGPIPE, SIG_DFL)

    args = parser.parse_args(args)

    verbosity = 1
    if args.quiet:
        verbosity = 0
    if args.verbose:
        verbosity = 2

    if (args.dst_url is None) == (args.dst_file is None):
        print('Either -u or -f must be passed')
        exit(1)

    if verbosity > 0:
        print('Connecting to', args.src_url)
    src_database = abridger.database.load(args.src_url)

    if args.dst_url is not None:
        outputter = DbOutputter(args.dst_url, verbosity)
        if not isinstance(src_database, type(outputter.database)):
            print('src and dst databases must be of the same type')
            exit(1)
    else:
        if not src_database.CAN_GENERATE_SQL_STATEMENTS:
            print("SQL generation isn't available for this type of database")
            exit(1)
        outputter = SqlOutputter(src_database, args.dst_file, verbosity)

    if verbosity > 0:
        print('Querying...')
    extraction_model_data = abridger.config_file_loader.load(args.config_path)
    extraction_model = ExtractionModel.load(src_database.schema,
                                            extraction_model_data)
    extractor = Extractor(src_database, extraction_model, explain=args.explain,
                          verbosity=verbosity)
    extractor.launch()

    if args.explain:
        exit(0)

    generator = Generator(src_database.schema, extractor)
    generator.generate_statements()

    if args.dst_url is not None:
        # The src database isn't needed any more
        src_database.disconnect()

    total_table_insert_counts = defaultdict(int)
    total_table_update_counts = defaultdict(int)
    table_insert_counts = defaultdict(int)
    table_update_counts = defaultdict(int)
    total_insert_count = len(generator.insert_statements)
    total_update_count = len(generator.update_statements)
    total_count = total_insert_count + total_update_count

    start_time = time()

    try:
        for insert_statement in generator.insert_statements:
            (table, values) = insert_statement
            total_table_insert_counts[table] += 1

        for update_statement in generator.update_statements:
            table = update_statement[0]
            total_table_update_counts[table] += 1

        if verbosity > 0:
            insert_tables = set(total_table_insert_counts.keys())
            update_tables = set(total_table_insert_counts.keys())
            tables = insert_tables | update_tables
            print('Performing %d inserts and %d updates to %d tables...' % (
                total_insert_count, total_update_count, len(tables)))

        insert_count = 0
        count = 0
        outputter.begin()
        for insert_statement in generator.insert_statements:
            (table, values) = insert_statement
            table_insert_counts[table] += 1
            insert_count += 1
            count += 1
            if verbosity > 1:
                percentage = math.floor(1000 * (count / total_count)) / 10
                print("%5.1f%% Inserting (%6d/%6d) row (%6d/%6d) in %s" % (
                    percentage,
                    insert_count, total_insert_count,
                    table_insert_counts[table],
                    total_table_insert_counts[table],
                    table))
            outputter
            outputter.insert_row(insert_statement)

        update_count = 0
        for update_statement in generator.update_statements:
            table = update_statement[0]
            table_update_counts[table] += 1
            update_count += 1
            count += 1
            if verbosity > 1:
                percentage = math.floor(1000 * (count / total_count)) / 10
                print("%5.1f%% Updating  (%6d/%6d) row (%6d/%6d) in %s" % (
                    percentage,
                    update_count, total_update_count,
                    total_table_update_counts[table],
                    table_update_counts[table],
                    table))
            outputter.update_row(update_statement)

        outputter.commit()
    finally:
        try:
            outputter.rollback()
        except:
            pass

        src_database.disconnect()
        outputter.finish()

    if verbosity > 0:
        elapsed_time = time() - start_time
        print('Data loading completed in %0.1f seconds' % elapsed_time)
<|endoftext|>


<commit_before>#############################################################################
#
# Copyright 2008 Tungsten Graphics, Inc.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################

"""windows.h"""

from base import *

SHORT = Intrinsic("SHORT", "%i")
USHORT = Intrinsic("USHORT", "%u")
INT = Intrinsic("INT", "%i")
UINT = Intrinsic("UINT", "%u")
LONG = Intrinsic("LONG", "%li")
ULONG = Intrinsic("ULONG", "%lu")
FLOAT = Intrinsic("FLOAT", "%f")

INT32 = Intrinsic("INT32", "%i")
UINT32 = Intrinsic("UINT32", "%i")

BYTE = Intrinsic("BYTE", "0x%02lx")
WORD = Intrinsic("WORD", "0x%04lx")
DWORD = Intrinsic("DWORD", "0x%08lx")

BOOL = Intrinsic("BOOL", "%i")

LPLONG = Pointer(LONG)
LPWORD = Pointer(WORD)
LPDWORD = Pointer(DWORD)
LPBOOL = Pointer(BOOL)
LPSIZE = LPDWORD

LPSTR = String
LPWSTR = String

LARGE_INTEGER = Intrinsic("LARGE_INTEGER", "0x%llx")

HRESULT = Alias("HRESULT", Int)

PVOID = Intrinsic("PVOID", "%p")
LPVOID = PVOID
HANDLE = Intrinsic("HANDLE", "%p")
HWND = Intrinsic("HWND", "%p")
HDC = Intrinsic("HDC", "%p")
HMONITOR = Intrinsic("HMONITOR", "%p")

GUID = Struct("GUID", [
    (DWORD, "Data1"),
    (WORD, "Data2"),
    (WORD, "Data3"),
    (BYTE, "Data4[0]"),
    (BYTE, "Data4[1]"),
    (BYTE, "Data4[2]"),
    (BYTE, "Data4[3]"),
    (BYTE, "Data4[4]"),
    (BYTE, "Data4[5]"),
    (BYTE, "Data4[6]"),
    (BYTE, "Data4[7]"),
])
LPGUID = Pointer(GUID)

#REFGUID = Alias("REFGUID", Pointer(GUID))
REFGUID = Alias("REFGUID", GUID)

IID = Alias("IID", GUID)
#REFIID = Alias("REFIID", Pointer(IID))
REFIID = Alias("REFIID", IID)

CLSID = Alias("CLSID", GUID)
#REFCLSID = Alias("REFCLSID", Pointer(CLSID))
REFCLSID = Alias("REFCLSID", CLSID)

LUID = Struct("LUID", [
    (DWORD, "LowPart"),
    (LONG, "HighPart"),
])

POINT = Struct("POINT", (
  (LONG, "x"),
  (LONG, "y"),
))
LPPOINT = Pointer(POINT)

RECT = Struct("RECT", (
  (LONG, "left"),
  (LONG, "top"),
  (LONG, "right"),
  (LONG, "bottom"),
))
LPRECT = Pointer(RECT)

PALETTEENTRY = Struct("PALETTEENTRY", (
  (BYTE, "peRed"),
  (BYTE, "peGreen"),
  (BYTE, "peBlue"),
  (BYTE, "peFlags"),
))
LPPALETTEENTRY = Pointer(PALETTEENTRY)

RGNDATAHEADER = Struct("RGNDATAHEADER", [
    (DWORD, "dwSize"),
    (DWORD, "iType"),
    (DWORD, "nCount"),
    (DWORD, "nRgnSize"),
    (RECT, "rcBound"),
])

RGNDATA = Struct("RGNDATA", [
    (RGNDATAHEADER, "rdh"),
    #(Char, "Buffer[1]"),
])
LPRGNDATA = Pointer(RGNDATA)

IUnknown = Interface("IUnknown")

IUnknown.methods = (
	Method(HRESULT, "QueryInterface", ((REFIID, "riid"), (Pointer(Pointer(Void)), "ppvObj"))),
	Method(ULONG, "AddRef", ()),
	Method(ULONG, "Release", ()),
)

class Dll:

    def __init__(self, name):
        self.name = name
        self.functions = []
        if self not in towrap:
            towrap.append(self)

    def wrap_name(self):
        return "Wrap" + self.name

    def wrap_pre_decl(self):
        pass

    def wrap_decl(self):
        print 'static HINSTANCE g_hDll = NULL;'
        print 'static TCHAR g_szDll[MAX_PATH] = {0};'
        print
        print 'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);'
        print

    def wrap_impl(self):
        print r'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {'
        print r'    switch(fdwReason) {'
        print r'    case DLL_PROCESS_ATTACH:'
        print r'        if(!GetSystemDirectory(g_szDll, MAX_PATH))'
        print r'            return FALSE;'
        print r'        _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name
        print r'        Log::Open("%s");' % self.name
        print r'    case DLL_THREAD_ATTACH:'
        print r'        return TRUE;'
        print r'    case DLL_THREAD_DETACH:'
        print r'        return TRUE;'
        print r'    case DLL_PROCESS_DETACH:'
        print r'        Log::Close();'
        print r'        if(g_hDll) {'
        print r'            FreeLibrary(g_hDll);'
        print r'            g_hDll = NULL;'
        print r'        }'
        print r'        return TRUE;'
        print r'    }'
        print r'    (void)hinstDLL;'
        print r'    (void)lpvReserved;'
        print r'    return TRUE;'
        print r'}'
        print
        for function in self.functions:
            type = 'P' + function.name
            print function.prototype() + ' {'
            if 0:
                print '    Log::Close();'
                print '    Log::Open("%s");' % self.name
            #print '    Log::ReOpen();'
            print '    typedef ' + function.prototype('* %s' % type) + ';'
            print '    %s pFunction;' % type
            if function.type is Void:
                result = ''
            else:
                print '    %s result;' % function.type
                result = 'result = '
            print '    if(!g_hDll) {'
            print '        g_hDll = LoadLibrary(g_szDll);'
            print '        if(!g_hDll)'
            print '            ExitProcess(0);'
            print '    }'
            print '    pFunction = (%s)GetProcAddress( g_hDll, "%s");' % (type, function.name)
            print '    if(!pFunction)'
            print '        ExitProcess(0);'
            print '    Log::BeginCall("%s");' % (function.name)
            print '    %spFunction(%s);' % (result, ', '.join([str(name) for type, name in function.args]))
            print '    Log::EndCall();'
            for type, name in function.args:
                if type.isoutput():
                    type.wrap_instance(name)
            if function.type is not Void:
                function.type.wrap_instance('result')
            if function.type is not Void:
                print '    return result;'
            print '}'
            print
        print

<commit_msg>Dump regular functions arguments/result.<commit_after>#############################################################################
#
# Copyright 2008 Tungsten Graphics, Inc.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################

"""windows.h"""

from base import *

SHORT = Intrinsic("SHORT", "%i")
USHORT = Intrinsic("USHORT", "%u")
INT = Intrinsic("INT", "%i")
UINT = Intrinsic("UINT", "%u")
LONG = Intrinsic("LONG", "%li")
ULONG = Intrinsic("ULONG", "%lu")
FLOAT = Intrinsic("FLOAT", "%f")

INT32 = Intrinsic("INT32", "%i")
UINT32 = Intrinsic("UINT32", "%i")

BYTE = Intrinsic("BYTE", "0x%02lx")
WORD = Intrinsic("WORD", "0x%04lx")
DWORD = Intrinsic("DWORD", "0x%08lx")

BOOL = Intrinsic("BOOL", "%i")

LPLONG = Pointer(LONG)
LPWORD = Pointer(WORD)
LPDWORD = Pointer(DWORD)
LPBOOL = Pointer(BOOL)
LPSIZE = LPDWORD

LPSTR = String
LPWSTR = String

LARGE_INTEGER = Intrinsic("LARGE_INTEGER", "0x%llx")

HRESULT = Alias("HRESULT", Int)

PVOID = Intrinsic("PVOID", "%p")
LPVOID = PVOID
HANDLE = Intrinsic("HANDLE", "%p")
HWND = Intrinsic("HWND", "%p")
HDC = Intrinsic("HDC", "%p")
HMONITOR = Intrinsic("HMONITOR", "%p")

GUID = Struct("GUID", [
    (DWORD, "Data1"),
    (WORD, "Data2"),
    (WORD, "Data3"),
    (BYTE, "Data4[0]"),
    (BYTE, "Data4[1]"),
    (BYTE, "Data4[2]"),
    (BYTE, "Data4[3]"),
    (BYTE, "Data4[4]"),
    (BYTE, "Data4[5]"),
    (BYTE, "Data4[6]"),
    (BYTE, "Data4[7]"),
])
LPGUID = Pointer(GUID)

#REFGUID = Alias("REFGUID", Pointer(GUID))
REFGUID = Alias("REFGUID", GUID)

IID = Alias("IID", GUID)
#REFIID = Alias("REFIID", Pointer(IID))
REFIID = Alias("REFIID", IID)

CLSID = Alias("CLSID", GUID)
#REFCLSID = Alias("REFCLSID", Pointer(CLSID))
REFCLSID = Alias("REFCLSID", CLSID)

LUID = Struct("LUID", [
    (DWORD, "LowPart"),
    (LONG, "HighPart"),
])

POINT = Struct("POINT", (
  (LONG, "x"),
  (LONG, "y"),
))
LPPOINT = Pointer(POINT)

RECT = Struct("RECT", (
  (LONG, "left"),
  (LONG, "top"),
  (LONG, "right"),
  (LONG, "bottom"),
))
LPRECT = Pointer(RECT)

PALETTEENTRY = Struct("PALETTEENTRY", (
  (BYTE, "peRed"),
  (BYTE, "peGreen"),
  (BYTE, "peBlue"),
  (BYTE, "peFlags"),
))
LPPALETTEENTRY = Pointer(PALETTEENTRY)

RGNDATAHEADER = Struct("RGNDATAHEADER", [
    (DWORD, "dwSize"),
    (DWORD, "iType"),
    (DWORD, "nCount"),
    (DWORD, "nRgnSize"),
    (RECT, "rcBound"),
])

RGNDATA = Struct("RGNDATA", [
    (RGNDATAHEADER, "rdh"),
    #(Char, "Buffer[1]"),
])
LPRGNDATA = Pointer(RGNDATA)

IUnknown = Interface("IUnknown")

IUnknown.methods = (
	Method(HRESULT, "QueryInterface", ((REFIID, "riid"), (Pointer(Pointer(Void)), "ppvObj"))),
	Method(ULONG, "AddRef", ()),
	Method(ULONG, "Release", ()),
)

class Dll:

    def __init__(self, name):
        self.name = name
        self.functions = []
        if self not in towrap:
            towrap.append(self)

    def wrap_name(self):
        return "Wrap" + self.name

    def wrap_pre_decl(self):
        pass

    def wrap_decl(self):
        print 'static HINSTANCE g_hDll = NULL;'
        print 'static TCHAR g_szDll[MAX_PATH] = {0};'
        print
        print 'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);'
        print

    def wrap_impl(self):
        print r'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {'
        print r'    switch(fdwReason) {'
        print r'    case DLL_PROCESS_ATTACH:'
        print r'        if(!GetSystemDirectory(g_szDll, MAX_PATH))'
        print r'            return FALSE;'
        print r'        _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name
        print r'        Log::Open("%s");' % self.name
        print r'    case DLL_THREAD_ATTACH:'
        print r'        return TRUE;'
        print r'    case DLL_THREAD_DETACH:'
        print r'        return TRUE;'
        print r'    case DLL_PROCESS_DETACH:'
        print r'        Log::Close();'
        print r'        if(g_hDll) {'
        print r'            FreeLibrary(g_hDll);'
        print r'            g_hDll = NULL;'
        print r'        }'
        print r'        return TRUE;'
        print r'    }'
        print r'    (void)hinstDLL;'
        print r'    (void)lpvReserved;'
        print r'    return TRUE;'
        print r'}'
        print
        for function in self.functions:
            type = 'P' + function.name
            print function.prototype() + ' {'
            if 0:
                print '    Log::Close();'
                print '    Log::Open("%s");' % self.name
            #print '    Log::ReOpen();'
            print '    typedef ' + function.prototype('* %s' % type) + ';'
            print '    %s pFunction;' % type
            if function.type is Void:
                result = ''
            else:
                print '    %s result;' % function.type
                result = 'result = '
            print '    if(!g_hDll) {'
            print '        g_hDll = LoadLibrary(g_szDll);'
            print '        if(!g_hDll)'
            print '            ExitProcess(0);'
            print '    }'
            print '    pFunction = (%s)GetProcAddress( g_hDll, "%s");' % (type, function.name)
            print '    if(!pFunction)'
            print '        ExitProcess(0);'
            print '    Log::BeginCall("%s");' % (function.name)
            for type, name in function.args:
                if not type.isoutput():
                    type.unwrap_instance(name)
                    print '    Log::BeginArg("%s", "%s");' % (type, name)
                    type.dump(name)
                    print '    Log::EndArg();'
            print '    %spFunction(%s);' % (result, ', '.join([str(name) for type, name in function.args]))
            for type, name in function.args:
                if type.isoutput():
                    print '    Log::BeginArg("%s", "%s");' % (type, name)
                    type.dump(name)
                    print '    Log::EndArg();'
                    type.wrap_instance(name)
            if function.type is not Void:
                print '    Log::BeginReturn("%s");' % function.type
                function.type.dump("result")
                print '    Log::EndReturn();'
                function.type.wrap_instance('result')
            print '    Log::EndCall();'
            if function.type is not Void:
                print '    return result;'
            print '}'
            print
        print

<|endoftext|>


<commit_before># Copyright 2013-2018 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *

class Minimap2(MakefilePackage):
    """Minimap2 is a versatile sequence alignment program that aligns DNA or
       mRNA sequences against a large reference database."""

    homepage = "https://github.com/lh3/minimap2"
    url      = "https://github.com/lh3/minimap2/releases/download/v2.2/minimap2-2.2.tar.bz2"

    version('2.2', '5b68e094f4fa3dfbd9b37d5b654b7715')

    depends_on('py-mappy', type=('build', 'run'))

    def install(self, spec, prefix):
        mkdirp(prefix.bin)
        install('minimap2', prefix.bin)
<commit_msg>minimap2: Add versions 2.10 and 2.14 (#9818)<commit_after># Copyright 2013-2018 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *

class Minimap2(MakefilePackage):
    """Minimap2 is a versatile sequence alignment program that aligns DNA or
       mRNA sequences against a large reference database."""

    homepage = "https://github.com/lh3/minimap2"
    url      = "https://github.com/lh3/minimap2/releases/download/v2.2/minimap2-2.2.tar.bz2"

    version('2.14', '9088b785bb0c33488ca3a27c8994648ce21a8be54cb117f5ecee26343facd03b')
    version('2.10', '52b36f726ec00bfca4a2ffc23036d1a2b5f96f0aae5a92fd826be6680c481c20')
    version('2.2', '5b68e094f4fa3dfbd9b37d5b654b7715')

    depends_on('py-mappy', type=('build', 'run'))
    depends_on('zlib')

    def install(self, spec, prefix):
        mkdirp(prefix.bin)
        install('minimap2', prefix.bin)
<|endoftext|>


<commit_before># -*- coding: utf-8 -*-
"""Misspellings.

---
layout:     post
source:     Garner's Modern American Usage
source_url: http://amzn.to/15wF76r
title:      misspellings
date:       2014-06-10 12:31:19
categories: writing
---

Points out misspellings.

"""
from tools import memoize, preferred_forms_check

@memoize
def check(text):
    """Suggest the preferred forms."""
    err = "garner.misspellings"
    msg = "Misspelling. '{}' is the preferred form."

    misspellings = [
        ["a lot",             ["alot"]],
        ["academically",      ["academicly"]],
        ["accidentally",      ["accidently"]],
        ["accommodable",      ["accomodatable"]],
        ["anilingus",         ["analingus"]],
        ["aren't i",          ["amn't i"]],
        ["aren't i",          ["an't i"]],
        ["barbed wire",       ["bob wire"]],
        ["chargeable",        ["chargable"]],
        ["chiffonier",        ["chiffonnier"]],
        ["chintzy",           ["chinchy"]],
        ["chipotle",          ["chipolte"]],
        ["chlorophyll",       ["chlorophyl"]],
        ["chocolaty",         ["chocolatey"]],
        ["chronicle",         ["chronical"]],
        ["chronicles",        ["chronicals"]],
        ["coleslaw",          ["coldslaw"]],
        ["choosy",            ["choosey"]],
        ["cummerbund",        ["kummerbund"]],
        ["financeable",       ["financable"]],
        ["fluorescent",       ["flourescent"]],
        ["fluoridation",      ["flouridation"]],
        ["fluoride",          ["flouride"]],
        ["foreclose",         ["forclose"]],
        ["forswear",          ["foreswear"]],
        ["free rein",         ["free reign"]],
        ["gist",              ["jist"]],
        ["glamour",           ["glamor"]],
        ["granddad",          ["grandad"]],
        ["grandpa",           ["granpa"]],
        ["highfalutin",       ["highfaluting", "highfalutin'", "hifalutin"]],
        ["Hippocratic",       ["hypocratic"]],
        ["hirable",           ["hireable"]],
        ["holistic",          ["wholistic"]],
        ["ideology",          ["idealogy"]],
        ["idiosyncrasy",      ["ideosyncracy"]],
        ["improvise",         ["improvize"]],
        ["incurrence",        ["incurment"]],
        ["inevitability",     ["inevitableness"]],
        ["innovate",          ["inovate"]],
        ["inoculation",       ["innoculation", "inocculation"]],
        ["integral",          ["intergral"]],
        ["inundate",          ["innundate"]],
        ["inundated",         ["innundated"]],
        ["inundates",         ["innundates"]],
        ["inundating",        ["innundating"]],
        ["iridescent",        ["irridescent"]],
        ["irrelevant",        ["irrevelant"]],
        ["jujitsu",           ["jiujutsu"]],
        ["kaleidoscope",      ["kaleidascope"]],
        ["knickknack",        ["knicknack"]],
        ["lassos",            ["lassoes"]],
        ["lessee",            ["leasee"]],
        ["lessor",            ["leasor"]],
        ["liaison",           ["liason"]],
        ["liaison",           ["laison"]],
        ["lightning rod",     ["lightening rod"]],
        ["struck by lightning", ["struck by lightening"]],
        ["liquefy",           ["liquify"]],
        ["loathsome",         ["loathesome"]],
        ["lodestar",          ["loadstar"]],
        ["to make do",        ["to make due"]],
        ["mademoiselle",      ["madamoiselle"]],
        ["martial arts",      ["marshall arts"]],
        ["court-martial",     ["court marshall", "court-marshall"]],
        ["maelstrom",         ["maelstorm"]],
        ["mafia",             ["maffia"]],
        ["mafiosi",           ["mafiosos"]],
        ["mangoes",           ["mangos"]],
        ["marijuana",         ["marihuana"]],
        ["marshmallow",       ["marshmellow"]],
        ["martial law",       ["marshall law"]],
        ["massacring",        ["massacering", "massacreing"]],
        ["measles",           ["measels"]],
        ["memento",           ["momento"]],
        ["minuscule",         ["miniscule"]],
        ["mileage",           ["milage"]],
        ["milieu",            ["mileau"]],
        ["millennium",        ["millenium"]],
        ["millennia",         ["millenia"]],
        ["millenniums",       ["milleniums"]],
        ["millipede",         ["millepede"]],
        ["millionaire",       ["millionnaire"]],
        ["milquetoast",       ["milktoast"]],
        ["mimicked",          ["mimiced"]],
        ["mimicking",         ["mimicing"]],
        ["misspelling",       ["mispelling"]],
        ["mischievous",       ["mischievious"]],
        ["moccasin",          ["mocasin", "moccassin", "mocassin"]],
        ["naphtha",           ["naptha"]],
        ["navel orange",      ["naval orange"]],
        ["neckwear",          ["neckware"]],
        ["newsstand",         ["newstand"]],
        ["occurred",          ["occured"]],
        ["plantar fasciitis", ["planter fasciitis", "plantar fascitis"]],
        ["pledgeable",        ["pledgable", "pledgeble"]],
        ["portentous",        ["portentuous", "portentious"]],
        ["praying mantis",    ["preying mantis"]],
        ["preestablished",    ["prestablished"]],
        ["preexisting",       ["prexisting"]],
        ["presumptuous",      ["presumptious"]],
        ["rarefy",            ["rarify"]],
        ["reckless",          ["wreckless"]],
        ["remuneration",      ["renumeration"]],
        ["restaurateur",      ["restauranteur"]],
        ["retractable",       ["retractible"]],
        ["reverie",           ["revery"]],
        ["spicy",             ["spicey"]],
        ["stupefy",           ["stupify"]],
        ["subtly",            ["subtley"]],
        ["till",              ["\'till?"]],
        ["tinderbox",         ["tenderbox"]],
        ["timpani",           ["tympani"]],
        ["a timpani",         ["a timpano"]],
        ["umpteenth",         ["umteenth"]],
        ["verbiage",          ["verbage"]],
    ]

    return preferred_forms_check(text, misspellings, err, msg)
<commit_msg>Add rule on monologues and monologuists<commit_after># -*- coding: utf-8 -*-
"""Misspellings.

---
layout:     post
source:     Garner's Modern American Usage
source_url: http://amzn.to/15wF76r
title:      misspellings
date:       2014-06-10 12:31:19
categories: writing
---

Points out misspellings.

"""
from tools import memoize, preferred_forms_check

@memoize
def check(text):
    """Suggest the preferred forms."""
    err = "garner.misspellings"
    msg = "Misspelling. '{}' is the preferred form."

    misspellings = [
        ["a lot",             ["alot"]],
        ["academically",      ["academicly"]],
        ["accidentally",      ["accidently"]],
        ["accommodable",      ["accomodatable"]],
        ["anilingus",         ["analingus"]],
        ["aren't i",          ["amn't i"]],
        ["aren't i",          ["an't i"]],
        ["barbed wire",       ["bob wire"]],
        ["chargeable",        ["chargable"]],
        ["chiffonier",        ["chiffonnier"]],
        ["chintzy",           ["chinchy"]],
        ["chipotle",          ["chipolte"]],
        ["chlorophyll",       ["chlorophyl"]],
        ["chocolaty",         ["chocolatey"]],
        ["chronicle",         ["chronical"]],
        ["chronicles",        ["chronicals"]],
        ["coleslaw",          ["coldslaw"]],
        ["choosy",            ["choosey"]],
        ["cummerbund",        ["kummerbund"]],
        ["financeable",       ["financable"]],
        ["fluorescent",       ["flourescent"]],
        ["fluoridation",      ["flouridation"]],
        ["fluoride",          ["flouride"]],
        ["foreclose",         ["forclose"]],
        ["forswear",          ["foreswear"]],
        ["free rein",         ["free reign"]],
        ["gist",              ["jist"]],
        ["glamour",           ["glamor"]],
        ["granddad",          ["grandad"]],
        ["grandpa",           ["granpa"]],
        ["highfalutin",       ["highfaluting", "highfalutin'", "hifalutin"]],
        ["Hippocratic",       ["hypocratic"]],
        ["hirable",           ["hireable"]],
        ["holistic",          ["wholistic"]],
        ["ideology",          ["idealogy"]],
        ["idiosyncrasy",      ["ideosyncracy"]],
        ["improvise",         ["improvize"]],
        ["incurrence",        ["incurment"]],
        ["inevitability",     ["inevitableness"]],
        ["innovate",          ["inovate"]],
        ["inoculation",       ["innoculation", "inocculation"]],
        ["integral",          ["intergral"]],
        ["inundate",          ["innundate"]],
        ["inundated",         ["innundated"]],
        ["inundates",         ["innundates"]],
        ["inundating",        ["innundating"]],
        ["iridescent",        ["irridescent"]],
        ["irrelevant",        ["irrevelant"]],
        ["jujitsu",           ["jiujutsu"]],
        ["kaleidoscope",      ["kaleidascope"]],
        ["knickknack",        ["knicknack"]],
        ["lassos",            ["lassoes"]],
        ["lessee",            ["leasee"]],
        ["lessor",            ["leasor"]],
        ["liaison",           ["liason"]],
        ["liaison",           ["laison"]],
        ["lightning rod",     ["lightening rod"]],
        ["struck by lightning", ["struck by lightening"]],
        ["liquefy",           ["liquify"]],
        ["loathsome",         ["loathesome"]],
        ["lodestar",          ["loadstar"]],
        ["to make do",        ["to make due"]],
        ["mademoiselle",      ["madamoiselle"]],
        ["martial arts",      ["marshall arts"]],
        ["court-martial",     ["court marshall", "court-marshall"]],
        ["maelstrom",         ["maelstorm"]],
        ["mafia",             ["maffia"]],
        ["mafiosi",           ["mafiosos"]],
        ["mangoes",           ["mangos"]],
        ["marijuana",         ["marihuana"]],
        ["marshmallow",       ["marshmellow"]],
        ["martial law",       ["marshall law"]],
        ["massacring",        ["massacering", "massacreing"]],
        ["measles",           ["measels"]],
        ["memento",           ["momento"]],
        ["minuscule",         ["miniscule"]],
        ["mileage",           ["milage"]],
        ["milieu",            ["mileau"]],
        ["millennium",        ["millenium"]],
        ["millennia",         ["millenia"]],
        ["millenniums",       ["milleniums"]],
        ["millipede",         ["millepede"]],
        ["millionaire",       ["millionnaire"]],
        ["milquetoast",       ["milktoast"]],
        ["mimicked",          ["mimiced"]],
        ["mimicking",         ["mimicing"]],
        ["misspelling",       ["mispelling"]],
        ["mischievous",       ["mischievious"]],
        ["moccasin",          ["mocasin", "moccassin", "mocassin"]],
        ["monologue",         ["monolog"]],
        ["monologuist",       ["monologist"]],
        ["naphtha",           ["naptha"]],
        ["navel orange",      ["naval orange"]],
        ["neckwear",          ["neckware"]],
        ["newsstand",         ["newstand"]],
        ["occurred",          ["occured"]],
        ["plantar fasciitis", ["planter fasciitis", "plantar fascitis"]],
        ["pledgeable",        ["pledgable", "pledgeble"]],
        ["portentous",        ["portentuous", "portentious"]],
        ["praying mantis",    ["preying mantis"]],
        ["preestablished",    ["prestablished"]],
        ["preexisting",       ["prexisting"]],
        ["presumptuous",      ["presumptious"]],
        ["rarefy",            ["rarify"]],
        ["reckless",          ["wreckless"]],
        ["remuneration",      ["renumeration"]],
        ["restaurateur",      ["restauranteur"]],
        ["retractable",       ["retractible"]],
        ["reverie",           ["revery"]],
        ["spicy",             ["spicey"]],
        ["stupefy",           ["stupify"]],
        ["subtly",            ["subtley"]],
        ["till",              ["\'till?"]],
        ["tinderbox",         ["tenderbox"]],
        ["timpani",           ["tympani"]],
        ["a timpani",         ["a timpano"]],
        ["umpteenth",         ["umteenth"]],
        ["verbiage",          ["verbage"]],
    ]

    return preferred_forms_check(text, misspellings, err, msg)
<|endoftext|>


<commit_before>from spack import *

class Paraview(Package):
    homepage = 'http://www.paraview.org'
    url      = 'http://www.paraview.org/files/v4.4/ParaView-v4.4.0-source.tar.gz'

    version('4.4.0', 'fa1569857dd680ebb4d7ff89c2227378', url='http://www.paraview.org/files/v4.4/ParaView-v4.4.0-source.tar.gz')

    variant('python', default=False, description='Enable Python support')

    variant('tcl', default=False, description='Enable TCL support')

    variant('mpi', default=False, description='Enable MPI support')

    variant('osmesa', default=False, description='Enable OSMesa support')
    variant('qt', default=False, description='Enable Qt support')
    variant('opengl2', default=False, description='Enable OPengl2 backend')

    depends_on('python', when='+python')
    depends_on('py-numpy', when='+python')
    depends_on('py-matplotlib', when='+python')
    depends_on('tcl', when='+tcl')
    depends_on('mpi', when='+mpi')
    depends_on('qt@:4', when='+qt')

    depends_on('bzip2')
    depends_on('freetype')
    depends_on('hdf5')
    depends_on('hdf5+mpi', when='+mpi')
    depends_on('jpeg')
    depends_on('libpng')
    depends_on('libtiff')
    depends_on('libxml2')
    depends_on('netcdf')
    #depends_on('protobuf') # version mismatches?
    #depends_on('sqlite') # external version not supported
    depends_on('zlib')

    def install(self, spec, prefix):
        with working_dir('spack-build', create=True):
            def feature_to_bool(feature, on='ON', off='OFF'):
                if feature in spec:
                    return on
                return off

            def nfeature_to_bool(feature):
                return feature_to_bool(feature, on='OFF', off='ON')

            feature_args = std_cmake_args[:]
            feature_args.append('-DPARAVIEW_BUILD_QT_GUI:BOOL=%s' % feature_to_bool('+qt'))
            feature_args.append('-DPARAVIEW_ENABLE_PYTHON:BOOL=%s' % feature_to_bool('+python'))
            if '+python' in spec:
                feature_args.append('-DPYTHON_EXECUTABLE:FILEPATH=%s/bin/python' % spec['python'].prefix)
            feature_args.append('-DPARAVIEW_USE_MPI:BOOL=%s' % feature_to_bool('+mpi'))
            if '+mpi' in spec:
                feature_args.append('-DMPIEXEC:FILEPATH=%s/bin/mpiexec' % spec['mpi'].prefix)
            feature_args.append('-DVTK_ENABLE_TCL_WRAPPING:BOOL=%s' % feature_to_bool('+tcl'))
            feature_args.append('-DVTK_OPENGL_HAS_OSMESA:BOOL=%s' % feature_to_bool('+osmesa'))
            feature_args.append('-DVTK_USE_X:BOOL=%s' % nfeature_to_bool('+osmesa'))
            feature_args.append('-DVTK_RENDERING_BACKEND:STRING=%s' % feature_to_bool('+opengl2', 'OpenGL2', 'OpenGL'))

            feature_args.extend(std_cmake_args)

            if 'darwin' in self.spec.architecture:
                feature_args.append('-DVTK_USE_X:BOOL=OFF')
                feature_args.append('-DPARAVIEW_DO_UNIX_STYLE_INSTALLS:BOOL=ON')

            cmake('..',
                '-DCMAKE_INSTALL_PREFIX:PATH=%s' % prefix,
                '-DBUILD_TESTING:BOOL=OFF',
                '-DVTK_USER_SYSTEM_FREETYPE:BOOL=ON',
                '-DVTK_USER_SYSTEM_HDF5:BOOL=ON',
                '-DVTK_USER_SYSTEM_JPEG:BOOL=ON',
                '-DVTK_USER_SYSTEM_LIBXML2:BOOL=ON',
                '-DVTK_USER_SYSTEM_NETCDF:BOOL=ON',
                '-DVTK_USER_SYSTEM_TIFF:BOOL=ON',
                '-DVTK_USER_SYSTEM_ZLIB:BOOL=ON',
                *feature_args)
            make()
            make('install')
<commit_msg>adding new version to praview, compiled with spack -d install -j 8 --keep-stage paraview@5.0.0+qt+python+tcl+opengl2%gcc@4.8.2 ^netcdf -mpi<commit_after>from spack import *

class Paraview(Package):
    homepage = 'http://www.paraview.org'
    url      = 'http://www.paraview.org/files/v5.0/ParaView-v'
    _url_str = 'http://www.paraview.org/files/v%s/ParaView-v%s-source.tar.gz'

    version('4.4.0', 'fa1569857dd680ebb4d7ff89c2227378')
    version('5.0.0', '4598f0b421460c8bbc635c9a1c3bdbee')

    variant('python', default=False, description='Enable Python support')

    variant('tcl', default=False, description='Enable TCL support')

    variant('mpi', default=False, description='Enable MPI support')

    variant('osmesa', default=False, description='Enable OSMesa support')
    variant('qt', default=False, description='Enable Qt support')
    variant('opengl2', default=False, description='Enable OPengl2 backend')

    depends_on('python', when='+python')
    depends_on('py-numpy', when='+python')
    depends_on('py-matplotlib', when='+python')
    depends_on('tcl', when='+tcl')
    depends_on('mpi', when='+mpi')
    depends_on('qt@:4', when='+qt')

    depends_on('bzip2')
    depends_on('freetype')
    depends_on('hdf5+mpi', when='+mpi')
    depends_on('hdf5~mpi', when='~mpi')
    depends_on('jpeg')
    depends_on('libpng')
    depends_on('libtiff')
    depends_on('libxml2')
    depends_on('netcdf')
    #depends_on('protobuf') # version mismatches?
    #depends_on('sqlite') # external version not supported
    depends_on('zlib')

    def url_for_version(self, version):
        """Handle ParaView version-based custom URLs."""
        return self._url_str % (version.up_to(2), version)

    def install(self, spec, prefix):
        with working_dir('spack-build', create=True):
            def feature_to_bool(feature, on='ON', off='OFF'):
                if feature in spec:
                    return on
                return off

            def nfeature_to_bool(feature):
                return feature_to_bool(feature, on='OFF', off='ON')

            feature_args = std_cmake_args[:]
            feature_args.append('-DPARAVIEW_BUILD_QT_GUI:BOOL=%s' % feature_to_bool('+qt'))
            feature_args.append('-DPARAVIEW_ENABLE_PYTHON:BOOL=%s' % feature_to_bool('+python'))
            if '+python' in spec:
                feature_args.append('-DPYTHON_EXECUTABLE:FILEPATH=%s/bin/python' % spec['python'].prefix)
            feature_args.append('-DPARAVIEW_USE_MPI:BOOL=%s' % feature_to_bool('+mpi'))
            if '+mpi' in spec:
                feature_args.append('-DMPIEXEC:FILEPATH=%s/bin/mpiexec' % spec['mpi'].prefix)
            feature_args.append('-DVTK_ENABLE_TCL_WRAPPING:BOOL=%s' % feature_to_bool('+tcl'))
            feature_args.append('-DVTK_OPENGL_HAS_OSMESA:BOOL=%s' % feature_to_bool('+osmesa'))
            feature_args.append('-DVTK_USE_X:BOOL=%s' % nfeature_to_bool('+osmesa'))
            feature_args.append('-DVTK_RENDERING_BACKEND:STRING=%s' % feature_to_bool('+opengl2', 'OpenGL2', 'OpenGL'))

            feature_args.extend(std_cmake_args)

            if 'darwin' in self.spec.architecture:
                feature_args.append('-DVTK_USE_X:BOOL=OFF')
                feature_args.append('-DPARAVIEW_DO_UNIX_STYLE_INSTALLS:BOOL=ON')

            cmake('..',
                '-DCMAKE_INSTALL_PREFIX:PATH=%s' % prefix,
                '-DBUILD_TESTING:BOOL=OFF',
                '-DVTK_USER_SYSTEM_FREETYPE:BOOL=ON',
                '-DVTK_USER_SYSTEM_HDF5:BOOL=ON',
                '-DVTK_USER_SYSTEM_JPEG:BOOL=ON',
                '-DVTK_USER_SYSTEM_LIBXML2:BOOL=ON',
                '-DVTK_USER_SYSTEM_NETCDF:BOOL=ON',
                '-DVTK_USER_SYSTEM_TIFF:BOOL=ON',
                '-DVTK_USER_SYSTEM_ZLIB:BOOL=ON',
                *feature_args)
            make()
            make('install')
<|endoftext|>


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

supported_extensions = ['jpeg', 'jpg', 'gif', 'png']

import os
import tensorflow as tf
from preprocessing import vgg_preprocessing as prep

tf.enable_eager_execution()     # execute commands immediately, instead of creating a graph and waiting for sess.run()

# Load and preprocess image
def load_image(image_path,            # Full path to processing image
               target_size            # Desired size of resulting image
               ):

  image_raw     = tf.read_file(image_path)
  image_tensor  = tf.image.decode_image(image_raw)

  preprocessed_float_numpy  = prep.preprocess_image(image_tensor, target_size, target_size).numpy()

  return preprocessed_float_numpy

def preprocess_files(selected_filenames, source_dir, destination_dir, square_side, data_type, new_file_extension):
    "Go through the selected_filenames and preprocess all the files"

    output_filenames = []

    for current_idx in range(len(selected_filenames)):
        input_filename = selected_filenames[current_idx]

        full_input_path     = os.path.join(source_dir, input_filename)

        image_data = load_image(image_path = full_input_path,
                              target_size = square_side)

        output_filename = input_filename.rsplit('.', 1)[0] + '.' + new_file_extension if new_file_extension else input_filename

        full_output_path    = os.path.join(destination_dir, output_filename)
        image_data.tofile(full_output_path)

        print("[{}]:  Stored {}".format(current_idx+1, full_output_path) )

        output_filenames.append(output_filename)

    return output_filenames

if __name__ == '__main__':
    import sys

    source_dir              = sys.argv[1]   # ignored if CK_IMAGE_FILE points to a file
    destination_dir         = sys.argv[2]

    square_side             = int( os.environ['_INPUT_SQUARE_SIDE'] )
    offset                  = int( os.getenv('_SUBSET_OFFSET', 0) )
    volume_str              = os.getenv('_SUBSET_VOLUME', '' )
    fof_name                = os.getenv('_SUBSET_FOF', 'fof.txt')
    data_type               = os.getenv('_DATA_TYPE', 'uint8')
    new_file_extension      = os.getenv('_NEW_EXTENSION', '')
    image_file              = os.getenv('CK_IMAGE_FILE', '')

    print("From: {} , To: {} , Size: {} , OFF: {}, VOL: '{}', FOF: {}, DTYPE: {}, EXT: {}, IMG: {}".format(
        source_dir, destination_dir, square_side, offset, volume_str, fof_name, data_type, new_file_extension, image_file) )

    if image_file:
        source_dir          = os.path.dirname(image_file)
        selected_filenames  = [ os.path.basename(image_file) ]

    elif os.path.isdir(source_dir):
        sorted_filenames = [filename for filename in sorted(os.listdir(source_dir)) if any(filename.lower().endswith(extension) for extension in supported_extensions) ]

        total_volume = len(sorted_filenames)

        if offset<0:        # support offsets "from the right"
            offset += total_volume

        volume = int(volume_str) if len(volume_str)>0 else total_volume-offset

        selected_filenames = sorted_filenames[offset:offset+volume]

    output_filenames = preprocess_files(selected_filenames, source_dir, destination_dir, square_side, data_type, new_file_extension)

    fof_full_path = os.path.join(destination_dir, fof_name)
    with open(fof_full_path, 'w') as fof:
        for filename in output_filenames:
            fof.write(filename + '\n')
<commit_msg>bugfix: force-convert grayscale (1-channel) images to RGB (3-channel)<commit_after>#!/usr/bin/env python3

supported_extensions = ['jpeg', 'jpg', 'gif', 'png']

import os
import tensorflow as tf
from preprocessing import vgg_preprocessing as prep

tf.enable_eager_execution()     # execute commands immediately, instead of creating a graph and waiting for sess.run()

# Load and preprocess image
def load_image(image_path,            # Full path to processing image
               target_size            # Desired size of resulting image
               ):

    image_raw     = tf.read_file(image_path)
    image_tensor  = tf.image.decode_image(image_raw)

    if image_tensor.get_shape()[2]==1:
        image_tensor = tf.image.grayscale_to_rgb( image_tensor )

    preprocessed_float_numpy  = prep.preprocess_image(image_tensor, target_size, target_size).numpy()

    return preprocessed_float_numpy

def preprocess_files(selected_filenames, source_dir, destination_dir, square_side, data_type, new_file_extension):
    "Go through the selected_filenames and preprocess all the files"

    output_filenames = []

    for current_idx in range(len(selected_filenames)):
        input_filename = selected_filenames[current_idx]

        full_input_path     = os.path.join(source_dir, input_filename)

        image_data = load_image(image_path = full_input_path,
                              target_size = square_side)

        output_filename = input_filename.rsplit('.', 1)[0] + '.' + new_file_extension if new_file_extension else input_filename

        full_output_path    = os.path.join(destination_dir, output_filename)
        image_data.tofile(full_output_path)

        print("[{}]:  Stored {}".format(current_idx+1, full_output_path) )

        output_filenames.append(output_filename)

    return output_filenames

if __name__ == '__main__':
    import sys

    source_dir              = sys.argv[1]   # ignored if CK_IMAGE_FILE points to a file
    destination_dir         = sys.argv[2]

    square_side             = int( os.environ['_INPUT_SQUARE_SIDE'] )
    offset                  = int( os.getenv('_SUBSET_OFFSET', 0) )
    volume_str              = os.getenv('_SUBSET_VOLUME', '' )
    fof_name                = os.getenv('_SUBSET_FOF', 'fof.txt')
    data_type               = os.getenv('_DATA_TYPE', 'uint8')
    new_file_extension      = os.getenv('_NEW_EXTENSION', '')
    image_file              = os.getenv('CK_IMAGE_FILE', '')

    print("From: {} , To: {} , Size: {} , OFF: {}, VOL: '{}', FOF: {}, DTYPE: {}, EXT: {}, IMG: {}".format(
        source_dir, destination_dir, square_side, offset, volume_str, fof_name, data_type, new_file_extension, image_file) )

    if image_file:
        source_dir          = os.path.dirname(image_file)
        selected_filenames  = [ os.path.basename(image_file) ]

    elif os.path.isdir(source_dir):
        sorted_filenames = [filename for filename in sorted(os.listdir(source_dir)) if any(filename.lower().endswith(extension) for extension in supported_extensions) ]

        total_volume = len(sorted_filenames)

        if offset<0:        # support offsets "from the right"
            offset += total_volume

        volume = int(volume_str) if len(volume_str)>0 else total_volume-offset

        selected_filenames = sorted_filenames[offset:offset+volume]

    output_filenames = preprocess_files(selected_filenames, source_dir, destination_dir, square_side, data_type, new_file_extension)

    fof_full_path = os.path.join(destination_dir, fof_name)
    with open(fof_full_path, 'w') as fof:
        for filename in output_filenames:
            fof.write(filename + '\n')
<|endoftext|>


<commit_before># Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *

class Pciutils(MakefilePackage):
    """This package contains the PCI Utilities."""

    homepage = "https://mj.ucw.cz/sw/pciutils/"
    url      = "https://github.com/pciutils/pciutils/archive/v3.7.0.tar.gz"

    version('3.7.0', sha256='ea768aa0187ba349391c6c157445ecc2b42e7d671fc1ce8c53ff5ef513f1e2ab')
    version('3.6.4', sha256='551d0ac33f030868b7e95c29e58dc2b1882455dbc9c15c15adf7086e664131f1')
    version('3.6.3', sha256='7ab0fbb35cffa326eb852539260562bac14f3d27cda8c70bc2cf3211ed97c014')

    def install(self, spec, prefix):
        make('install', 'PREFIX={0}'.format(prefix))

    def setup_run_environment(self, env):
        env.prepend_path('PATH', self.prefix.sbin)
<commit_msg>install lib/headers option support (#21186)<commit_after># Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *

class Pciutils(MakefilePackage):
    """This package contains the PCI Utilities."""

    homepage = "https://mj.ucw.cz/sw/pciutils/"
    url      = "https://github.com/pciutils/pciutils/archive/v3.7.0.tar.gz"

    version('3.7.0', sha256='ea768aa0187ba349391c6c157445ecc2b42e7d671fc1ce8c53ff5ef513f1e2ab')
    version('3.6.4', sha256='551d0ac33f030868b7e95c29e58dc2b1882455dbc9c15c15adf7086e664131f1')
    version('3.6.3', sha256='7ab0fbb35cffa326eb852539260562bac14f3d27cda8c70bc2cf3211ed97c014')

    variant('lib', default=False, description='Install libraries with headers')

    def install(self, spec, prefix):
        if '+lib' in spec:
            make('install-lib', 'install', 'PREFIX={0}'.format(prefix))
        else:
            make('install', 'PREFIX={0}'.format(prefix))

    def setup_run_environment(self, env):
        env.prepend_path('PATH', self.prefix.sbin)
<|endoftext|>