Skip to content

Commit 59487f8

Browse files
jhkennedygtsystem
authored andcommitted
convert scripts to console_scripts entry_points
1 parent da62e11 commit 59487f8

3 files changed

Lines changed: 48 additions & 47 deletions

File tree

bin/remotezip

Lines changed: 0 additions & 45 deletions
This file was deleted.

remotezip.py

100644100755
Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
#!/usr/bin/env python
12
import io
23
import zipfile
4+
from datetime import datetime
35
from itertools import tee
46

57
import requests
8+
from tabulate import tabulate
69

710
__all__ = ['RemoteIOError', 'RemoteZip']
811

@@ -252,4 +255,45 @@ def _get_position_to_size(self):
252255
return {a: b-a for a, b in pairwise(ilist)}
253256

254257

255-
258+
def list_files(url, support_suffix_range, filenames):
259+
with RemoteZip(url, headers={'User-Agent': 'remotezip'}, support_suffix_range=support_suffix_range) as zip:
260+
if len(filenames) == 0:
261+
filenames = zip.namelist()
262+
data = [('Length', 'DateTime', 'Name')]
263+
for fname in filenames:
264+
zinfo = zip.getinfo(fname)
265+
dt = datetime(*zinfo.date_time)
266+
data.append((zinfo.file_size, dt.strftime('%Y-%m-%d %H:%M:%S'), zinfo.filename))
267+
print(tabulate(data, headers='firstrow'))
268+
269+
270+
def extract_files(url, support_suffix_range, filenames, path):
271+
with RemoteZip(url, support_suffix_range=support_suffix_range) as zip:
272+
if len(filenames) == 0:
273+
filenames = zip.namelist()
274+
for fname in filenames:
275+
print('Extracting {0}...'.format(fname))
276+
zip.extract(fname, path=path)
277+
278+
279+
def main():
280+
import argparse
281+
import os
282+
283+
parser = argparse.ArgumentParser(description="Unzip remote files")
284+
parser.add_argument('url', help='Url of the zip archive')
285+
parser.add_argument('filename', nargs='*', help='File to extract')
286+
parser.add_argument('-l', '--list', action='store_true', help='List files in the archive')
287+
parser.add_argument('-d', '--dir', default=os.getcwd(), help='Extract directory, default current directory')
288+
parser.add_argument('--disable-suffix-range-support', action='store_true', help='Use when remote server does not support suffix range (negative offset)')
289+
290+
args = parser.parse_args()
291+
support_suffix_range = not args.disable_suffix_range_support
292+
if args.list:
293+
list_files(args.url, support_suffix_range, args.filename)
294+
else:
295+
extract_files(args.url, support_suffix_range, args.filename, args.dir)
296+
297+
298+
if __name__ == "__main__":
299+
main()

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
long_description_content_type="text/markdown",
1717
install_requires=["requests", "tabulate"],
1818
tests_require=['requests_mock'],
19-
scripts=['bin/remotezip'],
19+
entry_points={
20+
'console_scripts': ['remotezip = remotezip:main']
21+
},
2022
test_suite='test_remotezip',
2123
classifiers=[
2224
'Intended Audience :: Developers',

0 commit comments

Comments
 (0)