Ejemplo n.º 1
0
def saveRealm(fn):
  fn = config['realmfile']
  if fn is not None and fn != "":
    backends.saveRealm(fn)
  else:
    saveRealmAs()
  common.bsay("?","Saved.")
Ejemplo n.º 2
0
def saveThisC(caller, fileid):
    global status
    if cities.get(fileid):
        if saveCity(fileid, cities[fileid]):
            status.push(0, "%s saved successfully." % fileid)
        else:
            status.push(0, "Error encountered saving %s." % fileid)
    else:
        bsay(caller, "saveThisC: Could not find city %s." % fileid)
Ejemplo n.º 3
0
def saveThisL(caller,fileid):
  global status
  if places.get(fileid):
    if savePlace(fileid,places[fileid]):
      status.push(0,"%s saved successfully." % fileid)
    else:
      status.push(0,"Error encountered saving %s." % fileid)
  else:
    bsay(caller,"saveThisL: Could not find place %s." % fileid)
Ejemplo n.º 4
0
def saveThisP(caller,fileid):
  global status
  if people.get(fileid):
    if savePerson(fileid,people[fileid]):
      status.push(0,"%s saved successfully." % fileid)
    else:
      status.push(0,"Error encountered saving %s." % fileid)
  else:
    bsay(caller,"saveThisP: Could not find person %s." % fileid)
Ejemplo n.º 5
0
def saveThisS(caller,fileid):
  global status
  if states.get(fileid):
    pushLoc(fileid,states[fileid].get('name'))
    if saveState(fileid,states[fileid]):
      status.push(0,"%s saved successfully." % fileid)
    else:
      status.push(0,"Error encountered saving %s." % fileid)
  else:
    bsay(caller,"saveThisS: Could not find state %s." % fileid)
Ejemplo n.º 6
0
def writefile(fn,lines,create = False):
  if create or os.path.exists(os.path.abspath(fn)):
    try:
      f = codecs.open(os.path.abspath(fn),'wU',"UTF-8")
      f.writelines(lines)
      f.close()
    except IOError as e:
      bsay(None, " Could not write story file: %s" % e)
      return
    status.push(0,"%s written successfully." % fn)
  else:
    bsay("File not found and not created: %s" % fn)
Ejemplo n.º 7
0
def getCitiesIn(state):
  if state.find(".xml") > -1: state = state.split('.')[0]
  if state:
    data = placeList.get(state)
    if data is not None:
      keys = data.keys()
      if keys is not None:
        return data
      else:
        common.bsay("?","State %s is empty in placeList" % state)
    else:
      common.bsay("?","State %s not found in placeList" % state)
  return {}
Ejemplo n.º 8
0
def readfile(fn,verbose = True):
  lines = []
  if os.path.exists(os.path.abspath(fn)):
    try:
      with codecs.open(os.path.abspath(fn),'rU','utf-8') as f:
        lines = f.readlines()
        f.close()
    except IOError as e:
      if verbose: bsay(None, " Could not open file: %s" % e)
    status.push(0,"File read successfully: %s" % fn)
  else:
    if verbose: bsay(None,"File not found: %s" % fn)
  return lines
Ejemplo n.º 9
0
def addRelToBox(self,target,relid,fileid,tabs,scroll,ar,plalts):
  global places
  cat = relid[1]
  relid = relid[0]
  if cat == 'p': global people
  if preRead(True,'l',[fileid,"relat"],2):
    name = []
    rels = {}
    nameperson = ""
    if not preRead(False,'l',[fileid,"relat",relid],3):
      if not preRead(False,'l',relid,1):
        pl = loadPlace(relid)
        inf = pl[0]
        try:
          inf.get("foo",None)
        except AttributeError:
          print "(l)addRelToBox: Load Error"
          return
        try:
          name = [inf['commonname'][0],inf["name"][0]]
        except KeyError as e:
          print "(l)addRelToBox: An error occurred accessing relation %s: %s" % (relid,e)
          return
      else:
        try:
          name = [people[relid]['info']['commonname'][0],people[relid]['info']['gname'][0],people[relid]['info']['fname'][0]]
        except KeyError as e:
          print "(l)addRelToBox: An error occurred accessing person %s: %s" % (relid,e)
          return
      if len(name[0]) > 2:
        nameperson = name[0]
      elif config['familyfirst']:
        nameperson = name[2] + " " + name[1]
      else:
        nameperson = name[1] + " " + name[2]
      places[fileid]['relat'][relid] = {}
      places[fileid]['relat'][relid]['file'] = [relid,True]
      places[fileid]['relat'][relid]['related'] = [nameperson,True]
      places[fileid]['relat'][relid]['relation'] = ["",False] # Add a dialog here
      places[fileid]['relat'][relid]['cat'] = [cat,True]
      places[fileid]['relat'][relid]['rtype'] = ["",False] # Perhaps all these things in one dialog
      places[fileid]['relat'][relid]['realm'] = ["",False] # Only write this one if user chooses a realm
      # Realm needs to be addressed in the DTD for XML files... not sure if it's hierarchically higher than relat or not, or if realm should just reference connections, rather than be part of their tree (people[fileid]['realm'][realm] = [list,of,relids])
      places[fileid]['relat'][relid]['events'] = {}
      places[fileid]['changed'] = True
      listRel(target,ar,plalts,places[fileid]['relat'][relid],fileid,relid,scroll,tabs)
    else:
      bsay(self,"Not clobbering existing connection to %s!" % relid)
      return
Ejemplo n.º 10
0
def setGender(caller,fileid,key,ar,alts):
  global people
  if key != None and len(key) > 1:
    genderkeys = allGenders(1)
    key = genderkeys.get(key,'N')
    if config['debug'] > 3: print "new key: %s" % key
  if preRead(False,'p',[fileid,"info","gender"],2):
    people[fileid]['info']['gender'] = [key,True]
    people[fileid]['changed'] = True
    if config['debug'] > 2: print "New Gender: %s" % key
  else:
    bsay(None,"setGender: Could not set gender for %s." % fileid)
  if caller not in alts: alts.append(caller)
  caller.modify_base(gtk.STATE_NORMAL,gtk.gdk.color_parse(config['altcolor']))
  setRuletext(ar,len(alts))
Ejemplo n.º 11
0
def setLoc(caller,fileid,key):
  global places
  lockeys = {}
  if len(key) > 1:
    lockeys = getCityList(1)
    key = lockeys.get(key,'N')
    lockeys = getCityList()
    if config['debug'] > 3: print "new key: %s" % key
    print "%s (%s), %s (%s)" % (lockeys[key][0],key,lockeys[key][2],lockeys[key][1])
    if preRead(False,'l',[fileid,"info"],2):
      places[fileid]['info']['locfile'] = [key,True]
      places[fileid]['info']['loc'] = [lockeys[key][0],True]
      places[fileid]['info']['statefile'] = [lockeys[key][1],True]
      places[fileid]['info']['state'] = [lockeys[key][2],True]
      places[fileid]['changed'] = True
      if config['debug'] > 0: print "New Loc: %s" % key
  else:
    bsay(None,"setLoc: Could not set loc for %s." % fileid)
Ejemplo n.º 12
0
def setState(caller, fileid, key):
    global cities
    statekeys = {}
    if len(key) > 1:
        statekeys = getStateList(1)
        key = statekeys.get(key, "N")
        statekeys = getStateList(0)
        if config["debug"] > 3:
            print "new key: %s" % key
        print "%s (%s)" % (statekeys[key], key)
        if preRead(False, "c", [fileid, "info"], 2):
            cities[fileid]["info"]["statefile"] = [key, True]
            cities[fileid]["info"]["state"] = [statekeys[key], True]
            cities[fileid]["changed"] = True
            #      if config['debug'] > 0: print "New State: %s" % key
            cityname = cities[fileid]["info"].get("name", None)
            if cityname:
                updateLocs(cityname[0], fileid, key)
    else:
        bsay(None, "setState: Could not set state for %s." % fileid)
Ejemplo n.º 13
0
def validateRealm(realm):
  for key in realm.keys():
    if key not in rlmkeys: # Only allow keys in the realm-specific keys list
      del realm[key]
  for key in rlmkeys:
    # XML file options
    if key == "dtdurl":
      realm['dtdurl'] = realm.get("dtddir",os.path.join("../../",realm['dtddir']))
    # other options
    else:
      realm[key] = realm.get(key,defaults[key])
      if realm[key] == "True": realm[key] = True
      if realm[key] == "False": realm[key] = False
  if not os.path.exists(os.path.abspath(realm['realmdir'])): # must be a valid directory
    if not config.get("makerd",False):
      bsay("?","Fatal error. Realm directory %s does not exist! Exiting." % os.path.abspath(realm['realmdir']))
      exit(-1)
    else:
      print "Stupid programmer: Function missing! Write function to create realmdir!"
      exit(-1)
  return realm
Ejemplo n.º 14
0
def saveXMLtree(tree,category,fileid):
  out = ""
  if config['debug'] > 6: printPretty(etree.tostring(tree),True,True)
  try:
    out = etree.tostring(tree,pretty_print=True)
  except TypeError: # for me, previous line results in "unexpected keyword argument 'pretty_print'"
    out = xmlout.prettyXML(tree)
  start = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\""
  start += os.path.join(config['xslurl'],"%s.xsl" % category)
  start += "\"?>\n<!DOCTYPE person SYSTEM \"%s%s.dtd\">\n" % (config['dtdurl'],category)
  finaloutput = start + out
  if config['debug'] > 0: print finaloutput
  fn = os.path.join(os.path.abspath(config['realmdir']),fileid + ".xml")
  try:
    with codecs.open(fn,'wU','UTF-8') as f:
      f.write(finaloutput)
      f.close()
  except IOError as e:
    message = "The file %s could not be saved: %s" % (fn,e)
    common.bsay("?",message)
    status.push(0,message)
    return False
  return True
Ejemplo n.º 15
0
def showHelp(caller,parent):
  common.bsay(parent,"Icons provided by http://www.fatcow.com/free-icons")
Ejemplo n.º 16
0
def loadPlace(fileid):
  """Given an id (filename) matching an XML file in the appropriate
  directory, loads the tree from the file and pushes its data into
  two dictionaries, which it returns as a tuple.
  """
  dinf = {}
  drel = {}
  root = etree.Element("place")
  text = None
  city = ""
  cityf = ""
  state = ""
  statef = ""
  placename = ""
  # TODO: put this in a global variable, and make a function to populate it from the DTD.
  tags = ["commonname","name","start","scue","end","ecue","stories","mention","desc","address","loc","locfile","state","statefile","note", "relat","update"]
  tags.remove("note")
  tags.remove("relat")
  tags.append("file")
  for tag in tags:
    dinf[tag] = ["",False]
  # if no relations or notes, leave blank
  dinf['aspects'] = {}
  if not idExists(fileid):
    status.push(0,"new place created... '%s'" % fileid)
    return (dinf,drel)
  fn = os.path.join(config['realmdir'],"%s.xml" % fileid)
  status.push(0,"loading place from XML... '%s'" % fn)
  try:
    with codecs.open(fn,'rU','utf-8') as f:
      tree = etree.parse(f)
      f.close()
      root = tree.getroot()
  except IOError as e:
    print " Could not open place file: %s" % e

  ir = 0
  for i in range(len(root)):
    if root[i].tag is not None:
      if root[i].tag == "relat":
        node = ""
        try:
          node = root[i].find("file").text.strip()
        except AttributeError:
          common.bsay("?","XML formatting error in %s! Probably an empty relat tag." % fileid)
        node = common.validateFileid(node)
        drel[node] = {}
        for j in root[i]:
          if j.tag == "events":
            if not drel[node].get('events'): drel[node]['events'] = {}
            for k in j:
              stone = str(len(drel[node]['events']))
              drel[node]['events'][stone] = {}
              for m in k:
                if m.tag and m.text:
                  drel[node]['events'][stone][m.tag] = [m.text.strip(),False]
          else: # elif j.tag != "file":
            if j.tag and j.text:
              drel[node][j.tag] = [j.text.strip(),False]
        if config['debug'] > 3: print drel[node]
      elif root[i].tag == "note":
#        print ",",
        if not dinf.get("notes"):
          dinf['notes'] = {}
        x = str(len(dinf['notes']))
        dinf['notes'][x] = {}
        try:
          dinf['notes'][x]['content'] = [root[i].find("content").text.strip(),False]
        except AttributeError:
          del dinf['notes'][x]
        if dinf['notes'].get(x):
          dinf['notes'][x]['date'] = [root[i].find("date").text.strip(),False]
#      elif root[i].tag == "formocc":
#        print ",",
      elif root[i].tag == "aspects":
        if len(root[i]) > 0:
          nodes = root[i]
          for node in nodes:
            k = str(len(dinf['aspects']))
            dinf['aspects'][k] = {}
            if node.tag and node.text:
              dinf['aspects'][k] = [node.text.strip(),False]
            else:
              if config['debug'] > 0:
                print "Invalid aspects tag:"
                print node.tag + ': ' + node.text,
        else: # no aspects length
          if config['debug'] > 0: print "Empty aspects tag."
      elif root[i].text is not None:
        if root[i].tag == "statefile":
          statef = root[i].text.strip()
          statef = common.validateFileid(statef)
          if statef is None: statef = ""
        elif root[i].tag == "state":
          state = root[i].text.strip()
        elif root[i].tag == "locfile":
          cityf = root[i].text.strip()
          cityf = common.validateFileid(cityf)
          if cityf is None: cityf = ""
        elif root[i].tag == "loc":
          city = root[i].text.strip()
        elif root[i].tag == "name":
          placename = root[i].text.strip()
        dinf[root[i].tag] = [root[i].text.strip(), False]
        if config['debug'] > 2: print str(i) + " ",
  if len(statef) > 0 and len(cityf) > 0: pushLoc(statef,state,cityf,city,fileid,placename)
  return (dinf,drel)