Functions
srt_ntbash_cache_t Namespace Reference

Functions

def main ()
 MAIN FUNCTION. More...
 

Function Documentation

def srt_ntbash_cache_t.main ( )

MAIN FUNCTION.

1D plots hits vs w //

Definition at line 12 of file srt_ntbash_cache_t.py.

12 def main():
13 
14  test_db = srt_ntbash_cache.srt_cache ("")
15  test_db.cache ("dork", "mama")
16  print "Simple Cache Test: " + test_db.lookup("dork")
17 
18  cache_db_file = "c:\\temp\\junk.python_db"
19 
20  def simple_write(cache_db_file):
21  cache_db = srt_ntbash_cache.srt_cache (cache_db_file)
22  cache_db.cache ("test", "you dude")
23  print "Got back for key test: " + cache_db.lookup ("test")
24  test = ["hi", "there", "me"]
25  cache_db.cache ("list", test)
26 
27  cache_db.write_db()
28 
29  simple_write(cache_db_file)
30 
31  cache_db = srt_ntbash_cache.srt_cache (cache_db_file)
32  print "Got back after read file " + cache_db.lookup ("test")
33 
34  test_list = cache_db.lookup("list")
35  print "From list I found:"
36  for item in test_list:
37  print " " + item
38 
39  print "Has key test (should): ", cache_db.has_key("test")
40  print "Has key bogus (shouldn't): ", cache_db.has_key("bogus")
41 
42  print "Going to test out srt_ntbash_cache stuff now"
43  print " Creating a temp directory called junk in local directory"
44 
45  if not os.path.exists ("junk_dir"):
46  os.system ("bash --norc -c \"mkdir junk_dir\"")
47  if os.path.exists("junk_dir/link1"):
48  os.unlink ("junk_dir/link1")
49  if os.path.exists("junk_dir/link2"):
50  os.unlink ("junk_dir/link2")
51  if os.path.exists("junk_dir/link3"):
52  os.unlink ("junk_dir/link3")
53 
54  os.system ("bash --norc -c \"ln -s srt_ntbash_cache_t.py junk_dir/link1\"")
55  os.system ("bash --norc -c \"ln -s srt_ntbash_cache_t.py junk_dir/link2\"")
56 
57  translated_path = srt_ntbashutil.translate_path ("junk_dir")
58  print " Links found (should be 2 extra):"
59  nt_path_list = srt_ntbashutil.resolve_bash_aliases (translated_path)
60  for path in nt_path_list:
61  print " Resolved to: " + path
62 
63  m_old_time = os.stat("junk_dir")[ST_MTIME]
64  os.system ("bash --norc -c \"ln -s srt_ntbash_cache_t.py junk_dir/link3\"")
65  m_new_time = os.stat("junk_dir")[ST_MTIME]
66 
67  print "Old Mod Time: ", m_old_time, " and new mod time: ", m_new_time
68  print " Difference: ", m_new_time - m_old_time
69 
70  print " Links found after third link created (should be 3 extra):"
71  nt_path_list = srt_ntbashutil.resolve_bash_aliases (translated_path)
72  for path in nt_path_list:
73  print " Resolved to: " + path
74 
76  sym_cache.cache ("hi", "bogus!")
77  sym_cache.write_db()
78 
79  print "Open cache file for reading, and try to write cache. No errors should occur..."
80  temp_file = open (cache_db_file, "r")
81  cache_db.write_db()
82  temp_file.close()
83 
84  print "Open cache file for writing, and try to read the cache. No errors should occur,"
85  print " and the db should be empty"
86  temp_file = open (cache_db_file, "w")
87  cache_db.load_db()
88  print " test lookup is ->" + cache_db.lookup ("test") + "<-..."
89  temp_file.close()
90