Python stat 模块,ST_CTIME 实例源码

我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用stat.ST_CTIME

项目:nOBEX    作者:nccgroup    | 项目源码 | 文件源码
def gen_folder_listing(path):
    l = os.listdir(path)
    s = '<?xml version="1.0"?>\n<folder-listing>\n'

    for i in l:
        objpath = os.path.join(path, i)
        if os.path.isdir(objpath):
            args = (i, unix2bluetime(os.stat(objpath)[stat.ST_CTIME]))
            s += '  <folder name="%s" created="%s" />' % args
        else:
            args = (i, unix2bluetime(os.stat(objpath)[stat.ST_CTIME]),
                    os.stat(objpath)[stat.ST_SIZE])
            s += '  <file name="%s" created="%s" size="%s" />' % args

    s += "</folder-listing>\n"

    if sys.version_info.major < 3:
        s = unicode(s)

    return s
项目:pyEPR    作者:zlatko-minev    | 项目源码 | 文件源码
def get_latest_h5(self):
        dirpath = self.data_dir

        entries1 = (os.path.join(dirpath, fn) for fn in os.listdir(dirpath))     # get all entries in the directory w/ stats
        entries2 = ((os.stat(path), path) for path in entries1)
        entries3 = ((stat[ST_CTIME], path)                                       # leave only regular files, insert creation date
                   for stat, path in entries2 if S_ISREG(stat[ST_MODE]) and path[-4:]=='hdf5')
        #NOTE: on Windows `ST_CTIME` is a creation date but on Unix it could be something else
        #NOTE: use `ST_MTIME` to sort by a modification date

        paths_sorted = []
        for cdate, path in sorted(entries3):
            paths_sorted.append(path)
            #print time.ctime(cdate), os.path.basename(path)

        if len(paths_sorted) > 0:
            self.latest_h5_path = paths_sorted[-1]
            if self.verbose:
                print('This simulations has been analyzed, latest data in ' + self.latest_h5_path)

        else:
            self.latest_h5_path = None
            if self.verbose:
                print('This simulation has never been analyzed')
项目:wxpythoncookbookcode    作者:driscollis    | 项目源码 | 文件源码
def updateDisplay(self, file_list):
        """"""
        for path in file_list:
            file_stats = os.stat(path)
            creation_time = time.strftime(
                "%m/%d/%Y %I:%M %p",
                time.localtime(file_stats[stat.ST_CTIME]))
            modified_time = time.strftime(
                "%m/%d/%Y %I:%M %p",
                time.localtime(file_stats[stat.ST_MTIME]))
            file_size = file_stats[stat.ST_SIZE]
            if file_size > 1024:
                file_size = file_size / 1024.0
                file_size = "%.2f KB" % file_size

            self.file_list.append(FileInfo(path,
                                           creation_time,
                                           modified_time,
                                           file_size))

        self.olv.SetObjects(self.file_list)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def getctime(self):
        st = self.statinfo
        if not st:
            self.restat()
            st = self.statinfo
        return st[ST_CTIME]
项目:locasploit    作者:lightfaith    | 项目源码 | 文件源码
def get_file_info(system, path, verbose=False):
    fullpath = get_fullpath(system, path)
    if fullpath == IO_ERROR:
        return IO_ERROR

    result = {}    
    if system.startswith('/'): # local or sub
        if can_read(system, path):
            # TODO platform-specific
            stats = os.stat(fullpath)
            stm = stats.st_mode
            result['type'] = get_file_type_char(stat.S_IFMT(stm))
            result['permissions'] = '%o' % (stat.S_IMODE(stm))
            result['UID'] = stats[stat.ST_UID]
            result['GID'] = stats[stat.ST_GID]
            result['ATIME'] = stats[stat.ST_ATIME]
            result['MTIME'] = stats[stat.ST_MTIME]
            result['CTIME'] = stats[stat.ST_CTIME] # actually mtime on UNIX, TODO
        else:
            if verbose:
                log.info('File \'%s\' is not accessible.' % (fullpath))
            result['type'] = None
            result['permissions'] =  None
            result['UID'] = None
            result['GID'] = None
            result['ATIME'] = None
            result['MTIME'] = None
            result['CTIME'] = None
        return result

    else: # SSH/FTP/TFTP/HTTP
        # TODO NOT IMPLEMENTED
        return IO_ERROR
项目:yt    作者:yt-project    | 项目源码 | 文件源码
def _set_owls_eagle(self):

        self.dimensionality = 3
        self.refine_by = 2
        self.parameters["HydroMethod"] = "sph"
        self.unique_identifier = \
            int(os.stat(self.parameter_filename)[stat.ST_CTIME])

        self._unit_base = self._get_uvals()
        self._unit_base['cmcm'] = 1.0 / self._unit_base["UnitLength_in_cm"]

        self.current_redshift = self.parameters["Redshift"]
        self.omega_lambda = self.parameters["OmegaLambda"]
        self.omega_matter = self.parameters["Omega0"]
        self.hubble_constant = self.parameters["HubbleParam"]

        if self.domain_left_edge is None:
            self.domain_left_edge = np.zeros(3, "float64")
            self.domain_right_edge = np.ones(
                3, "float64") * self.parameters["BoxSize"]

        nz = 1 << self.over_refine_factor
        self.domain_dimensions = np.ones(3, "int32") * nz

        self.cosmological_simulation = 1
        self.periodicity = (True, True, True)

        prefix = os.path.abspath(
            os.path.join(os.path.dirname(self.parameter_filename),
                         os.path.basename(self.parameter_filename).split(".", 1)[0]))

        suffix = self.parameter_filename.rsplit(".", 1)[-1]
        if self.parameters["NumFiles"] > 1:
            self.filename_template = "%s.%%(num)i.%s" % (prefix, suffix)
        else:
            self.filename_template = self.parameter_filename

        self.file_count = self.parameters["NumFilesPerSnapshot"]
项目:yt    作者:yt-project    | 项目源码 | 文件源码
def _parse_parameter_file(self):
        # Read all parameters.
        simu = self._read_log_simu()
        param = self._read_parameter()

        # Set up general information.
        self.filename_template = self.parameter_filename
        self.file_count = 1
        self.parameters.update(param)
        self.particle_types = ('halos')
        self.particle_types_raw = ('halos')
        self.unique_identifier = \
            int(os.stat(self.parameter_filename)[stat.ST_CTIME])

        # Set up geometrical information.
        self.refine_by = 2
        self.dimensionality = 3
        nz = 1 << self.over_refine_factor
        self.domain_dimensions = np.ones(self.dimensionality, "int32") * nz
        self.domain_left_edge = np.array([0.0, 0.0, 0.0])
        # Note that boxsize is in Mpc but particle positions are in kpc.
        self.domain_right_edge = np.array([simu['boxsize']] * 3) * 1000
        self.periodicity = (True, True, True)

        # Set up cosmological information.
        self.cosmological_simulation = 1
        self.current_redshift = param['z']
        self.omega_lambda = simu['lambda0']
        self.omega_matter = simu['omega0']
        cosmo = Cosmology(self.hubble_constant,
                          self.omega_matter, self.omega_lambda)
        self.current_time = cosmo.hubble_time(param['z']).in_units('s')
项目:yt    作者:yt-project    | 项目源码 | 文件源码
def _parse_parameter_file(self):
        with open(self.parameter_filename, "rb") as f:
            hvals = fpu.read_cattrs(f, header_dt)
            hvals.pop("unused")
        self.dimensionality = 3
        self.refine_by = 2
        self.unique_identifier = \
            int(os.stat(self.parameter_filename)[stat.ST_CTIME])
        prefix = ".".join(self.parameter_filename.rsplit(".", 2)[:-2])
        self.filename_template = "%s.%%(num)s%s" % (prefix, self._suffix)
        self.file_count = len(glob.glob(prefix + ".*" + self._suffix))

        # Now we can set up things we already know.
        self.cosmological_simulation = 1
        self.current_redshift = (1.0 / hvals['scale']) - 1.0
        self.hubble_constant = hvals['h0']
        self.omega_lambda = hvals['Ol']
        self.omega_matter = hvals['Om']
        cosmo = Cosmology(self.hubble_constant,
                          self.omega_matter, self.omega_lambda)
        self.current_time = cosmo.hubble_time(self.current_redshift).in_units("s")
        self.periodicity = (True, True, True)
        self.particle_types = ("halos")
        self.particle_types_raw = ("halos")

        self.domain_left_edge = np.array([0.0,0.0,0.0])
        self.domain_right_edge = np.array([hvals['box_size']] * 3)

        nz = 1 << self.over_refine_factor
        self.domain_dimensions = np.ones(3, "int32") * nz
        self.parameters.update(hvals)
项目:yt    作者:yt-project    | 项目源码 | 文件源码
def _parse_parameter_file(self):
        """
        Parses the parameter file and establishes the various
        dictionaries.
        """
        self._parse_header_file()
        # Let's read the file
        hfn = os.path.join(self.output_dir, 'Header')
        self.unique_identifier = int(os.stat(hfn)[ST_CTIME])
        # the 'inputs' file is now optional
        self._parse_cparams()
        self._parse_fparams()
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def getctime(self):
        st = self.statinfo
        if not st:
            self.restat()
            st = self.statinfo
        return st[ST_CTIME]
项目:scripts    作者:mbfraga    | 项目源码 | 文件源码
def add_file(self, filepath, misc_prop=None):
        """Manually add files to the files list, and get all its file
        properties.

        Keyword arguments:
        filepath -- path to file
        misc_prop -- add a miscellaneous property
        """
        if not os.path.isfile(filepath):
            print(filepath + " is not a file.")
            return
        fp_rel = filepath[self.__path_len:]

        try:
            stat = os.stat(filepath)
        except:
            return
        file_props = {}
        file_props['size'] = stat[ST_SIZE]
        file_props['adate'] = stat[ST_ATIME]
        file_props['mdate'] = stat[ST_MTIME]
        file_props['cdate'] = stat[ST_CTIME]
        file_props['name'] = fp_rel
        file_props['fullpath'] = filepath
        file_props['misc'] = misc_prop

        self.__files.append(file_props)
        self.__filecount += 1
项目:firmware-extract    作者:dell    | 项目源码 | 文件源码
def fileDetails(file):
    name = os.path.basename(file)
    f_stat = os.stat(file)
    size = f_stat[stat.ST_SIZE]
    ctime = f_stat[stat.ST_CTIME]
    md5sum = ""
    return (name, size, ctime, md5sum)
项目:qn    作者:mbfraga    | 项目源码 | 文件源码
def add_file(self, filepath, misc_prop=None):
        """Add a file to the file repo.

        Keyword arguments:
        filepath -- path to file
        misc_props -- string to add as a 'misc' property to file
        """
        if not path.isfile(filepath):
            print(filepath + " is not a file.")
            exit(1)

        fp_rel = filepath[self.__path_len:]

        try:
            filestat = stat(filepath)
        except:
            return

        file_props = {}
        file_props['size'] = filestat[ST_SIZE]
        file_props['adate'] = filestat[ST_ATIME]
        file_props['mdate'] = filestat[ST_MTIME]
        file_props['cdate'] = filestat[ST_CTIME]
        file_props['name'] = fp_rel
        file_props['fullpath'] = filepath
        file_props['misc'] = misc_prop

        self.__file_list.append(file_props)
        self.__filecount += 1
项目:Automation-Framework-for-devices    作者:tok-gogogo    | 项目源码 | 文件源码
def path_copy(Oldpath,Newpath):
    os.chdir(Oldpath)
    fromdir = Oldpath
    todir = Newpath
    for root,dirs,files in os.walk(fromdir):
        for filename in files:
            path=os.path.join(root,filename)
            shutil.copyfile(path,'%s/%s'%(todir,filename))
            #stat1=os.stat(os.path.join(fromdir,filename))
            #os.utime(os.path.join(todir,filename),(stat1[ST_CTIME], stat1[ST_MTIME]))
    return True
项目:PYSHA    作者:shafaypro    | 项目源码 | 文件源码
def file_info (self, file_name=""):
        if file_name != "":
            file_stats = os.stat(file_name)
            # create a dictionary to hold file info
            file_info = {
                'fname': file_name,
                'fsize': file_stats[stat.ST_SIZE],
                'f_lm': time.strftime("%d/%m/%Y %I:%M:%S %p", time.localtime(file_stats[stat.ST_MTIME])),
                'f_la': time.strftime("%d/%m/%Y %I:%M:%S %p", time.localtime(file_stats[stat.ST_ATIME])),
                'f_ct': time.strftime("%d/%m/%Y %I:%M:%S %p", time.localtime(file_stats[stat.ST_CTIME]))
            }
            print
            print("file name = %(fname)s" % file_info)
            print("file size = %(fsize)s bytes" % file_info)
            print("last modified = %(f_lm)s" % file_info)
            print("last accessed = %(f_la)s" % file_info)
            print("creation time = %(f_ct)s" % file_info)
            print
            if stat.S_ISDIR(file_stats[stat.ST_MODE]):
                print("This a directory")
            else:
                print("This is not a directory")
                print
                print("A closer look at the os.stat(%s) tuple:" % file_name)
                print(file_stats)
                print
                print("The above tuple has the following sequence:")
                print("""st_mode (protection bits), st_ino (inode number),
              st_dev (device), st_nlink (number of hard links),
              st_uid (user ID of owner), st_gid (group ID of owner),
              st_size (file size, bytes), st_atime (last access time, seconds since epoch),
              st_mtime (last modification time), st_ctime (time of creation, Windows)""")
        else:
            print("No File Detected , hence Exiting !")
项目:yt    作者:yt-project    | 项目源码 | 文件源码
def _parse_parameter_file(self):
        self.refine_by = 2
        with h5py.File(self.parameter_filename, "r") as f:
            for key in f.attrs.keys():
                v = parse_h5_attr(f, key)
                if key == "con_args":
                    v = v.astype("str")
                self.parameters[key] = v
            self._with_parameter_file_open(f)

        # if saved, restore unit registry from the json string
        if "unit_registry_json" in self.parameters:
            self.unit_registry = UnitRegistry.from_json(
                self.parameters["unit_registry_json"])
            # reset self.arr and self.quan to use new unit_registry
            self._arr = None
            self._quan = None
            for dim in ["length", "mass", "pressure",
                        "temperature", "time", "velocity"]:
                cu = "code_" + dim
                if cu not in self.unit_registry:
                    self.unit_registry.add(
                        cu, 1.0, getattr(dimensions, dim))
            if "code_magnetic" not in self.unit_registry:
                self.unit_registry.add("code_magnetic", 1.0,
                                       dimensions.magnetic_field)

        # if saved, set unit system
        if "unit_system_name" in self.parameters:
            unit_system = self.parameters["unit_system_name"]
            del self.parameters["unit_system_name"]
        else:
            unit_system = "cgs"
        # reset unit system since we may have a new unit registry
        self._assign_unit_system(unit_system)

        # assign units to parameters that have associated unit string
        del_pars = []
        for par in self.parameters:
            ustr = "%s_units" % par
            if ustr in self.parameters:
                if isinstance(self.parameters[par], np.ndarray):
                    to_u = self.arr
                else:
                    to_u = self.quan
                self.parameters[par] = to_u(
                    self.parameters[par], self.parameters[ustr])
                del_pars.append(ustr)
        for par in del_pars:
            del self.parameters[par]

        for attr in self._con_attrs:
            setattr(self, attr, self.parameters.get(attr))
        self.unique_identifier = \
          int(os.stat(self.parameter_filename)[stat.ST_CTIME])
项目:yt    作者:yt-project    | 项目源码 | 文件源码
def _parse_parameter_file(self):
        """
        Parses the parameter file and establishes the various
        dictionaries.
        """

        f = open(self.parameter_filename, "r")
        # get dimension from first block name
        b0, fn0 = f.readline().strip().split()
        level0, left0, right0 = get_block_info(b0, min_dim=0)
        root_blocks = get_root_blocks(b0)
        f.close()
        self.dimensionality = left0.size
        self.periodicity = \
          ensure_tuple(np.ones(self.dimensionality, dtype=bool))

        fh = h5py.File(os.path.join(self.directory, fn0), "r")
        self.domain_left_edge  = fh.attrs["lower"]
        self.domain_right_edge = fh.attrs["upper"]

        # all blocks are the same size
        ablock = fh[list(fh.keys())[0]]
        self.current_time = ablock.attrs["time"][0]
        gsi = ablock.attrs["enzo_GridStartIndex"]
        gei = ablock.attrs["enzo_GridEndIndex"]
        self.ghost_zones = gsi[0]
        self.root_block_dimensions = root_blocks
        self.active_grid_dimensions = gei - gsi + 1
        self.grid_dimensions = ablock.attrs["enzo_GridDimension"]
        self.domain_dimensions = root_blocks * self.active_grid_dimensions
        fh.close()

        self.periodicity += (False, ) * (3 - self.dimensionality)

        # WIP hard-coded for now
        self.refine_by = 2
        self.cosmological_simulation = 0
        self.gamma = 5. / 3.
        self.particle_types = ()
        self.particle_types_raw = self.particle_types
        self.unique_identifier = \
          str(int(os.stat(self.parameter_filename)[stat.ST_CTIME]))
项目:yt    作者:yt-project    | 项目源码 | 文件源码
def _parse_parameter_file(self):
        if self.parameter_filename.startswith("http"):
            sdf_class = HTTPSDFRead
        else:
            sdf_class = SDFRead
        self.sdf_container = sdf_class(self.parameter_filename,
                                 header=self.sdf_header)

        # Reference
        self.parameters = self.sdf_container.parameters
        self.dimensionality = 3
        self.refine_by = 2
        try:
            self.unique_identifier = \
                int(os.stat(self.parameter_filename)[stat.ST_CTIME])
        except:
            self.unique_identifier = time.time()

        if self.domain_left_edge is None or self.domain_right_edge is None:
            R0 = self.parameters['R0']
            if 'offset_center' in self.parameters and self.parameters['offset_center']:
                self.domain_left_edge = np.array([0, 0, 0], dtype=np.float64)
                self.domain_right_edge = np.array([
                    2.0 * self.parameters.get("R%s" % ax, R0) for ax in 'xyz'],
                    dtype=np.float64)
            else:
                self.domain_left_edge = np.array([
                    -self.parameters.get("R%s" % ax, R0) for ax in 'xyz'],
                    dtype=np.float64)
                self.domain_right_edge = np.array([
                    +self.parameters.get("R%s" % ax, R0) for ax in 'xyz'],
                    dtype=np.float64)
            self.domain_left_edge *= self.parameters.get("a", 1.0)
            self.domain_right_edge *= self.parameters.get("a", 1.0)
        nz = 1 << self.over_refine_factor
        self.domain_dimensions = np.ones(3, "int32") * nz
        if "do_periodic" in self.parameters and self.parameters["do_periodic"]:
            self.periodicity = (True, True, True)
        else:
            self.periodicity = (False, False, False)

        self.cosmological_simulation = 1

        self.current_redshift = self.parameters.get("redshift", 0.0)
        self.omega_lambda = self.parameters["Omega0_lambda"]
        self.omega_matter = self.parameters["Omega0_m"]
        if "Omega0_fld" in self.parameters:
            self.omega_lambda += self.parameters["Omega0_fld"]
        if "Omega0_r" in self.parameters:
            # not correct, but most codes can't handle Omega0_r
            self.omega_matter += self.parameters["Omega0_r"]
        self.hubble_constant = self.parameters["h_100"]
        self.current_time = units_2HOT_v2_time * self.parameters.get("tpos", 0.0)
        mylog.info("Calculating time to be %0.3e seconds", self.current_time)
        self.filename_template = self.parameter_filename
        self.file_count = 1
项目:yt    作者:yt-project    | 项目源码 | 文件源码
def _parse_parameter_file(self):

        self._determine_structure()
        self._determine_axes()

        if self.parameter_filename.startswith("InMemory"):
            self.unique_identifier = time.time()
        else:
            self.unique_identifier = \
                int(os.stat(self.parameter_filename)[stat.ST_CTIME])

        # Determine dimensionality

        self.dimensionality = self.naxis
        self.geometry = "cartesian"

        # Sometimes a FITS file has a 4D datacube, in which case
        # we take the 4th axis and assume it consists of different fields.
        if self.dimensionality == 4: 
            self.dimensionality = 3

        self._determine_wcs()

        self.domain_dimensions = np.array(self.dims)[:self.dimensionality]
        if self.dimensionality == 2:
            self.domain_dimensions = np.append(self.domain_dimensions,
                                               [int(1)])

        domain_left_edge = np.array([0.5]*3)
        domain_right_edge = np.array([float(dim)+0.5 for dim in self.domain_dimensions])

        if self.dimensionality == 2:
            domain_left_edge[-1] = 0.5
            domain_right_edge[-1] = 1.5

        self.domain_left_edge = domain_left_edge
        self.domain_right_edge = domain_right_edge

        # Get the simulation time
        try:
            self.current_time = self.parameters["time"]
        except:
            mylog.warning("Cannot find time")
            self.current_time = 0.0
            pass

        # For now we'll ignore these
        self.periodicity = (False,)*3
        self.current_redshift = self.omega_lambda = self.omega_matter = \
            self.hubble_constant = self.cosmological_simulation = 0.0

        self._determine_nprocs()

        # Now we can set up some of our parameters for convenience.
        for k, v in self.primary_header.items():
            self.parameters[k] = v
        # Remove potential default keys
        self.parameters.pop('', None)
项目:yt    作者:yt-project    | 项目源码 | 文件源码
def _parse_parameter_file(self):
        handle = h5py.File(self.parameter_filename, mode="r")
        hvals = {}
        hvals.update((str(k), v) for k, v in handle["/Header"].attrs.items())
        hvals["NumFiles"] = hvals["NumFilesPerSnapshot"]
        hvals["Massarr"] = hvals["MassTable"]

        self.dimensionality = 3
        self.refine_by = 2
        self.unique_identifier = \
            int(os.stat(self.parameter_filename)[stat.ST_CTIME])

        # Set standard values
        self.current_time = self.quan(hvals["Time_GYR"], "Gyr")
        self.domain_left_edge = np.zeros(3, "float64")
        self.domain_right_edge = np.ones(3, "float64") * hvals["BoxSize"]
        nz = 1 << self.over_refine_factor
        self.domain_dimensions = np.ones(3, "int32") * nz
        self.cosmological_simulation = 1
        self.periodicity = (True, True, True)
        self.current_redshift = hvals["Redshift"]
        self.omega_lambda = hvals["OmegaLambda"]
        self.omega_matter = hvals["Omega0"]
        self.hubble_constant = hvals["HubbleParam"]
        self.parameters = hvals
        prefix = os.path.abspath(
            os.path.join(os.path.dirname(self.parameter_filename), 
                         os.path.basename(self.parameter_filename).split(".", 1)[0]))

        suffix = self.parameter_filename.rsplit(".", 1)[-1]
        self.filename_template = "%s.%%(num)i.%s" % (prefix, suffix)
        self.file_count = len(glob.glob(prefix + "*" + self._suffix))
        if self.file_count == 0:
            raise YTException(message="No data files found.", ds=self)
        self.particle_types = ("FOF", "SUBFIND")
        self.particle_types_raw = ("FOF", "SUBFIND")

        # To avoid having to open files twice
        self._unit_base = {}
        self._unit_base.update(
            (str(k), v) for k, v in handle["/Units"].attrs.items())
        handle.close()
项目:yt    作者:yt-project    | 项目源码 | 文件源码
def _parse_parameter_file(self):
        self.unique_identifier = \
            int(os.stat(self.parameter_filename)[stat.ST_CTIME])

        # code-specific parameters
        for t in self._handle['Info']:
            info_category = self._handle['Info'][t]
            for v in info_category.dtype.names: self.parameters[v] = info_category[v]

        # shortcut for self.parameters
        parameters = self.parameters

        # reset 'Model' to be more readable
        if parameters['Model'] == 1:
            parameters['Model'] = 'Hydro'
        elif parameters['Model'] == 2:
            parameters['Model'] = 'MHD'
        elif parameters['Model'] == 3:
            parameters['Model'] = 'ELBDM'
        else:
            parameters['Model'] = 'Unknown'

        # simulation time and domain
        self.current_time      = parameters['Time'][0]
        self.dimensionality    = 3  # always 3D
        self.domain_left_edge  = np.array([0.,0.,0.], dtype='float64')
        self.domain_right_edge = parameters['BoxSize'].astype('float64')
        self.domain_dimensions = parameters['NX0'].astype('int64')

        # periodicity
        periodic         = parameters['Opt__BC_Flu'][0] == 0
        self.periodicity = (periodic,periodic,periodic)

        # cosmological parameters
        if parameters['Comoving']:
            self.cosmological_simulation = 1
            self.current_redshift        = 1.0/self.current_time - 1.0
            self.omega_matter            = parameters['OmegaM0']
            self.omega_lambda            = 1.0 - self.omega_matter
            # default to 0.7 for old data format
            self.hubble_constant         = parameters.get('Hubble0', 0.7)
        else:
            self.cosmological_simulation = 0
            self.current_redshift        = 0.0
            self.omega_matter            = 0.0
            self.omega_lambda            = 0.0
            self.hubble_constant         = 0.0

        # make aliases to some frequently used variables
        if parameters['Model'] == 'Hydro' or parameters['Model'] == 'MHD':
            self.gamma = parameters["Gamma"]
            # default to 0.6 for old data format
            self.mu    = parameters.get('MolecularWeight', 0.6)

        # old data format (version < 2210) does not contain any information of code units
        self.parameters.setdefault('Opt__Unit', 0)
项目:rdiff-backup    作者:sol1    | 项目源码 | 文件源码
def make_file_dict_python(filename):
    """Create the data dictionary using a Python call to os.lstat

    We do this on Windows since Python's implementation is much better
    than the one in cmodule.c    Eventually, we will move to using
    this on all platforms since CPUs have gotten much faster than
    they were when it was necessary to write cmodule.c
    """
    try:
        statblock = os.lstat(filename)
    except os.error:
        return {'type':None}
    data = {}
    mode = statblock[stat.ST_MODE]

    if stat.S_ISREG(mode): type_ = 'reg'
    elif stat.S_ISDIR(mode): type_ = 'dir'
    elif stat.S_ISCHR(mode):
        type_ = 'dev'
        s = statblock.st_rdev
        data['devnums'] = ('c',) + (s >> 8, s & 0xff)
    elif stat.S_ISBLK(mode):
        type_ = 'dev'
        s = statblock.st_rdev
        data['devnums'] = ('b',) + (s >> 8, s & 0xff)
    elif stat.S_ISFIFO(mode): type_ = 'fifo'
    elif stat.S_ISLNK(mode):
        type_ = 'sym'
        data['linkname'] = os.readlink(filename)
    elif stat.S_ISSOCK(mode): type_ = 'sock'
    else: raise C.UnknownFileError(filename)
    data['type'] = type_
    data['size'] = statblock[stat.ST_SIZE]
    data['perms'] = stat.S_IMODE(mode)
    data['uid'] = statblock[stat.ST_UID]
    data['gid'] = statblock[stat.ST_GID]
    data['inode'] = statblock[stat.ST_INO]
    data['devloc'] = statblock[stat.ST_DEV]
    data['nlink'] = statblock[stat.ST_NLINK]

    if os.name == 'nt':
        global type
        if type(filename) == unicode:
            attribs = win32file.GetFileAttributesW(filename)
        else:
            attribs = win32file.GetFileAttributes(filename)
        if attribs & winnt.FILE_ATTRIBUTE_REPARSE_POINT:
            data['type'] = 'sym'
            data['linkname'] = None

    if not (type_ == 'sym' or type_ == 'dev'):
        # mtimes on symlinks and dev files don't work consistently
        data['mtime'] = long(statblock[stat.ST_MTIME])
        data['atime'] = long(statblock[stat.ST_ATIME])
        data['ctime'] = long(statblock[stat.ST_CTIME])
    return data
项目:scripts    作者:mbfraga    | 项目源码 | 文件源码
def scan_files(self, recursive=True):
        """Scans the directory for files and populates the files list and 
        linebs. It is not a particularly fast implementation.

        Keyword arguments:
        recursive -- define whether scan should be recursive or not 
                     (default True)
        """
        self.__filecount = 0
        self.__files = []
        if recursive:
            for root, dirs, files in os.walk(self.__path, topdown=True):
                for name in files:
                    fp = os.path.join(root, name)
                    fp_rel = fp[self.__path_len:]

                    if (fp_rel[0] == '.'):
                        continue
                    try:
                        stat = os.stat(fp)
                    except:
                        continue

                    file_props = {}
                    file_props['size'] = stat[ST_SIZE]
                    file_props['adate'] = stat[ST_ATIME]
                    file_props['mdate'] = stat[ST_MTIME]
                    file_props['cdate'] = stat[ST_CTIME]
                    file_props['name'] = fp_rel
                    file_props['fullpath'] = fp
                    file_props['misc'] = None

                    self.__files.append(file_props)
                    self.__filecount += 1
        else:
            for f in os.scandir(self.__path):

                fp_rel = f.name
                fp = os.path.join(self.__path, fp_rel)
                if (fp_rel[0] == '.'):
                    continue
                if f.is_dir():
                    continue
                #try:
                #    stat = os.stat(fp)
                #except:
                #    continue

                file_props = {}
                file_props['size'] = f.stat()[ST_SIZE]
                file_props['adate'] = f.stat()[ST_ATIME]
                file_props['mdate'] = f.stat()[ST_MTIME]
                file_props['cdate'] = f.stat()[ST_CTIME]
                file_props['name'] = fp_rel
                file_props['fullpath'] = fp
                file_props['misc'] = None

                self.__files.append(file_props)
                self.__filecount += 1
项目:qn    作者:mbfraga    | 项目源码 | 文件源码
def scan_files(self):
        """Scans the directory for files and populates the file list and
        linebs.
        """
        self.__filecount = 0
        self.__pfilecount = 0
        pintot = len(self.__pinned_filenames)
        if pintot != 0:
            temp_pinned_filenames = list(self.__pinned_filenames)
        else:
            temp_pinned_filenames = False

        for root, dirs, files in walk(self.__path, topdown=True):
            for name in files:
                fp = path.join(root, name)
                fp_rel = fp[self.__path_len:]

                if (fp_rel[0] == '.'):
                    continue
                try:
                    filestat = stat(fp)
                except:
                    continue

                file_props = {}
                file_props['size'] = filestat[ST_SIZE]
                file_props['adate'] = filestat[ST_ATIME]
                file_props['mdate'] = filestat[ST_MTIME]
                file_props['cdate'] = filestat[ST_CTIME]
                file_props['name'] = fp_rel
                file_props['fullpath'] = fp
                file_props['misc'] = None
                file_props['tags'] = None

                if temp_pinned_filenames:
                    if name in temp_pinned_filenames:
                        temp_pinned_filenames.remove(name)
                        self.__pfile_list.append(file_props)
                        self.__pfilecount += 1
                        continue

                    self.__file_list.append(file_props)
                    self.__filecount += 1
                    continue

                # if name in self.pinned_filenames:
                #     self.__pfile_list.append(file_props)
                #     self.__pfilecount += 1
                # else:
                #     self.__file_list.append(file_props)
                #     self.__filecount += 1
                self.__file_list.append(file_props)
                self.__filecount += 1