In [98]:
import binstar_client

public_token = open('/home/edill/dev/dotfiles/tokens/lightsource2-testing.token', 'r').read().strip()
public = binstar_client.Binstar(token=token)
public_condaforge = public.show_channel('main', 'conda-forge')

In [99]:
public_condaforge['files'][0]


Out[99]:
{'attrs': {'arch': 'x86_64',
  'build': 'py27_0',
  'build_number': 0,
  'depends': ['python 2.7*'],
  'license': 'BSD 3-Clause',
  'machine': 'x86_64',
  'operatingsystem': 'linux',
  'platform': 'linux',
  'subdir': 'linux-64',
  'target-triplet': 'x86_64-any-linux'},
 'basename': 'linux-64/affine-1.2.0-py27_0.tar.bz2',
 'dependencies': {'depends': [{'name': 'python', 'specs': [['==', '2.7']]}]},
 'description': None,
 'distribution_type': 'conda',
 'download_url': '//api.anaconda.org/download/conda-forge/affine/1.2.0/linux-64/affine-1.2.0-py27_0.tar.bz2',
 'full_name': 'conda-forge/affine/1.2.0/linux-64/affine-1.2.0-py27_0.tar.bz2',
 'md5': '5523b283cbc93fd7f7c31ce634133c72',
 'ndownloads': 55,
 'owner': 'conda-forge',
 'size': 19504,
 'type': 'conda',
 'upload_time': '2016-03-29 17:22:50.403000+00:00',
 'version': '1.2.0'}

In [46]:
nsls2_token = open('/home/edill/dev/dotfiles/tokens/edill.anaconda.nsls2.token').read().strip()
nsls2 = binstar_client.Binstar(domain='https://anaconda.nsls2.bnl.gov/api',
                              token=nsls2_token)

In [53]:
nsls2tag = nsls2.show_channel('main', 'nsls2-tag')

In [ ]:
'cat'.split

In [60]:
f0 = nsls2tag['files'][0]
login, package_name, version, platform, filename = f0['full_name'].split('/')

In [61]:
login, package_name, version, platform, filename


Out[61]:
('nsls2-tag',
 'xray-vision',
 '0.0.4',
 'linux-64',
 'xray-vision-0.0.4-py35_0.tar.bz2')

In [70]:
ret = nsls2.download(login, 
                     package_name, 
                     f0['version'], 
                     f0['basename'])

In [85]:
with open('/tmp/{}'.format(f0['basename'].split('/')[-1]), 'wb') as f:
#     for chunk in ret.iter_content(chunk_size=512 * 1024):
#         if chunk:
    f.write(ret.content)

In [86]:
import tempfile

In [92]:
tempdir = tempfile.TemporaryDirectory(prefix='conda_downloader')

In [96]:
tempdir.name


Out[96]:
'/tmp/conda_downloader2llsgezb'

In [77]:
nsls2.add_package(login='edill', package_name=package_name, 
#                   release=f0['version'], 
#                   basename=f0['basename'],
#                   fd=ret.content, 
#                   distribution_type=f0['distribution_type'],
#                   description=f0['description'],
#                   dependencies=f0['dependencies'],
                  attrs=f0['attrs']
                 )


---------------------------------------------------------------------------
BinstarError                              Traceback (most recent call last)
<ipython-input-77-317fbf628ca0> in <module>()
      6 #                   description=f0['description'],
      7 #                   dependencies=f0['dependencies'],
----> 8                   attrs=f0['attrs']
      9                  ) 

/home/edill/miniconda/lib/python3.5/site-packages/binstar_client/__init__.py in add_package(self, login, package_name, summary, license, public, license_url, attrs)
    329         data, headers = jencode(payload)
    330         res = self.session.post(url, data=data, headers=headers)
--> 331         self._check_response(res)
    332         return res.json()
    333 

/home/edill/miniconda/lib/python3.5/site-packages/binstar_client/__init__.py in _check_response(self, res, allowed)
    194                 ErrCls = errors.ServerError
    195 
--> 196             raise ErrCls(msg, res.status_code)
    197 
    198     def user(self, login=None):

BinstarError: ('package name xray-vision already exists', 400)

In [78]:
import subprocess

In [ ]:
subprocess.check_call(['anaconda', 'upload', '-u'])

In [76]:
nsls2.upload(login='edill', package_name=package_name, 
             release=f0['version'], 
             basename=f0['basename'],
             fd=ret.content, 
             distribution_type=f0['distribution_type'],
             description=f0['description'],
             dependencies=f0['dependencies'],
             attrs=f0['attrs']
            )


---------------------------------------------------------------------------
NotFound                                  Traceback (most recent call last)
<ipython-input-76-568e23597627> in <module>()
      6              description=f0['description'],
      7              dependencies=f0['dependencies'],
----> 8              attrs=f0['attrs']
      9             )

/home/edill/miniconda/lib/python3.5/site-packages/binstar_client/__init__.py in upload(self, login, package_name, release, basename, fd, distribution_type, description, md5, size, dependencies, attrs, channels, callback)
    472         data, headers = jencode(payload)
    473         res = self.session.post(url, data=data, headers=headers)
--> 474         self._check_response(res)
    475         obj = res.json()
    476 

/home/edill/miniconda/lib/python3.5/site-packages/binstar_client/__init__.py in _check_response(self, res, allowed)
    194                 ErrCls = errors.ServerError
    195 
--> 196             raise ErrCls(msg, res.status_code)
    197 
    198     def user(self, login=None):

NotFound: ("release version=u'0.0.4' does not exist", 404)

In [74]:
nsls2.add_package?

In [97]:
subprocess.Popen?

In [68]:
f0a


Out[68]:
{'attrs': {'arch': 'x86_64',
  'build': 'py35_0',
  'build_number': 0,
  'depends': ['matplotlib', 'numpy', 'pyqt', 'python 3.5*', 'six'],
  'license': '3-Clause BSD',
  'machine': 'x86_64',
  'operatingsystem': 'linux',
  'platform': 'linux',
  'subdir': 'linux-64',
  'target-triplet': 'x86_64-any-linux'},
 'basename': 'linux-64/xray-vision-0.0.4-py35_0.tar.bz2',
 'dependencies': {'depends': [{'name': 'matplotlib', 'specs': []},
   {'name': 'numpy', 'specs': []},
   {'name': 'pyqt', 'specs': []},
   {'name': 'python', 'specs': [['==', '3.5']]},
   {'name': 'six', 'specs': []}]},
 'description': None,
 'distribution_type': 'conda',
 'download_url': '//anaconda.nsls2.bnl.gov/download/nsls2-tag/xray-vision/0.0.4/linux-64/xray-vision-0.0.4-py35_0.tar.bz2',
 'full_name': 'nsls2-tag/xray-vision/0.0.4/linux-64/xray-vision-0.0.4-py35_0.tar.bz2',
 'md5': '3a0f56e4e559aba43f9da22a16c580cb',
 'ndownloads': 0,
 'owner': 'nsls2-tag',
 'size': 136493,
 'type': 'conda',
 'upload_time': '2016-02-10 20:43:25.343000+00:00',
 'version': '0.0.4'}

In [49]:
nsls2tag['files'][0]


Out[49]:
{'attrs': {'arch': 'x86_64',
  'build': 'py35_0',
  'build_number': 0,
  'depends': ['matplotlib', 'numpy', 'pyqt', 'python 3.5*', 'six'],
  'license': '3-Clause BSD',
  'machine': 'x86_64',
  'operatingsystem': 'linux',
  'platform': 'linux',
  'subdir': 'linux-64',
  'target-triplet': 'x86_64-any-linux'},
 'basename': 'linux-64/xray-vision-0.0.4-py35_0.tar.bz2',
 'dependencies': {'depends': [{'name': 'matplotlib', 'specs': []},
   {'name': 'numpy', 'specs': []},
   {'name': 'pyqt', 'specs': []},
   {'name': 'python', 'specs': [['==', '3.5']]},
   {'name': 'six', 'specs': []}]},
 'description': None,
 'distribution_type': 'conda',
 'download_url': '//anaconda.nsls2.bnl.gov/download/nsls2-tag/xray-vision/0.0.4/linux-64/xray-vision-0.0.4-py35_0.tar.bz2',
 'full_name': 'nsls2-tag/xray-vision/0.0.4/linux-64/xray-vision-0.0.4-py35_0.tar.bz2',
 'md5': '3a0f56e4e559aba43f9da22a16c580cb',
 'ndownloads': 0,
 'owner': 'nsls2-tag',
 'size': 136493,
 'type': 'conda',
 'upload_time': '2016-02-10 20:43:25.343000+00:00',
 'version': '0.0.4'}

In [18]:
anaconda_packages = public.user_packages('anaconda')

In [19]:
condaforge_packages = public.user_packages('conda-forge')

In [28]:
condaforge_channel = public.show_channel('main', 'conda-forge')

In [29]:
condaforge_channel['files'][0]


Out[29]:
{'attrs': {'arch': 'x86_64',
  'build': 'py27_0',
  'build_number': 0,
  'depends': ['python 2.7*'],
  'license': 'BSD 3-Clause',
  'machine': 'x86_64',
  'operatingsystem': 'linux',
  'platform': 'linux',
  'subdir': 'linux-64',
  'target-triplet': 'x86_64-any-linux'},
 'basename': 'linux-64/affine-1.2.0-py27_0.tar.bz2',
 'dependencies': {'depends': [{'name': 'python', 'specs': [['==', '2.7']]}]},
 'description': None,
 'distribution_type': 'conda',
 'download_url': '//api.anaconda.org/download/conda-forge/affine/1.2.0/linux-64/affine-1.2.0-py27_0.tar.bz2',
 'full_name': 'conda-forge/affine/1.2.0/linux-64/affine-1.2.0-py27_0.tar.bz2',
 'md5': '5523b283cbc93fd7f7c31ce634133c72',
 'ndownloads': 55,
 'owner': 'conda-forge',
 'size': 19504,
 'type': 'conda',
 'upload_time': '2016-03-29 17:22:50.403000+00:00',
 'version': '1.2.0'}

In [21]:
condaforge_packages[0]


Out[21]:
{'app_entry': {},
 'app_summary': {},
 'app_type': {},
 'conda_platforms': ['linux-64', 'win-32', 'win-64', 'osx-64'],
 'full_name': 'conda-forge/affine',
 'html_url': 'http://anaconda.org/conda-forge/affine',
 'id': '56fab9ea0697b60a633d575a',
 'latest_version': '2.0.0.post1',
 'name': 'affine',
 'owner': 'conda-forge',
 'package_types': ['conda'],
 'public': True,
 'revision': 39,
 'summary': 'Matrices describing affine transformation of the plane',
 'url': 'http://api.anaconda.org/packages/conda-forge/affine',
 'versions': ['1.2.0', '1.3.0', '2.0.0.post1']}

In [30]:
anaconda_packages[4]


Out[30]:
{'app_entry': {},
 'app_summary': {},
 'app_type': {},
 'conda_platforms': ['linux-64', 'linux-32', 'osx-64'],
 'full_name': 'anaconda/abstract-rendering',
 'html_url': 'http://anaconda.org/anaconda/abstract-rendering',
 'id': '5637ebd89c73330b8ae7dc3e',
 'latest_version': '0.5.1',
 'name': 'abstract-rendering',
 'owner': 'anaconda',
 'package_types': ['conda'],
 'public': True,
 'revision': 65,
 'summary': '',
 'url': 'http://api.anaconda.org/packages/anaconda/abstract-rendering',
 'versions': ['0.5.1', '0.5.0', '0.3.1', '0.4.0', '0.1.0']}

In [27]:
public.download??

In [23]:
pkg = anaconda_packages[0]
login = pkg['owner']
package_name = pkg['name']
release = pkg['versions'][-1]
basename = 'linux_64/{}'.format()
public.download(anaconda_packages[0]['owner'],
                anaconda_packages[0]['name'],
                anaconda_packages[0]['versions'][0])


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-23-fb026409b318> in <module>()
----> 1 public.download(anaconda_packages[0]['url'])

TypeError: download() missing 3 required positional arguments: 'package_name', 'release', and 'basename'