Exemplo n.º 1
0
class Reader(object):
    re_number = re.compile(r"\d+")

    def __init__(self, glos):
        self._glos = glos
        self._tabFileNames = []
        self._tabFileReader = None

    def open(self, dirname):
        self._dirname = dirname
        dicFiles = []
        orderFileNames = []
        for fname in os.listdir(dirname):
            if not fname.startswith("directory"):
                continue
            try:
                num = self.re_number.findall(fname)[-1]
            except IndexError:
                pass
            else:
                orderFileNames.append((num, fname))
        orderFileNames.sort(
            key=lambda x: x[0],
            reverse=True,
        )
        self._tabFileNames = [x[1] for x in orderFileNames]
        self.nextTabFile()

    def __len__(self):  # FIXME
        raise NotImplementedError

    def __iter__(self):
        return self

    def __next__(self):
        for _ in range(10):
            try:
                return next(self._tabFileReader)
            except StopIteration:
                self._tabFileReader.close()
                self.nextTabFile()

    def nextTabFile(self):
        try:
            tabFileName = self._tabFileNames.pop()
        except IndexError:
            raise StopIteration
        self._tabFileReader = TabfileReader(self._glos, hasInfo=False)
        self._tabFileReader.open(join(self._dirname, tabFileName))

    def close(self):
        if self._tabFileReader:
            try:
                self._tabFileReader.close()
            except:
                pass
        self._tabFileReader = None
        self._tabFileNames = []
Exemplo n.º 2
0
class Reader(object):
	def __init__(self, glos):
		self._glos = glos
		self._tabFileNames = []
		self._tabFileReader = None

	def open(self, dirname):
		self._dirname = dirname
		dicFiles = []
		orderFileNames = []
		for fname in os.listdir(dirname):
			if not fname.startswith("directory"):
				continue
			try:
				num = re.findall("\d+", fname)[-1]
			except IndexError:
				pass
			else:
				orderFileNames.append((num, fname))
		orderFileNames.sort(
			key=lambda x: x[0],
			reverse=True,
		)
		self._tabFileNames = [x[1] for x in orderFileNames]
		self.nextTabFile()

	def __len__(self):  # FIXME
		raise NotImplementedError

	def __iter__(self):
		return self

	def __next__(self):
		for _ in range(10):
			try:
				return next(self._tabFileReader)
			except StopIteration:
				self._tabFileReader.close()
				self.nextTabFile()

	def nextTabFile(self):
		try:
			tabFileName = self._tabFileNames.pop()
		except IndexError:
			raise StopIteration
		self._tabFileReader = TabfileReader(self._glos, hasInfo=False)
		self._tabFileReader.open(join(self._dirname, tabFileName))

	def close(self):
		if self._tabFileReader:
			try:
				self._tabFileReader.close()
			except:
				pass
		self._tabFileReader = None
		self._tabFileNames = []
Exemplo n.º 3
0
 def nextTabFile(self):
     try:
         tabFileName = self._tabFileNames.pop()
     except IndexError:
         raise StopIteration
     self._tabFileReader = TabfileReader(self._glos, hasInfo=False)
     self._tabFileReader.open(join(self._dirname, tabFileName))
Exemplo n.º 4
0
	def nextTabFile(self):
		try:
			tabFileName = self._tabFileNames.pop()
		except IndexError:
			raise StopIteration
		self._tabFileReader = TabfileReader(self._glos, hasInfo=False)
		self._tabFileReader.open(join(self._dirname, tabFileName))