Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Recolic Keghart
product-uniqer
Commits
9b757288
Commit
9b757288
authored
Oct 04, 2021
by
Recolic K
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync
parent
ab8ff167
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
+68
-0
summerize-part-list/tool_search_part_user_autoopen.py
summerize-part-list/tool_search_part_user_autoopen.py
+68
-0
No files found.
summerize-part-list/tool_search_part_user_autoopen.py
0 → 100644
View file @
9b757288
#!/usr/bin/python3
# A script to deal with product sheet. (see test-*.xlsx)
# Workaround for fucking Windows NT
import
traceback
def
show_exception_and_exit
(
exc_type
,
exc_value
,
tb
):
traceback
.
print_exception
(
exc_type
,
exc_value
,
tb
)
input
(
"Press any key to exit."
)
sys
.
exit
(
-
1
)
import
sys
import
os
,
shutil
if
os
.
name
==
'nt'
:
sys
.
excepthook
=
show_exception_and_exit
# Allow import parent
import
os
,
sys
,
inspect
currentdir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
inspect
.
getfile
(
inspect
.
currentframe
())))
parentdir
=
os
.
path
.
dirname
(
currentdir
)
sys
.
path
.
insert
(
0
,
parentdir
)
################################### BEGIN #####################################
import
config
,
xlsx_conv
,
utils
def
main
():
def
contains_id
(
fname
,
_id
):
try
:
s
=
xlsx_conv
.
read_as_csv
(
fname
)
s
=
s
.
replace
(
' '
,
''
).
replace
(
','
,
''
)
return
s
.
lower
().
find
(
_id
.
lower
())
!=
-
1
except
:
# Catch PermissionError etc.
return
False
def
got_result
(
filepath
):
print
(
"DEBUG: HIT"
,
filepath
)
import
subprocess
,
os
,
platform
,
time
if
platform
.
system
()
==
'Darwin'
:
# macOS
subprocess
.
call
((
'open'
,
filepath
))
elif
platform
.
system
()
==
'Windows'
:
# Windows
os
.
startfile
(
filepath
)
else
:
# linux variants
subprocess
.
call
((
'xdg-open'
,
filepath
))
exit
(
0
)
if
len
(
sys
.
argv
)
==
1
:
raise
RuntimeError
(
'Usage: drag a file into me...'
)
target_filename
=
os
.
path
.
basename
(
sys
.
argv
[
1
])
target_id
=
utils
.
get_id_prefix_from_string
(
target_filename
)
results
=
[]
print
(
'Iterating... Please wait... (searching for'
,
target_id
)
is_xlsx
=
lambda
fname
:
fname
.
endswith
(
'.xlsm'
)
or
fname
.
endswith
(
'.xlsx'
)
or
fname
.
endswith
(
'.xls'
)
or
fname
.
endswith
(
'.XLSM'
)
or
fname
.
endswith
(
'.XLSX'
)
or
fname
.
endswith
(
'.XLS'
)
for
(
dirpath
,
dirnames
,
filenames
)
in
os
.
walk
(
config
.
library_path
):
for
fname
in
filenames
:
if
is_xlsx
(
fname
):
if
contains_id
(
dirpath
+
os
.
path
.
sep
+
fname
,
target_id
):
results
.
append
(
fname
)
got_result
(
dirpath
+
os
.
path
.
sep
+
fname
)
# if config.search_only_top_level_directory:
# break
if
config
.
working_dir
!=
""
:
os
.
chdir
(
config
.
working_dir
)
print
(
"找不到存在此引用的文件"
)
import
time
time
.
sleep
(
1000
)
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment