Code Search for Developers
 
 
  

config.py from Thousand Parsec at Krugle


Show config.py syntax highlighted

"""\
This file contains function useful for storing and retriving config.
"""

import sys
import os
import os.path

try:
	import cPickle as pickle
except ImportError:
	import pickle

def configpath():
	"""\
	Figures out where to save the preferences.
	"""
	dirs = [("APPDATA", "Thousand Parsec"), ("HOME", ".tp"), (".", "var")]
	for base, extra in dirs:
		if base in os.environ:
			base = os.environ[base]
		elif base != ".":
			continue
			
		rc = os.path.join(base, extra)
		if not os.path.exists(rc):
			os.mkdir(rc)
		return rc

def load_data(file):
	"""\
	Loads preference data from a file.
	"""
	try:
		f = open(os.path.join(configpath(), file), "r")
		data = pickle.load(f)
	except IOError:
		return None
	return data
	
def save_data(file, data):
	"""\
	Saves preference data to a file.
	"""
	f = open(os.path.join(configpath(), file), "w")
	pickle.dump(data, f)




See more files for this project here

Thousand Parsec

Thousand Parsec is a framework for turn based 4 X\'s game (eXplore, eXpand, eXploit, eXterminate). Designed for long games, supporting massive universes and has an easily expanded tech tree.

Project homepage: http://sourceforge.net/projects/thousandparsec
Programming language(s): C++,Python
License: other

  pyscheme/
    t/
      factorial.scm
      generators.scm
      hello.scm
      pairs1.scm
      pocket.scm
      quine.scm
      stack.scm
      test1.scm
    LICENSE
    __init__.py
    all_tests.py
    analyzer.py
    builtins.py
    environment.py
    error.py
    evaluator.py
    expander.py
    expressions.py
    pair.py
    parser.py
    pogo.py
    prompt.py
    scheme.py
    symbol.py
    test_analyzer.py
    test_scheme.py
  ChangeDict.py
  Log.py
  __init__.py
  cache.py
  config.py
  media.py
  parser.py
  strptime.py
  threads.py
  version.py