rl_ci_tools.py
author robin <robin@reportlab.com>
Wed, 14 Jun 2017 16:36:46 +0100
changeset 0 664ae0993bd1
child 2 e30f155ae0db
permissions -rw-r--r--
first checkin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
     1
VERSION='0.0.0'
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
     2
import os, sys, glob, time, json
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
     3
PROG=os.path.basename(sys.argv[0])
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
     4
debug=verbosity=0
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
     5
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
     6
class PyPiRequestor():
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
     7
    scheme = 'https'
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
     8
    host = os.environ.get('CITOOLS_SERVER','www.reportlab.com')
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
     9
    root = '%s://%s' % (scheme,host)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    10
    loginurl = "%s/accounts/login/" % root
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    11
    def __init__(self,debug=0):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    12
        self.debug = debug
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    13
        import requests
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    14
        self.session = requests.session()
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    15
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    16
    def login(self,u,p,nxt='/test-7491/'):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    17
        s = self.session
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    18
        resp = s.get(self.loginurl)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    19
        loginpage = resp.text
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    20
        if self.debug>1:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    21
            if self.debug>2: print('=============loginpage\n%r' % loginpage)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    22
        resp = s.post(self.loginurl,
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    23
                        data=dict(
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    24
                                csrfmiddlewaretoken=s.cookies['csrftoken'],
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    25
                                username=u,
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    26
                                password=p,
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    27
                                next=nxt,
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    28
                                ),
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    29
                        headers=dict(
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    30
                            Referer=self.loginurl,
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    31
                            ),
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    32
                        )
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    33
        text = resp.text
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    34
        status_code = resp.status_code
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    35
        if debug>2:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    36
            print('!!!!!\n%s\n!!!!!'% text)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    37
            print('%s: test-7491 csrftoken=%r' % (PROG,resp.cookies.get('csrftoken','???')))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    38
        if text!='I am alive!' or status_code!=200:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    39
            raise ValueError('%s: login at %r failed with status_code=%r' % (PROG,self.loginurl,status_code))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    40
        elif verbosity>=2:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    41
            print('%s: logged in OK' % PROG)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    42
        return status_code
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    43
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    44
    def _download(self,u,p, kind, fn, dst):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    45
        self.login(u,p)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    46
        base = '%s/pypi/%s/' % (self.root,kind)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    47
        url = base + fn + '/'
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    48
        resp = self.session.get(url,
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    49
                data=dict(csrfmiddlewaretoken=self.session.cookies['csrftoken']),
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    50
                headers = dict(Referer=self.loginurl),
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    51
                )
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    52
        status_code = resp.status_code
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    53
        b = resp.content
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    54
        if debug>2:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    55
            print('!!!!!\n%r\n!!!!!'% b)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    56
        if status_code!=200:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    57
            raise ValueError('%s: download %r failed with status_code=%r!\n%r' % (PROG,url,status_code,b))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    58
        if dst:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    59
            fn = os.path.join(dst,fn)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    60
        with open(fn,'wb') as f:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    61
            f.write(b)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    62
        if verbosity:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    63
            print('%s: %r(%d bytes) downloaded from %r.' % (PROG, fn, len(b),base))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    64
        return resp.status_code
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    65
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    66
    def download(self,u,p,kind, fn, dst):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    67
        for i in self.info(u,p,kind[:-1],fn):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    68
            self._download(u,p,kind,i[0],dst)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    69
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    70
    def info(self,u,p,kind,pat):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    71
        #self.login(u,p)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    72
        url = '%s/pypi/%s-info/%s/?json=1' % (self.root,kind,pat)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    73
        resp = self.session.get(url,
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    74
                #data=dict(csrfmiddlewaretoken=self.session.cookies['csrftoken']),
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    75
                headers = dict(Referer=self.loginurl),
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    76
                )
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    77
        status_code = resp.status_code
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    78
        b = resp.content
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    79
        if debug>2:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    80
            print('!!!!!\n%r\n!!!!!'% b)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    81
        if status_code!=200:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    82
            raise ValueError('%s: request %r failed with status_code=%r!\n%r' % (PROG,url,status_code,b))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    83
        I = json.loads(b)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    84
        if verbosity>1:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    85
            print('%s: %r --> %d rows' % (PROG, url, len(I)))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    86
        return I
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    87
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    88
    def upload(self,u,p,kind,fn):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    89
        self.login(u,p)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    90
        url = '%s/pypi/upload-%s/' % (self.root,kind)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    91
        files= dict(file=(os.path.basename(fn),open(fn,'rb'),'application/octet-stream'))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    92
        resp = self.session.post(url,
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    93
                data=dict(csrfmiddlewaretoken=self.session.cookies['csrftoken']),
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    94
                files=files,
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    95
                headers = dict(Referer=self.loginurl),
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    96
                )
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    97
        status_code = resp.status_code
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    98
        text = resp.text
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
    99
        if text!='OK' or status_code!=200:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   100
            raise ValueError('%s: upload %r failed with status_code=%r!\n%r' % (PROG,url,status_code,text))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   101
        if verbosity:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   102
            print('%s: uploaded %r to %r.' % (PROG,fn,url))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   103
        return resp.status_code
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   104
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   105
def getoption(key,default=0,cnv=int):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   106
    key = '--%s=' % key
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   107
    v = [x for x in sys.argv if x.startswith(key)]
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   108
    if v:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   109
        for x in v:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   110
            sys.argv.remove(x)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   111
        v = cnv(v[-1][len(key):])
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   112
    else:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   113
        v = default
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   114
    return v
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   115
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   116
def _file_info(fn):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   117
    st = os.stat(fn)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   118
    return (fn,st.st_size,st.st_mtime)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   119
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   120
def tabulate(I):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   121
    if I:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   122
        rows = [['Name','Length',(5*' ')+'Modified']]
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   123
        for nm,sz,mt in I:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   124
            rows.append([nm,str(sz),time.strftime('%Y%m%d %H:%M:%S',time.localtime(mt))])
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   125
        W = [max(map(len,col)) for col in [list(i) for i in zip(*rows)]]
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   126
        if debug>3:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   127
            print('tabluate: rows=%s' % repr(rows))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   128
            print('tabluate: W=%s' % repr(W))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   129
        fmt = '{:<%d} {:>%d}    {:<%d}' % tuple(W)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   130
        print('\n'.join(fmt.format(*i) for i in rows))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   131
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   132
def main():
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   133
    u = os.environ.get('CITOOLS_USER','beta')
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   134
    p = os.environ.get('CITOOLS_PASSWORD','???')
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   135
    global debug, verbosity
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   136
    debug = getoption('debug')
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   137
    verbosity = getoption('verbosity')
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   138
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   139
    if debug>3:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   140
        import logging
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   141
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   142
        # These two lines enable debugging at httplib level (requests->urllib3->http.client)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   143
        # You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   144
        # The only thing missing will be the response.body which is not logged.
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   145
        try:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   146
            import http.client as http_client
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   147
        except ImportError:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   148
            # Python 2
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   149
            import httplib as http_client
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   150
        http_client.HTTPConnection.debuglevel = 1
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   151
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   152
        # You must initialize logging, otherwise you'll not see debug output.
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   153
        logging.basicConfig()
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   154
        logging.getLogger().setLevel(logging.DEBUG)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   155
        requests_log = logging.getLogger("requests.packages.urllib3")
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   156
        requests_log.setLevel(logging.DEBUG)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   157
        requests_log.propagate = True
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   158
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   159
    dst = getoption('dst',None,cnv=str)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   160
    try:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   161
        cmd = sys.argv[1]
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   162
    except:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   163
        cmd = 'help'
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   164
    pypi = PyPiRequestor(debug=debug)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   165
    if cmd=='test':
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   166
        status_code = pypi.login(u,p)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   167
        if debug:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   168
            print('status=%s' % status_code)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   169
    elif cmd.startswith('download-'):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   170
        kind = cmd.split('-')[1]
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   171
        if not kind in ('resources','packages'):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   172
            raise ValueError('%s: invalid download kind: %r' % (PROG,kind))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   173
        if dst and not os.path.isdir(dst):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   174
            raise ValueError('%s: %r is not a directory!' % (PROG,dst))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   175
        for fn in sys.argv[2:]:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   176
            pypi.download(u,p,kind,fn,dst)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   177
    elif cmd.endswith('-info'):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   178
        kind = cmd.split('-')[0]
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   179
        if not kind in ('resource','package'):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   180
            raise ValueError('%s: invalid info kind: %r' % (PROG,kind))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   181
        tabulate([i for fn in sys.argv[2:] for i in pypi.info(u,p,kind,fn)])
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   182
    elif cmd.startswith('upload-'):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   183
        kind = cmd.split('-')[1]
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   184
        if not kind in ('resources','packages'):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   185
            raise ValueError('%s: invalid upload kind: %r' % (PROG,kind))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   186
        for pat in sys.argv[2:]:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   187
            for fn in glob.glob(pat):
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   188
                pypi.upload(u,p,kind[:-1],fn)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   189
    elif cmd=='info':
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   190
        tabulate([_file_info(i) for fn in sys.argv[2:] for i in glob.glob(fn)])
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   191
    elif cmd=='help':
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   192
        print('Usage %s [test|info|download-[resources|packages]|upload-[resources|packages]|[package|resource]-info] path....' % PROG)
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   193
    else:
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   194
        raise ValueError('%s: nknown command %r' % (PROG,cmd))
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   195
if __name__=='__main__':
664ae0993bd1 first checkin
robin <robin@reportlab.com>
parents:
diff changeset
   196
    main()