Skip to content

Commit

Permalink
Fully functional package installer.
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolDude53 committed Sep 25, 2017
1 parent d23af90 commit 811bcad
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# Snatch-CLI
Using Click for clean CLI.
Built on Python 2.7.10 using click and requests

### Setup
```
pip install click
pip install requests
```

### Usage
```
python snatch.py
```
To see all line args run:
```
python snatch.py --help
```
37 changes: 34 additions & 3 deletions snatch.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
import click
import requests
import io
import zipfile


@click.command()
@click.option('--name', prompt="Please enter your name/package", help='The person to greet.')
def pull(name):
click.echo('Hello %s!' % name)
@click.option('--name', prompt='Please enter your name/package', help='Your package name in format name/package.')
@click.option('--path', help='Absolute path to install packages. Defaults to current dir.')
def pull(name, path):
url = "http://snatch.joycestick.com/api/" + name
download(url, path)


# installs unzipped package to the given directory
def download(url, path):
returned_request = requests.get(url)

# make sure web response is good before continuing
if returned_request.status_code != 200:
print("Bad response for url: %s" % url)
return

byte_file = io.BytesIO(returned_request.content)
if not zipfile.is_zipfile(byte_file):
print("Returned file is not a zip at url: %s" % url)
return

# create a zipfile object
zip_file = zipfile.ZipFile(byte_file)

# extract zip
if path is not None:
zip_file.extractall(path)
else:
zip_file.extractall()

print("Success!")


if __name__ == '__main__':
Expand Down

0 comments on commit 811bcad

Please sign in to comment.