Skip to content

Commit

Permalink
Commit of the first commands
Browse files Browse the repository at this point in the history
Sketching implementation for search, download, install, mirror. There is also
a pretty useless "user" command.
  • Loading branch information
dvarrazzo committed Apr 25, 2011
0 parents commit 88e58cb
Show file tree
Hide file tree
Showing 12 changed files with 665 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
env
25 changes: 25 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2011, Daniele Varrazzo <daniele.varrazzo@gmail.com>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* The name of Daniele Varrazzo may not be used to endorse or promote
products derived from this software without specific prior written
permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# pgxn.client Makefile
#
# Copyright (C) 2011 Daniele Varrazzo
#
# This file is part of the PGXN client

.PHONY: env

PYTHON := python$(PYTHON_VERSION)
PYTHON_VERSION ?= $(shell $(PYTHON) -c 'import sys; print ("%d.%d" % sys.version_info[:2])')
ENV_DIR = $(shell pwd)/env
ENV_BIN = $(ENV_DIR)/bin
ENV_LIB = $(ENV_DIR)/lib
EASY_INSTALL = PYTHONPATH=$(ENV_LIB) $(ENV_BIN)/easy_install-$(PYTHON_VERSION) -d $(ENV_LIB) -s $(ENV_BIN)
EZ_SETUP = $(ENV_BIN)/ez_setup.py


# Install development dependencies.

env: easy_install
mkdir -p $(ENV_BIN)
mkdir -p $(ENV_LIB)
$(EASY_INSTALL) uri
$(EASY_INSTALL) argparse
$(EASY_INSTALL) zc.buildout

easy_install: ez_setup
PYTHONPATH=$(ENV_LIB) $(PYTHON) $(EZ_SETUP) -d $(ENV_LIB) -s $(ENV_BIN) setuptools

ez_setup:
mkdir -p $(ENV_BIN)
mkdir -p $(ENV_LIB)
wget -O $(EZ_SETUP) http://peak.telecommunity.com/dist/ez_setup.py
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A command line tool to interact with the PostgreSQL Extension Network.
10 changes: 10 additions & 0 deletions pgxn/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
pgxn.client -- pgxn package
This package is currently only meant as a placeholder.
"""

# Copyright (C) 2011 Daniele Varrazzo

# This file is part of the PGXN client

84 changes: 84 additions & 0 deletions pgxn/client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""
pgxn.client -- main package
"""

# Copyright (C) 2011 Daniele Varrazzo

# This file is part of the PGXN client

__version__ = '0.1dev0'


import re

from pgxn.client.errors import BadSpecError

class Name(str):
"""A string representing a package name."""
# TODO: range

class SemVer(str):
"""A string representing a semantic version specification.
See: http://semver.org/
"""
# TODO: format and ordering


class Spec(object):
"""A name together with a range of versions."""
def __init__(self, name, op=None, ver=None):
self.name = name
self.op = op
self.ver = ver

@classmethod
def parse(self, spec):
"""Parse a spec string and return name and version required.
Return (name, op, version), op and version can be None.
Raise BadSpecError if couldn't parse.
"""
# split operator/version and name
m = re.match(r'(.+?)(?:(==|=|>=|>|<=|<)(.*))?$', spec)
if m is None:
raise BadSpecError('bad format')

name = Name(m.group(1))
op = m.group(2)
if op == '=':
op = '=='

if op is not None:
ver = SemVer(m.group(3))
else:
ver = None

return Spec(name, op, ver)


class Extension(object):
def __init__(self, name=None, version=None, status=None, abstract=None):
self.name = name
self.version = version
self.status = status
self.abstract = abstract

@classmethod
def from_json(self, data):
data1 = data[data['latest']]
name = data['extension']
abstract = data1.get('abstract')

rv = []
for ver, vdata in data['versions'].iteritems():
vdata = vdata[0]
ver = SemVer(ver)
ext = Extension(name=name, version=ver,
status=vdata.get('status', 'stable'),
abstract=abstract)
rv.append(ext)

rv.sort(key=lambda x: x.version, reverse=True)
return rv

Loading

0 comments on commit 88e58cb

Please sign in to comment.