2 """deterfile.py - determine file type"""
\r
8 _file_cmd = "file %s"
\r
12 determine given file's type.
\r
13 This function returns strings.
\r
15 @param path: filepath you want to determine
\r
19 if not os.path.isfile(path):
\r
20 return ("file not exist.",)
\r
22 cmd = _file_cmd % path
\r
23 escaped_path = path.replace("\\", "\\\\");
\r
24 stdout = os.popen(cmd, "r")
\r
27 if re.search(r"^%s:" % escaped_path, line):
\r
28 line = re.sub(r"^%s:\s*" % escaped_path, "", line)
\r
29 tpl = line.strip().split(",")
\r
30 results.extend([x.strip() for x in tpl])
\r