Esempio n. 1
0
    def __init__(self, fn, ftype=None, write=False):
        self.name = fn
        self.dirname = os.path.dirname(fn)
        self.basename = os.path.basename(fn)
        self.ext = get_extension(fn)
        self.ftype = None  # the file's associated class
        self.mtime = None
        self.ctime = None
        self.atime = None

        from mmgen.seed import SeedSource
        from mmgen.tx import MMGenTX
        if ftype:
            if type(ftype) == type:
                if issubclass(ftype, SeedSource) or issubclass(ftype, MMGenTX):
                    self.ftype = ftype
                # elif: # other MMGen file types
                else:
                    die(
                        3, "'{}': not a recognized file type for SeedSource".
                        format(ftype))
            else:
                die(3, "'{}': not a class".format(ftype))
        else:
            # TODO: other file types
            self.ftype = SeedSource.ext_to_type(self.ext)
            if not self.ftype:
                die(
                    3,
                    "'{}': not a recognized extension for SeedSource".format(
                        self.ext))

        import stat
        if stat.S_ISBLK(os.stat(fn).st_mode):
            mode = (os.O_RDONLY, os.O_RDWR)[bool(write)]
            if g.platform == 'win': mode |= os.O_BINARY
            try:
                fd = os.open(fn, mode)
            except OSError as e:
                if e.errno == 13:
                    die(2, "'{}': permission denied".format(fn))


#				if e.errno != 17: raise
            else:
                self.size = os.lseek(fd, 0, os.SEEK_END)
                os.close(fd)
        else:
            self.size = os.stat(fn).st_size
            self.mtime = os.stat(fn).st_mtime
            self.ctime = os.stat(fn).st_ctime
            self.atime = os.stat(fn).st_atime
Esempio n. 2
0
	def __init__(self,fn,ftype=None,write=False):
		self.name     = fn
		self.dirname  = os.path.dirname(fn)
		self.basename = os.path.basename(fn)
		self.ext      = get_extension(fn)
		self.ftype    = None # the file's associated class
		self.mtime    = None
		self.ctime    = None
		self.atime    = None

		from mmgen.seed import SeedSource
		from mmgen.tx import MMGenTX
		if ftype:
			if type(ftype) == type:
				if issubclass(ftype,SeedSource) or issubclass(ftype,MMGenTX):
					self.ftype = ftype
				# elif: # other MMGen file types
				else:
					die(3,"'{}': not a recognized file type for SeedSource".format(ftype))
			else:
				die(3,"'{}': not a class".format(ftype))
		else:
			# TODO: other file types
			self.ftype = SeedSource.ext_to_type(self.ext)
			if not self.ftype:
				die(3,"'{}': not a recognized extension for SeedSource".format(self.ext))


		import stat
		if stat.S_ISBLK(os.stat(fn).st_mode):
			mode = (os.O_RDONLY,os.O_RDWR)[bool(write)]
			if g.platform == 'win': mode |= os.O_BINARY
			try:
				fd = os.open(fn, mode)
			except OSError as e:
				if e.errno == 13:
					die(2,"'{}': permission denied".format(fn))
#				if e.errno != 17: raise
			else:
				self.size = os.lseek(fd, 0, os.SEEK_END)
				os.close(fd)
		else:
			self.size = os.stat(fn).st_size
			self.mtime = os.stat(fn).st_mtime
			self.ctime = os.stat(fn).st_ctime
			self.atime = os.stat(fn).st_atime