Skip to content

Commit 08cb7f8

Browse files
committed
set up docker
1 parent c85fcfc commit 08cb7f8

7 files changed

Lines changed: 106 additions & 39 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,6 @@ ENV/
9999

100100
# mypy
101101
.mypy_cache/
102+
103+
# test output
104+
/output

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# syntax=docker/dockerfile:1
2+
FROM python:3.10-alpine
3+
WORKDIR /app
4+
# ENV FLASK_APP=app.py I think therse are env variables that the contianer will have access too
5+
# ENV FLASK_RUN_HOST=0.0.0.0
6+
COPY requirements.txt requirements.txt
7+
RUN pip install -r requirements.txt
8+
COPY . .
9+
# CMD ["python3", "runcmd.py", "--help"]

README.md

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ The goal of this forked version of `remotezip` is to use the unzip library for p
66

77
This module provides a way to access single members of a zip file archive without downloading the full content from a remote web server. For this library to work, the web server hosting the archive needs to support the [range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests) header.
88

9+
## Command line tool
10+
11+
This version of the project allows you to run the command line tool, `sremotezip.py` with `docker-compose` for development. The flags and arguments can be passed during the build process using the host's environment variables.
12+
13+
```
14+
FLAG=-l URL=url FILENAME=filename docker-compose up
15+
```
16+
17+
The container will create and write the extracted files in a directory called `output`.
18+
919
## Usage
1020

1121
### Initialization
@@ -90,41 +100,6 @@ with RemoteZip(url, auth=auth, headers=headers) as z:
90100
zip.extract('somefile.txt')
91101
```
92102

93-
## Command line tool
94-
95-
A simple command line tool is included in this distribution.
96-
97-
```
98-
usage: remotezip [-h] [-l] [-d DIR] url [filename [filename ...]]
99-
100-
Unzip remote files
101-
102-
positional arguments:
103-
url Url of the zip archive
104-
filename File to extract
105-
106-
optional arguments:
107-
-h, --help show this help message and exit
108-
-l, --list List files in the archive
109-
-d DIR, --dir DIR Extract directory, default current directory
110-
```
111-
112-
#### Example
113-
114-
```
115-
$ remotezip -l "http://thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.zip"
116-
Length DateTime Name
117-
-------- ------------------- ------------------------
118-
2962 2008-07-30 13:58:46 Readme.txt
119-
24740 2008-07-30 12:16:46 TM_WORLD_BORDERS-0.3.dbf
120-
145 2008-03-12 13:11:54 TM_WORLD_BORDERS-0.3.prj
121-
6478464 2008-07-30 12:16:46 TM_WORLD_BORDERS-0.3.shp
122-
2068 2008-07-30 12:16:46 TM_WORLD_BORDERS-0.3.shx
123-
124-
$ remotezip "http://thematicmapping.org/downloads/TM_WORLD_BORDERS-0.3.zip" Readme.txt
125-
Extracting Readme.txt...
126-
```
127-
128103
## How it works
129104

130105
This module uses the `zipfile.ZipFile` class under the hood to decode the zip file format. The `ZipFile` class is initialized with a file like object that will perform transparently the remote queries.

Readme.txt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
TM_WORLD_BORDERS-0.1.ZIP
2+
3+
Provided by Bjorn Sandvik, thematicmapping.org
4+
5+
Use this dataset with care, as several of the borders are disputed.
6+
7+
The original shapefile (world_borders.zip, 3.2 MB) was downloaded from the Mapping Hacks website:
8+
http://www.mappinghacks.com/data/
9+
10+
The dataset was derived by Schuyler Erle from public domain sources.
11+
Sean Gilles did some clean up and made some enhancements.
12+
13+
14+
COLUMN TYPE DESCRIPTION
15+
16+
Shape Polygon Country/area border as polygon(s)
17+
FIPS String(2) FIPS 10-4 Country Code
18+
ISO2 String(2) ISO 3166-1 Alpha-2 Country Code
19+
ISO3 String(3) ISO 3166-1 Alpha-3 Country Code
20+
UN Short Integer(3) ISO 3166-1 Numeric-3 Country Code
21+
NAME String(50) Name of country/area
22+
AREA Long Integer(7) Land area, FAO Statistics (2002)
23+
POP2005 Double(10,0) Population, World Polulation Prospects (2005)
24+
REGION Short Integer(3) Macro geographical (continental region), UN Statistics
25+
SUBREGION Short Integer(3) Geogrpahical sub-region, UN Statistics
26+
LON FLOAT (7,3) Longitude
27+
LAT FLOAT (6,3) Latitude
28+
29+
30+
CHANGELOG VERSION 0.3 - 30 July 2008
31+
32+
- Corrected spelling mistake (United Arab Emirates)
33+
- Corrected population number for Japan
34+
- Adjusted long/lat values for India, Italy and United Kingdom
35+
36+
37+
CHANGELOG VERSION 0.2 - 1 April 2008
38+
39+
- Made new ZIP archieves. No change in dataset.
40+
41+
42+
CHANGELOG VERSION 0.1 - 13 March 2008
43+
44+
- Polygons representing each country were merged into one feature
45+
- �land Islands was extracted from Finland
46+
- Hong Kong was extracted from China
47+
- Holy See (Vatican City) was added
48+
- Gaza Strip and West Bank was merged into "Occupied Palestinean Territory"
49+
- Saint-Barthelemy was extracted from Netherlands Antilles
50+
- Saint-Martin (Frensh part) was extracted from Guadeloupe
51+
- Svalbard and Jan Mayen was merged into "Svalbard and Jan Mayen Islands"
52+
- Timor-Leste was extracted from Indonesia
53+
- Juan De Nova Island was merged with "French Southern & Antarctic Land"
54+
- Baker Island, Howland Island, Jarvis Island, Johnston Atoll, Midway Islands
55+
and Wake Island was merged into "United States Minor Outlying Islands"
56+
- Glorioso Islands, Parcel Islands, Spartly Islands was removed
57+
(almost uninhabited and missing ISO-3611-1 code)
58+
59+
- Added ISO-3166-1 codes (alpha-2, alpha-3, numeric-3). Source:
60+
https://www.cia.gov/library/publications/the-world-factbook/appendix/appendix-d.html
61+
http://unstats.un.org/unsd/methods/m49/m49alpha.htm
62+
http://www.fysh.org/~katie/development/geography.txt
63+
- AREA column has been replaced with data from UNdata:
64+
Land area, 1000 hectares, 2002, FAO Statistics
65+
- POPULATION column (POP2005) has been replaced with data from UNdata:
66+
Population, 2005, Medium variant, World Population Prospects: The 2006 Revision
67+
- Added region and sub-region codes from UN Statistics Division. Source:
68+
http://unstats.un.org/unsd/methods/m49/m49regin.htm
69+
- Added LAT, LONG values for each country
70+

docker-compose.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: "3.9"
2+
services:
3+
remotezipser:
4+
build: .
5+
command: python3 sremotezip.py ${FLAG} ${URL} ${FILENAME}
6+
volumes:
7+
- .:/app
8+

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tabulate
2+
requests

bin/remotezip renamed to sremotezip.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def list_files(url, filenames):
1818

1919

2020
def extract_files(url, filenames, path):
21-
with RemoteZip(url) as zip:
21+
with RemoteZip(url, headers={'User-Agent': 'remotezip'}) as zip:
2222
if len(filenames) == 0:
2323
filenames = zip.namelist()
2424
for fname in filenames:
@@ -30,14 +30,14 @@ def extract_files(url, filenames, path):
3030
import argparse
3131
import os
3232

33-
parser = argparse.ArgumentParser(description="Unzip remote files")
33+
parser = argparse.ArgumentParser(description="Safe Unzip remote files")
3434
parser.add_argument('url', help='Url of the zip archive')
3535
parser.add_argument('filename', nargs='*', help='File to extract')
3636
parser.add_argument('-l', '--list', action='store_true', default=False, help='List files in the archive')
37-
parser.add_argument('-d', '--dir', default=os.getcwd(), help='Extract directory, default current directory')
37+
parser.add_argument('-d', '--dir', default=f'{os.getcwd()}/output', help='Extract directory, default current directory')
3838

3939
args = parser.parse_args()
4040
if args.list:
4141
list_files(args.url, args.filename)
4242
else:
43-
extract_files(args.url, args.filename, args.dir)
43+
extract_files(args.url, args.filename, args.dir)

0 commit comments

Comments
 (0)