# Path: common.py
# def init(workDBName, dropWorkDB=False, matchDBName = None, dropMatchDB=False,
#          indexes=False):
# def checkStatusUpdate(fromStat, toStat):
# def get_id(what):
# def deleteDB(dbname):
# def rmMatchData(dbname):
# def infoDB(dbname):
# 
# Path: workFlow.py
# def workFlowUI(user, workingDir):
#     files = []
#     if not workingDir:
#         rootdir = "./files/" 
#         if user == 'guest':
#             #get temporary directory (do NOT use '_' in directorynames)
#             workingDir = ''
#             tempdir = rootdir + 'GUEST'
#             for i in xrange(1000):
#                 workingDir = '%s%04d' % (tempdir, i)
#                 if not os.path.isdir(workingDir):
#                     try:
#                         os.mkdir(workingDir)
#                         user = '%s%04d' % (user, i)
#                         break
#                     except OSError:
#                         continue
#         else:
#             workingDir = rootdir + user
#             if not os.path.isdir(workingDir):
#                 os.mkdir(workingDir)
#     for file in glob.glob(workingDir + "/*.GED_*"):
#         files.append(os.path.basename(file))
#     for file in glob.glob(workingDir + "/*.ged_*"):
#         files.append(os.path.basename(file))
#     dbs = []
#     #8 = len rootdir FIX!
#     activeUser = workingDir[8:]
#     for db in client.database_names():
#         if db.startswith(activeUser+'_') or (user == 'admin'):
#             dbs.append(db)
#     return (files, dbs, workingDir, activeUser)
# 
# Path: dbUtils.py
# def getFamilyFromId(famId, familyDB, relationsDB):
#     """
#     Build a full family record (husb,wife,marriage,children)
#     from a familyId
#     """
#     famRecord = familyDB.find_one({'_id': famId})
#     if famRecord is None: return None
#     famRecord['husb'] = None
#     famRecord['wife'] = None
#     famRecord['children'] = []
#     for member in relationsDB.find({'famId': famRecord['_id']}):
#         if member['relTyp'] == 'child': famRecord['children'].append(member['persId'])
#         else: famRecord[member['relTyp']] = member['persId']
#         #if 'husb' in member: famRecord['husb'] = member['husb']
#         #elif 'wife' in member: famRecord['wife'] = member['wife']
#         #elif 'child' in member: famRecord['children'].append(member['child'])
#     return famRecord


import argparse, sys, os, datetime, re
import pickle
import common
import codecs, locale
import json
import datePrecision
                import unicodedata
from collections import defaultdict
from common import RGDadm 
from workFlow import workFlowUI
from dbUtils import getFamilyFromId
from gedcom.gedcom import *
            for e in ev.children_lines():
                if e.tag()=='DATE': date = firstDate(e.value())
            if date==0: date = dateNo
            #if debug: print 'Using::', ev.tag(), date
            evs[date].append(ev)
        for key in sorted(evs.iterkeys()):
            for ev in evs[key]:
                #if debug: print 'Printing::', ev.tag(), key
                print gedcomNoRGD(ev)
    if 'death' in ind and ind['death']['tag'] == 'DEAT':
        if 'date' in ind['death'] or 'place' in ind['death'] or 'source' in ind['death']:
            print "1", mapGedcom['death']
            for item in ('date', 'place', 'source'):
                if item in ind['death']: printTag("2 "+mapGedcom[item],ind['death'][item])
    if 'BURI' in gedEvents: gedPrintMergeEvent(gedEvents['BURI'])
    if gedTags: gedPrintUniqueTag(gedTags)
    if ind['_id'] in  mapFamc: printTagF("1 FAMC", mapFamc[ind['_id']])
    for rel in config['relations'].find({'persId': ind['_id']}):
        #Sort chronological?
        if rel['relTyp'] == 'child': continue
        printTagF("1 FAMS",rel['famId'])
    #CHAN-tag
    if len(parsedGed) == 1 and chanTag:
        print gedcomNoRGD(chanTag)
    else:
        print '1 CHAN'
        print today.strftime('2 DATE %d %b %Y').upper() # 27 DEC 2011
        print today.strftime('3 TIME %H:%M:%S')         # 07:52:26

for famRec in config['families'].find({}):

# Path: common.py
# def init(workDBName, dropWorkDB=False, matchDBName = None, dropMatchDB=False,
#          indexes=False):
# def checkStatusUpdate(fromStat, toStat):
# def get_id(what):
# def deleteDB(dbname):
# def rmMatchData(dbname):
# def infoDB(dbname):
# 
# Path: workFlow.py
# def workFlowUI(user, workingDir):
#     files = []
#     if not workingDir:
#         rootdir = "./files/" 
#         if user == 'guest':
#             #get temporary directory (do NOT use '_' in directorynames)
#             workingDir = ''
#             tempdir = rootdir + 'GUEST'
#             for i in xrange(1000):
#                 workingDir = '%s%04d' % (tempdir, i)
#                 if not os.path.isdir(workingDir):
#                     try:
#                         os.mkdir(workingDir)
#                         user = '%s%04d' % (user, i)
#                         break
#                     except OSError:
#                         continue
#         else:
#             workingDir = rootdir + user
#             if not os.path.isdir(workingDir):
#                 os.mkdir(workingDir)
#     for file in glob.glob(workingDir + "/*.GED_*"):
#         files.append(os.path.basename(file))
#     for file in glob.glob(workingDir + "/*.ged_*"):
#         files.append(os.path.basename(file))
#     dbs = []
#     #8 = len rootdir FIX!
#     activeUser = workingDir[8:]
#     for db in client.database_names():
#         if db.startswith(activeUser+'_') or (user == 'admin'):
#             dbs.append(db)
#     return (files, dbs, workingDir, activeUser)
# 
# Path: dbUtils.py
# def getFamilyFromId(famId, familyDB, relationsDB):
#     """
#     Build a full family record (husb,wife,marriage,children)
#     from a familyId
#     """
#     famRecord = familyDB.find_one({'_id': famId})
#     if famRecord is None: return None
#     famRecord['husb'] = None
#     famRecord['wife'] = None
#     famRecord['children'] = []
#     for member in relationsDB.find({'famId': famRecord['_id']}):
#         if member['relTyp'] == 'child': famRecord['children'].append(member['persId'])
#         else: famRecord[member['relTyp']] = member['persId']
#         #if 'husb' in member: famRecord['husb'] = member['husb']
#         #elif 'wife' in member: famRecord['wife'] = member['wife']
#         #elif 'child' in member: famRecord['children'].append(member['child'])
#     return famRecord


# Path: exportGedcom.py
import argparse, sys, os, datetime, re
import pickle
import common
import codecs, locale
import json
import datePrecision
                import unicodedata
from collections import defaultdict
from common import RGDadm 
from workFlow import workFlowUI
from dbUtils import getFamilyFromId
from gedcom.gedcom import *

            for e in ev.children_lines():
                if e.tag()=='DATE': date = firstDate(e.value())
            if date==0: date = dateNo
            #if debug: print 'Using::', ev.tag(), date
            evs[date].append(ev)
        for key in sorted(evs.iterkeys()):
            for ev in evs[key]:
                #if debug: print 'Printing::', ev.tag(), key
                print gedcomNoRGD(ev)
    if 'death' in ind and ind['death']['tag'] == 'DEAT':
        if 'date' in ind['death'] or 'place' in ind['death'] or 'source' in ind['death']:
            print "1", mapGedcom['death']
            for item in ('date', 'place', 'source'):
                if item in ind['death']: printTag("2 "+mapGedcom[item],ind['death'][item])
    if 'BURI' in gedEvents: gedPrintMergeEvent(gedEvents['BURI'])
    if gedTags: gedPrintUniqueTag(gedTags)
    if ind['_id'] in  mapFamc: printTagF("1 FAMC", mapFamc[ind['_id']])
    for rel in config['relations'].find({'persId': ind['_id']}):
        #Sort chronological?
        if rel['relTyp'] == 'child': continue
        printTagF("1 FAMS",rel['famId'])
    #CHAN-tag
    if len(parsedGed) == 1 and chanTag:
        print gedcomNoRGD(chanTag)
    else:
        print '1 CHAN'
        print today.strftime('2 DATE %d %b %Y').upper() # 27 DEC 2011
        print today.strftime('3 TIME %H:%M:%S')         # 07:52:26

for famRec in config['families'].find({}):

    fam = getFamilyFromId(famRec['_id'], config['families'], config['relations'])