
from iatidq import db

import models
import csv
import util
import urllib2

def _importPCs(fh, local=True):
    
    results = {}
    for n, line in enumerate(fh):
        text = line.strip('\n')
        results[n]=text
        
    import dqparseconditions
    test_functions = dqparseconditions.parsePC(results)
    tested_results = []
    for n, line in results.items():
        data = test_functions[n](line)
        data["description"] = line
        tested_results.append(data)

    return tested_results

def importPCsFromFile(filename='tests/organisation_structures.txt', local=True):
    with file(filename) as fh:
        return _importPCs(fh, local=True) 

def importPCsFromUrl(url):
    fh = urllib2.urlopen(url)
    return _importPCs(fh, local=False)

if __name__ == "__main__":
    importPCs('../tests/organisation_structures.txt')


from iatidq import db

import models
import csv
import util
import urllib2

def _parsePCresults(results):
    import dqparseconditions
    test_functions = dqparseconditions.parsePC(results)
    tested_results = []
    for n, line in results.items():
        data = test_functions[n](line)
        data["description"] = line
        tested_results.append(data)

    return tested_results

def importPCsFromText(text):
    results = {}
    for n, line in enumerate(text.split("\n")):
        results[n]=line
    return _parsePCresults(results)

def _importPCs(fh, local=True):
    results = {}
    for n, line in enumerate(fh):
        text = line.strip('\n')
        results[n]=text
    return _parsePCresults(results)

def importPCsFromFile(filename='tests/organisation_structures.txt', local=True):
    with file(filename) as fh:
        return _importPCs(fh, local=True) 

def importPCsFromUrl(url):
    fh = urllib2.urlopen(url)
    return _importPCs(fh, local=False)

if __name__ == "__main__":
    importPCs('../tests/organisation_structures.txt')

Allow publisher conditions to be imported from text
Allow publisher conditions to be imported from text

  
  from iatidq import db
  
  import models
  import csv
  import util
  import urllib2
  
+ def _parsePCresults(results):
- def _importPCs(fh, local=True):
-     
-     results = {}
-     for n, line in enumerate(fh):
-         text = line.strip('\n')
-         results[n]=text
-         
      import dqparseconditions
      test_functions = dqparseconditions.parsePC(results)
      tested_results = []
      for n, line in results.items():
          data = test_functions[n](line)
          data["description"] = line
          tested_results.append(data)
  
      return tested_results
+ 
+ def importPCsFromText(text):
+     results = {}
+     for n, line in enumerate(text.split("\n")):
+         results[n]=line
+     return _parsePCresults(results)
+ 
+ def _importPCs(fh, local=True):
+     results = {}
+     for n, line in enumerate(fh):
+         text = line.strip('\n')
+         results[n]=text
+     return _parsePCresults(results)
  
  def importPCsFromFile(filename='tests/organisation_structures.txt', local=True):
      with file(filename) as fh:
          return _importPCs(fh, local=True) 
  
  def importPCsFromUrl(url):
      fh = urllib2.urlopen(url)
      return _importPCs(fh, local=False)
  
  if __name__ == "__main__":
      importPCs('../tests/organisation_structures.txt')
  
Allow publisher conditions to be imported from text
## Code Before:

from iatidq import db

import models
import csv
import util
import urllib2

def _importPCs(fh, local=True):
    
    results = {}
    for n, line in enumerate(fh):
        text = line.strip('\n')
        results[n]=text
        
    import dqparseconditions
    test_functions = dqparseconditions.parsePC(results)
    tested_results = []
    for n, line in results.items():
        data = test_functions[n](line)
        data["description"] = line
        tested_results.append(data)

    return tested_results

def importPCsFromFile(filename='tests/organisation_structures.txt', local=True):
    with file(filename) as fh:
        return _importPCs(fh, local=True) 

def importPCsFromUrl(url):
    fh = urllib2.urlopen(url)
    return _importPCs(fh, local=False)

if __name__ == "__main__":
    importPCs('../tests/organisation_structures.txt')

## Instruction:
Allow publisher conditions to be imported from text
## Code After:

from iatidq import db

import models
import csv
import util
import urllib2

def _parsePCresults(results):
    import dqparseconditions
    test_functions = dqparseconditions.parsePC(results)
    tested_results = []
    for n, line in results.items():
        data = test_functions[n](line)
        data["description"] = line
        tested_results.append(data)

    return tested_results

def importPCsFromText(text):
    results = {}
    for n, line in enumerate(text.split("\n")):
        results[n]=line
    return _parsePCresults(results)

def _importPCs(fh, local=True):
    results = {}
    for n, line in enumerate(fh):
        text = line.strip('\n')
        results[n]=text
    return _parsePCresults(results)

def importPCsFromFile(filename='tests/organisation_structures.txt', local=True):
    with file(filename) as fh:
        return _importPCs(fh, local=True) 

def importPCsFromUrl(url):
    fh = urllib2.urlopen(url)
    return _importPCs(fh, local=False)

if __name__ == "__main__":
    importPCs('../tests/organisation_structures.txt')
