2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-21 23:01:52 +00:00
troggle/parsers/survex.py
substantialnoninfringinguser b503d3d588 [svn] Initial troggle checkin
This is a development site using Django 1.0
Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8034 by julian @ 10/26/2008 9:04 PM
2009-05-13 05:13:38 +01:00

31 lines
1.1 KiB
Python

import settings
import expo.models as models
import re
import os
def readFile(filename):
for line in fileIterator(settings.SURVEX_DATA, filename):
print line
re_include_extension = re.compile(r"^\s*\*include\s+([^\s]*).svx$", re.IGNORECASE)
re_include_no_extension = re.compile(r"^\s*\*include\s+([^\s]*)$", re.IGNORECASE)
def fileIterator(directory, filename):
f = open(os.path.join(directory, filename + ".svx"), "rb")
for line in f.readlines():
include_extension = re_include_extension.match(line)
include_no_extension = re_include_no_extension.match(line)
def a(include):
link = re.split(r"/|\\", include)
print os.path.join(directory, *link[:-1]), link[-1]
return fileIterator(os.path.join(directory, *link[:-1]), link[-1])
if include_extension:
for b in a(include_extension.groups()[0]):
yield b
elif include_no_extension:
for b in a(include_no_extension.groups()[0]):
yield b
else:
yield line
readFile("all")