Skip to content

Commit cf610ff

Browse files
authored
Merge pull request #13 from TaskarCenterAtUW/feature-directory-issue-fix
Fixes the issue with folder inside extracted zip
2 parents f5473df + f155d86 commit cf610ff

File tree

5 files changed

+36
-23
lines changed

5 files changed

+36
-23
lines changed

CHANGELOG.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
# Change log
22

3-
### 0.0.1
4-
- Initial version of python_osw_validation package.
5-
6-
### 0.0.2
7-
- Updated package Unit test cases.
8-
- Updated README file
9-
10-
### 0.0.3
11-
- Added schema file to package
12-
13-
### 0.0.4
14-
- Points are not required for a valid OSW dataset
15-
16-
### 0.0.5
17-
- Support for multi-level geojson file
18-
- Now handles the following two folder structures when unzipped abc.zip
19-
1. abc\{nodes, edges, points}.geojson
20-
2. {nodes, edges, points}.geojson
3+
### 0.2.1
4+
- Updated zipfile_handler
5+
- Fixed "No .geojson files found in the specified directory or its subdirectories." issue
216

227
### 0.2.0
238
- Updated schema file to OSW 0.2
@@ -26,4 +11,23 @@
2611
- Added additional validation steps based on the OSW network properties
2712
- Add external extensions to ExtractedDataValidator
2813
- Validate external extensions against basic Open Geospatial Consortium (OGC) standards
29-
- Aggregate schema errors and data integrity errors separately before returning errors to user
14+
- Aggregate schema errors and data integrity errors separately before returning errors to user
15+
16+
### 0.0.5
17+
- Support for multi-level geojson file
18+
- Now handles the following two folder structures when unzipped abc.zip
19+
1. abc\{nodes, edges, points}.geojson
20+
2. {nodes, edges, points}.geojson
21+
22+
### 0.0.4
23+
- Points are not required for a valid OSW dataset
24+
25+
### 0.0.3
26+
- Added schema file to package
27+
28+
### 0.0.2
29+
- Updated package Unit test cases.
30+
- Updated README file
31+
32+
### 0.0.1
33+
- Initial version of python_osw_validation package.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.2.0'
1+
__version__ = '0.2.1'

src/python_osw_validation/zipfile_handler.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,20 @@ def extract_zip(self) -> Optional[str]:
5050
if len(zip_ref.namelist()) == 0:
5151
raise Exception('ZIP file is empty')
5252

53-
first_item = zip_ref.namelist()[0]
54-
55-
return f'{self.extracted_dir}/{first_item}'
53+
internal_folder_name = self.find_internal_folder(zip_ref)
54+
return os.path.join(self.extracted_dir,internal_folder_name)
5655
except Exception as e:
5756
self.error = f'Error extracting ZIP file: {e}'
57+
58+
# finds the first folder available in the extracted folder.
59+
# returns empty if there are no folders inside
60+
def find_internal_folder(self, zip_ref: zipfile.ZipFile)-> str:
61+
for filename in zip_ref.namelist():
62+
path = os.path.join(self.extracted_dir,filename)
63+
if(os.path.isdir(path)):
64+
return filename
65+
return ''
66+
5867

5968
def remove_extracted_files(self) -> None:
6069
if self.extracted_dir and os.path.exists(self.extracted_dir):

tests/assets/Archive.zip

268 KB
Binary file not shown.

tests/assets/Archive_2.zip

271 KB
Binary file not shown.

0 commit comments

Comments
 (0)