Permalink
Browse files

Commit of the first commands

Sketching implementation for search, download, install, mirror. There is also
a pretty useless "user" command.
  • Loading branch information...
0 parents commit 88e58cb8d3748833b5c124f64b083f095357c3e8 @dvarrazzo committed Apr 25, 2011
Showing with 665 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +25 −0 COPYING
  3. +33 −0 Makefile
  4. +1 −0 README
  5. +10 −0 pgxn/__init__.py
  6. +84 −0 pgxn/client/__init__.py
  7. +364 −0 pgxn/client/commands.py
  8. +33 −0 pgxn/client/errors.py
  9. +18 −0 pgxn/client/i18n.py
  10. +52 −0 pgxn/client/network.py
  11. +1 −0 scripts/pgxn
  12. +43 −0 scripts/pgxncli.py
@@ -0,0 +1 @@
+env
@@ -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.
@@ -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
@@ -0,0 +1 @@
+A command line tool to interact with the PostgreSQL Extension Network.
@@ -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
+
@@ -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
+
Oops, something went wrong.

0 comments on commit 88e58cb

Please sign in to comment.