Exemplo n.º 1
0
def ReadFile(doc, readProperties):
    first = 0
    list = {}
    counters = {}

    # LOG.LOG_FILTER = LOG.LOG_FILTER | LOG.LOG_DEBUG

    if (isOleFile(getInventorFile())):
        ole = OleFileIO(getInventorFile())
        setFileVersion(ole)
        elements = ole.listdir(streams=True, storages=False)

        folder = getInventorFile()[0:-4]
        if not os.path.exists(folder):
            os.makedirs(folder)

        counter = 1
        list = []
        for fname in elements:
            if (len(fname) == 1):
                list.append(fname)
            else:
                #Ensure that RSe* files will be parsed first
                if (fname[-1].startswith('RSe')):
                    #ensure RSeDb is the very first "file" to be parsed
                    list.insert(first, fname)
                    if (fname[-1] == 'RSeDb'):
                        first += 1
                elif (not fname[-1].startswith('B')):
                    list.append(fname)

        for fname in list:
            ReadElement(ole, fname, doc, counter, readProperties)
            counter += 1
        ole.close()

        now = datetime.datetime.now()
        if (len(doc.Comment) > 0):
            doc.Comment += '\n'
        doc.Comment = '# %s: read from %s' % (
            now.strftime('%Y-%m-%d %H:%M:%S'), getInventorFile())

        logMessage("Dumped data to folder: '%s'" % (getInventorFile()[0:-4]),
                   LOG.LOG_INFO)

        return True
    logError("Error - '%s' is not a valid Autodesk Inventor file." % (infile))
    return False
def oleMetaData(file_path, save=True):
    now = dt.now()
    file_name = getFileName(file_path)
    metadata = "Time: %d/%d/%d %d : %d : %d. Found the following metadata for file %s:\n\n" % (
        now.year, now.month, now.day, now.hour, now.minute, now.second,
        file_name[:-4])
    try:
        ole = OleFileIO(file_path)
        meta = ole.get_metadata()
        ole.close()
        author = meta.author.decode("latin-1")
        creation_time = meta.create_time.ctime()
        last_author = meta.last_saved_by.decode("latin-1")
        last_edit_time = meta.last_saved_time.ctime()
        last_printed = meta.last_printed.ctime()
        revisions = meta.revision_number.decode("latin-1")
        company = meta.company.decode("latin-1")
        creating_app = meta.creating_application.decode("latin-1")

        metadata += "Original Author: %s\nCreation Time: %s\nLast Author: %s\n" % (author, creation_time, last_author) \
                    + "Last Modification Time: %s\nLast Printed at: %s\Total Revisions: %s\n" % (last_edit_time, last_printed, revisions) \
                    + "Created with: %s\nCompany: %s" % (creating_app, company)

        try:
            print(metadata)
        except UnicodeEncodeError:
            print(
                "Console encoding can't decode the result. Enter chcp 65001 in the console and rerun the script."
            )

        if save:
            file_name = getFileName(file_path)
            tgt = file_name + ".txt"

            saveResult(tgt, metadata)

    except OSError as e1:
        print("File not supported: %s" % e1)
    except FileNotFoundError:
        print("Specified file could not be found")
Exemplo n.º 3
0
class OleFileFS(FS):

    _meta = dict(read_only=True, thread_safe=False, network=False, unicode_paths=True, case_insensitive_paths=True)

    def __init__(self, path):
        try:
            self._olefile = OleFileIO(path, path_encoding=None)
        except IOError as e:
            raise CreateFailedError(str(e), details=e)

    #
    # Essential methods
    #

    def open(
        self, path, mode="r", buffering=-1, encoding=None, errors=None, newline=None, line_buffering=False, **kwargs
    ):
        for unsupported in "w", "a", "+":
            if unsupported in mode:
                raise OperationFailedError("open", path=path)
        segments = path_to_segments_normalized(path)
        return self._olefile.openstream(segments)

    def isdir(self, path):
        segments = path_to_segments_normalized(path)
        sty = self._olefile.get_type(segments)
        return sty in (STGTY_STORAGE, STGTY_ROOT)

    def isfile(self, path):
        segments = path_to_segments_normalized(path)
        sty = self._olefile.get_type(segments)
        return sty is STGTY_STREAM

    def listdir(self, path="./", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
        items = self.ilistdir(
            path=path, wildcard=wildcard, full=full, absolute=absolute, dirs_only=dirs_only, files_only=files_only
        )
        return list(items)

    def getinfo(self, path):
        segments = path_to_segments_normalized(path)
        size = self._olefile.get_size(segments)
        ctime = self._olefile.getctime(segments)
        mtime = self._olefile.getmtime(segments)
        return {"size": size, "created_time": ctime, "modified_time": mtime}

    #
    # Non-essential methods
    #

    def close(self):
        self._olefile.close()
        FS.close(self)

    def ilistdir(self, path="./", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False):
        if dirs_only:
            olefile_listdir_args = dict(streams=False, storages=True)
        elif files_only:
            olefile_listdir_args = dict(streams=True, storages=False)
        else:
            olefile_listdir_args = dict()
        given_node = path_to_segments_normalized(path)
        leafs = self._olefile.listdir(**olefile_listdir_args)
        leafs = map(tuple, leafs)
        nodes = find_children(given_node, leafs)
        for segments in nodes:
            stgty = self._olefile.get_type(segments)
            if dirs_only and stgty not in (STGTY_STORAGE, STGTY_ROOT):
                continue
            elif files_only and stgty is not STGTY_STREAM:
                continue
            if absolute:
                yield absolute_path_from_segments(segments)
            elif full:
                yield full_path_from_segments(segments)
            else:
                yield segments[-1]