|
1 | 1 | """bgst is a command line client to BigStash.co |
2 | 2 |
|
3 | 3 | Usage: |
4 | | - bgst put [-t TITLE] [--silent] [--dont-wait] FILES... |
| 4 | + bgst put [--ignore-file IGNORE] [-t TITLE] [--silent] [--dont-wait] FILES... |
5 | 5 | bgst settings [--user=USERNAME] [--password=PASSWORD] |
6 | 6 | bgst settings --reset |
7 | 7 | bgst list [--limit=NUMBER] |
|
22 | 22 | --reset Remove saved configuration, revoke |
23 | 23 | authentication token. |
24 | 24 | --limit=NUMBER Show up to NUMBER results. [default: 10] |
| 25 | + --ignore-file=IGNORE Path to a .gitignore like file. |
25 | 26 | """ |
26 | 27 |
|
27 | 28 | from __future__ import print_function |
|
33 | 34 | import logging |
34 | 35 | import posixpath |
35 | 36 | import threading |
| 37 | +import inflect |
36 | 38 | from wrapt import decorator |
37 | 39 | from BigStash import __version__ |
| 40 | +from BigStash.filename import setup_user_ignore |
38 | 41 | from BigStash.auth import get_api_credentials |
39 | 42 | from BigStash.conf import BigStashAPISettings |
40 | 43 | from BigStash import BigStashAPI, BigStashError |
|
45 | 48 |
|
46 | 49 | log = logging.getLogger('bigstash.upload') |
47 | 50 |
|
| 51 | +peng = inflect.engine() |
| 52 | + |
48 | 53 |
|
49 | 54 | def smart_str(s): |
50 | 55 | if isinstance(s, six.text_type): |
@@ -195,16 +200,30 @@ def bgst_put(args, settings): |
195 | 200 | opt_dont_wait = False if not args['--dont-wait'] else True |
196 | 201 | upload = None |
197 | 202 | filepaths = map(smart_str, args['FILES']) |
198 | | - manifest, errors = Manifest.from_paths(paths=filepaths, title=title) |
| 203 | + ignorefile = args['--ignore-file'] |
| 204 | + if ignorefile: |
| 205 | + setup_user_ignore(ignorefile) |
| 206 | + manifest, errors, ignored = Manifest.from_paths( |
| 207 | + paths=filepaths, title=title) |
| 208 | + ignored_msg = '' |
| 209 | + if ignored: |
| 210 | + ignored_msg = "({} {} ignored)".format( |
| 211 | + len(ignored), peng.plural("file", len(ignored))) |
| 212 | + if len(manifest) == 0: |
| 213 | + print(" ".join(["No files found", ignored_msg])) |
| 214 | + sys.exit(5) |
199 | 215 | if errors: |
200 | 216 | errtext = [": ".join(e) for e in errors] |
201 | 217 | print("\n".join(["There were errors:"] + errtext)) |
202 | 218 | sys.exit(4) |
203 | 219 | k, s = get_api_credentials(settings) |
204 | 220 | bigstash = BigStashAPI(key=k, secret=s, settings=settings) |
205 | 221 | upload = bigstash.CreateUpload(manifest=manifest) |
| 222 | + filecount = len(manifest) |
206 | 223 | if not opt_silent: |
207 | | - print("Uploading {}..".format(upload.archive.key)) |
| 224 | + msg = "Uploading {} {} as archive {}..".format( |
| 225 | + filecount, peng.plural("file", filecount), upload.archive.key) |
| 226 | + print(" ".join([msg, ignored_msg])) |
208 | 227 | s3 = boto3.resource( |
209 | 228 | 's3', region_name=upload.s3.region, |
210 | 229 | aws_access_key_id=upload.s3.token_access_key, |
|
0 commit comments