Repository navigation
Expand file tree
/
Copy pathFileMetaInfos.py
More file actions
60 lines (44 loc) · 1.51 KB
/
Copy pathFileMetaInfos.py
File metadata and controls
60 lines (44 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Analyze meta infos from the .gcode input file
import os
class FileMetaInfos:
generator = ""
generator_line = ""
generator_flavor = ""
file_name = ""
file_size = 0
modified_time = ""
longest_line = 0
line_count = 0
def _decode_comment_line(self, line):
if "Generated with Cura_SteamEngine" in line:
self.generator_line = line
self.generator = "Cura"
return
if "FLAVOR:Marlin" in line:
self.generator_flavor = "Marlin"
return
if "generated by Slic3r" in line:
self.generator_line = line
self.generator = "Slic3r"
return
if "generated by PrusaSlicer" in line:
self.generator_line = line
self.generator = "PrusaSlicer"
return
def _decode_line(self, line):
current_len = len(line)
stripped_line = line.strip()
if stripped_line.startswith(";"):
self._decode_comment_line(stripped_line)
else:
if current_len > self.longest_line and len(stripped_line) > 0:
self.longest_line = current_len
def read_meta_infos(self, file_name):
self.file_name = file_name
file1 = open(file_name, 'r', encoding='utf-8')
lines = file1.readlines()
self.file_size = os.path.getsize(file_name)
self.modified_time = os.path.getmtime(file_name)
for line in lines:
self.line_count += 1
self._decode_line(line)