File: upload.py

package info (click to toggle)
datapm 0.10-1.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 472 kB
  • ctags: 590
  • sloc: python: 2,760; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,136 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os

from dpm.cli.base import Command
import dpm.upload


class UploadCommand(Command):
    name = 'upload'
    summary = 'Upload a resource or package to a storage system'
    min_args = 2
    max_args = 2
    usage = \
'''%prog {path} {upload-spec}

Upload a file or package at {path} to {upload-spec}. Upload-spec are of the form::

    {upload-dest-id}://BUCKET/LABEL

For example::

    ## default ckan upload
    ckan://BUCKET/LABEL

    ## an s3 upload destination
    my-s3://BUCKET/LABEL

    ## local pairtree
    my-pairtree://BUCKET/LABEL

    ## google storage
    my-google-storage://BUCKET/LABEL

Upload destinations are specified in your dpm config file and are of the form::

    [upload:dest-id]
    ofs.backend = {s3|google|archive.org|...}
    ## see OFS documentation for a given backend
    {config-option} = {config-value}
    '''

    def run(self, options, args):
        path = args[0]
        # is path a package or not?
        upload_spec = args[1]
        uploader = dpm.upload.Uploader(verbose=True)
        print 'Uploading, please be patient ...'
        uploader.upload(open(path), upload_spec)