Python os.path.getctime() Examples

The following are code examples for showing how to use os.path.getctime(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: NeoAnalysis   Author: neoanalysis   File: elphyio.py    (license) View Source Project 6 votes vote down vote up
def open(self):
        """
        Setup the internal structure.
        
        NB : Call this function before 
        extracting data from a file.
        """
        if self.file :
            self.file.close()
        try :
            self.file = open(self.path, 'rb')
        except Exception as e:
            raise Exception("python couldn't open file %s : %s" % (self.path, e))
        self.file_size = path.getsize(self.file.name)
        self.creation_date = datetime.fromtimestamp(path.getctime(self.file.name))
        self.modification_date = datetime.fromtimestamp(path.getmtime(self.file.name))
        self.nomenclature = self.get_nomenclature()
        self.factory = self.get_factory()
        self.layout = self.create_layout() 
Example 2
Project: NeoAnalysis   Author: neoanalysis   File: elphyio.py    (license) View Source Project 6 votes vote down vote up
def open(self):
        """
        Setup the internal structure.
        
        NB : Call this function before 
        extracting data from a file.
        """
        if self.file :
            self.file.close()
        try :
            self.file = open(self.path, 'rb')
        except Exception as e:
            raise Exception("python couldn't open file %s : %s" % (self.path, e))
        self.file_size = path.getsize(self.file.name)
        self.creation_date = datetime.fromtimestamp(path.getctime(self.file.name))
        self.modification_date = datetime.fromtimestamp(path.getmtime(self.file.name))
        self.nomenclature = self.get_nomenclature()
        self.factory = self.get_factory()
        self.layout = self.create_layout() 
Example 3
Project: vismooc-data-server   Author: HKUST-VISLab   File: meta_info.py    (license) View Source Project 6 votes vote down vote up
def compute_one_metadb_item(cls, filename):
        '''Process one file to get one metadb document
        '''
        md5 = hashlib.md5()
        try:
            with open(filename, 'r', encoding='utf-8') as file:
                md5.update(file.read().encode('utf-8'))
        except BaseException:
            return
        md5 = md5.hexdigest()
        item = {
            DBc.FIELD_METADBFILES_FILEPATH: filename,
            DBc.FIELD_METADBFILES_CREATEDAT: getctime(filename),
            DBc.FIELD_METADBFILES_LAST_MODIFIED: getmtime(filename),
            DBc.FIELD_METADBFILES_PROCESSED: False,
            DBc.FIELD_METADBFILES_ETAG: md5,
            DBc.FIELD_METADBFILES_TYPE: 'eventData' if 'eventData' in filename else 'databaseData',
        }
        return item 
Example 4
Project: Panorama   Author: AlmCo   File: HTML.py    (license) View Source Project 5 votes vote down vote up
def writeFile(self, string):
		name = '<font color="silver" size="3">'+string.rsplit("\\",1)[0]+'</font> '+string.rsplit("\\",1)[1]
		link = string.replace("\\","\\\\").replace("%20"," ")
		self.Files.write('<tr><td><a href="javascript:openURL(\'{}\')">\
			{}</a></td><td>{}</td></tr>\n'.format(link, name, timestamp2date(getctime(string),1))) 
Example 5
Project: Panorama   Author: AlmCo   File: HTML.py    (license) View Source Project 5 votes vote down vote up
def writeIMG(self, string):
		name = string.rsplit("\\",1)[1]
		link = string.replace("\\","\\\\").replace("%20"," ")
		self.Files.write('<tr><td><img src="{}" width="40" height="25"></td><td><a href="javascript:openURL(\'{}\')">\
			{}</a></td><td>{}</td></tr>\n'.format(link, link, name, timestamp2date(getctime(string),1))) 
Example 6
Project: snowflake-connector-python   Author: snowflakedb   File: ocsp_pyopenssl.py    (license) View Source Project 5 votes vote down vote up
def file_timestamp(filename):
    if platform.system() == 'Windows':
        ts = int(path.getctime(filename))
    else:
        stat = os.stat(filename)
        if hasattr(stat, 'st_birthtime'):  # odx
            ts = int(stat.st_birthtime)
        else:
            ts = int(stat.st_mtime)  # linux
    return ts 
Example 7
Project: process-watcher   Author: arlowhite   File: __init__.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, pid):

        self.pid = pid
        self.running = True
        self.ended_datetime = None

        # Mapping of each status_fields to value from the status file.
        # Initialize fields to zero in case info() is called.
        self.status = {field: 0 for field in self.status_fields}

        self.path = path = P.join(PROC_DIR, str(pid))
        if not P.exists(path):
            raise NoProcessFound(pid)

        self.status_path = P.join(path, 'status')

        # Get the command that started the process
        with open(P.join(path, 'cmdline'), encoding='utf-8') as f:
            cmd = f.read()
            # args are separated by \x00 (Null byte)
            self.command = cmd.replace('\x00', ' ').strip()

            if self.command == '':
                # Some processes (such as kworker) have nothing in cmdline, read comm instead
                with open(P.join(path, 'comm')) as comm_file:
                    self.command = self.executable = comm_file.read().strip()

            else:
                # Just use 1st arg instead of reading comm
                self.executable = self.command.split()[0]

        # Get the start time (/proc/PID file creation time)
        self.created_datetime = datetime.fromtimestamp(P.getctime(path))

        self.check() 
Example 8
Project: wykop_wyzwaniepython   Author: WykopWyzwanie   File: rozwiazanie.py    (license) View Source Project 5 votes vote down vote up
def info(path):
        filesizes = CmdHandlers._lst_file_sizes(path) if isdir(path) else [getsize(path)]
        return '\n'.join('{}: {}'.format(name, value) for (name, value) in [
            ('typ', 'plik' if isfile(path) else 'katalog' if isdir(path) else 'inny'),
            ('sciezka', abspath(path)),
            ('rozmiar', '{}B'.format(sum(filesizes))),
            ('liczba_plikow', sum(isfile(f) for f in os.listdir()) if isdir(path) else None),
            ('ctime', datetime.fromtimestamp(getctime(path)).date()),
            ('mtime', datetime.fromtimestamp(getmtime(path)).date()),
        ] if value is not None) 
Example 9
Project: MishMash   Author: nicfit   File: sync.py    (license) View Source Project 4 votes vote down vote up
def handleDirectory(self, d, _):
        pout(Fg.blue("Syncing directory") + ": " + str(d))
        audio_files = list(self._file_cache)
        self._file_cache = []

        image_files = self._dir_images
        self._dir_images = []

        if not audio_files:
            return

        d_datetime = datetime.fromtimestamp(getctime(d))

        album_type = self._albumTypeHint(audio_files) or LP_TYPE

        album = None
        session = self._db_session
        for audio_file in audio_files:
            try:
                album = self._syncAudioFile(audio_file, album_type, d_datetime,
                                            session)
            except Exception as ex:
                # TODO: log and skip????
                raise

        if album:
            # Directory images.
            for img_file in image_files:
                img_type = art.matchArtFile(img_file)
                if img_type is None:
                    log.warn("Skipping unrecognized image file: %s" %
                             img_file)
                    continue

                new_img = Image.fromFile(img_file, img_type)
                if new_img:
                    new_img.description = os.path.basename(img_file)
                    syncImage(new_img, album if img_type in IMAGE_TYPES["album"]
                                             else album.artist,
                              session)
                else:
                    log.warn("Invalid image file: " + img_file)

        session.commit()
        if self.args.monitor:
            self._watchDir(d)