-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscan-files.py
70 lines (58 loc) · 2.07 KB
/
scan-files.py
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
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python
##
#
# Copyright 2018 Martin Böhmer
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
#
##
import configparser
import glob
# Open configuration
config = configparser.ConfigParser()
config.optionxform = str
config.read('tz-drawio.ini', 'utf-8')
# Read settings
settings_section = 'SETTINGS'
images_basedir = config.get(settings_section, "images.basedir")
# Index config
print('Indexing files mentoined in config file')
config_images = set()
# Loop through sections, each representing a library
for lib in config.sections():
# Skip settings section
if lib == settings_section:
continue
print('|- library: ' + lib)
# Loop through images in section
for image in config[lib]:
print(' |- image: ' + image)
config_images.add(image)
# Index pyhsical images files
print()
print('Scanning for SVG files in ' + images_basedir)
physical_images = set()
svg_files = glob.glob(images_basedir + '/**/*.svg', recursive=True)
for file in svg_files:
# Strip base dir
normalized_filename = file[len(images_basedir)+1:]
# Normlized directory slashes
normalized_filename = normalized_filename.replace('\\','/')
print('|- file: ' + normalized_filename)
physical_images.add(normalized_filename)
# Determine images in config file with no physical match
broken_references = sorted(config_images.difference(physical_images))
print()
print('Broken config references: ')
for image in broken_references:
print('|- broken: ' + image)
# Determine new images
new_images = sorted(physical_images.difference(config_images))
print()
print('New file not considered in config')
for image in new_images:
print('|- new: ' + image)