Home

Mongoose Web Server Spec @ 2010-03-10 20:19:33
Filed under: Code  Fedora  Linux  Python  Tech 
I happened to take a look at this and see there wasn't a package for it. It's one of those items that I don't have time to keep up with but I think would be a nice package to have in Fedora. If anyone wants to pick up with this and run with it be my guest!

The package includes a subpackage for devel (a single header file) and a subpackage for the Python bindings. There is also a patch to get the Python code to find the shared object.

Have fun!

Patch: mongoose-site-location.patch
--- bindings/python/mongoose.py	2010-03-10 20:07:53.735407453 -0500
+++ bindings/python/mongoose.py	2010-03-10 20:09:08.935760549 -0500
@@ -110,7 +110,8 @@
 
 	def __init__(self, **kwargs):
 		dll_extension = os.name == 'nt' and 'dll' or 'so'
-		self.dll = ctypes.CDLL('_mongoose.%s' % dll_extension)
+		from distutils.sysconfig import get_python_lib
+		self.dll = ctypes.CDLL(get_python_lib(1) + '/_mongoose.%s' % dll_extension)
 		start = self.dll.mg_start
 		self.ctx = ctypes.c_voidp(self.dll.mg_start()).value
 		self.version = ctypes.c_char_p(self.dll.mg_version()).value
Spec:
# sitearch for others (remove the unneeded one)
%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}


Name:           mongoose
Version:        2.8
Release:        1%{?dist}
Summary:        Simple and easy to use web server

Group:          System Environment/Daemons
License:        MIT
URL:            http://code.google.com/p/mongoose/
Source0:        http://mongoose.googlecode.com/files/%{name}-%{version}.tgz
Patch0:         mongoose-site-location.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)


%description
Mongoose is an easy to use web server. It can be embedded into
existing application to provide a web interface to it.


%package python
Summary:       Python bindings for the mongoose web server
Requires:      mongoose


%description python
Mongoose is an easy to use web server. It can be embedded into
existing application to provide a web interface to it. This
package includes the bindings for the Python programming language.


%package devel
Summary:       Development files for the mongoose web server
BuildArch:     noarch


%description devel
Mongoose is an easy to use web server. It can be embedded into
existing application to provide a web interface to it. This
package includes the development files.


%prep
%setup -qn %{name}
%patch0


%build
make %{?_smp_mflags} linux


%install
rm -rf $RPM_BUILD_ROOT
# Install the base
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
mkdir -p $RPM_BUILD_ROOT/%{_mandir}/man1/
cp %{name} $RPM_BUILD_ROOT/%{_bindir}
cp %{name}.1 $RPM_BUILD_ROOT/%{_mandir}/man1/

# Install the python bindings
mkdir -p $RPM_BUILD_ROOT/%{python_sitearch}
cp bindings/python/mongoose.py _%{name}.so $RPM_BUILD_ROOT/%{python_sitearch}

# Install the development files
mkdir -p $RPM_BUILD_ROOT/%{_includedir}/%{name}/
cp %{name}.h $RPM_BUILD_ROOT/%{_includedir}/%{name}/


%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%{_bindir}/%{name}
%{_mandir}/man1/%{name}.1.gz


%files python
%defattr(-,root,root,-)
%{python_sitearch}/_%{name}.so
%{python_sitearch}/%{name}.py*


%files devel
%defattr(-,root,root,-)
%{_includedir}/%{name}/


%changelog
* Wed Mar 10 2010 Steve 'Ashcrow' Milner <me@stevemilner.org> 2.8-1
- Initial spec

 digg it   seed it   del.icio.us   ma.gnolia
Comments: 0 Tags:          


I Don't Know Why I Wrote This @ 2010-02-14 20:45:01
Filed under: Code  Personal  Python  Tech 
More or less a dictionary store on the network with very simple authentication. I don't know what got into me ... I had no intention of writing this ... hopefully it will be of use to someone. It is a little messy, but it works on Python2.6.

# WHY DID I WRITE THIS?!

import os
import yaml

from multiprocessing import Process
from multiprocessing.managers import BaseManager


class WriteableDict(dict):
    """
    A dictionary which can write to disk.
    """

    def __init__(self, fs_loc, *args, **kwargs):
        """
        Create the instance.

        :Parameters:
           - `fs_loc`: location on disk to write to
           - `args`: all other non-keyword arguments
           - `kwargs`: all other keyword arguments
        """
        dict.__init__(self, *args, **kwargs)
        self.__fs_loc = fs_loc
        self.__saving = None

    def __save_to_disk(self):
        """
        Save to disk.
        """
        # If we are trying to save while anothe save is happening
        # kill the previous save as it's already out of date
        try:
            if self.__saving.is_alive():
                self.__saving.terminate()
            self.__saving.join()
        except:
            pass

        def save(write, data):
            with open(write, 'w') as fs_file:
                fs_file.write(yaml.dump(data.copy()))
            self.__saving = False

        self.__saving = Process(target=save, args=(self.__fs_loc, self))
        self.__saving.daemon = True
        self.__saving.start()

    def update(self, *args, **kwargs):
        """
        Write enabled update.

        :Parameters:
           - `args`: all other non-keyword arguments
           - `kwargs`: all other keyword arguments
        """
        dict.update(self, *args, **kwargs)
        self.__save_to_disk()

    def pop(self, *args, **kwargs):
        """
        Write enabled pop.

        :Parameters:
           - `args`: all other non-keyword arguments
           - `kwargs`: all other keyword arguments
        """
        dict.pop(self, *args, **kwargs)
        self.__save_to_disk()

    def popitem(self, *args, **kwargs):
        """
        Write enabled popitem.

        :Parameters:
           - `args`: all other non-keyword arguments
           - `kwargs`: all other keyword arguments
        """
        dict.popitem(self, *args, **kwargs)
        self.__save_to_disk()

    def clear(self, *args, **kwargs):
        """
        Write enabled clear.

        :Parameters:
           - `args`: all other non-keyword arguments
           - `kwargs`: all other keyword arguments
        """
        dict.clear(self, *args, **kwargs)
        self.__save_to_disk()


class DataBroker(object):

    __data = {}

    def __init__(self, data_loc, auth):
        """
        Creates an instance of the broker and loads any initial data found.

        :Parameters:
           - `data_loc`: directory on disk that houses any .data files to load
           - `auth`: auth information to use
        """
        self.__auth = auth
        self.__data_loc = data_loc
        for loc in filter(lambda s: s.endswith('.data'), os.listdir(data_loc)):
            full_path = os.path.sep.join([data_loc, loc])
            name = os.path.basename(loc).replace('.data', '')
            with open(full_path, 'r') as f_loc:
                self.__data[name] = WriteableDict(
                    full_path, yaml.load(f_loc.read()))

    def __authenticate(self, user, passwd):
        """
        Poor mans authentication.

        :Parameters:
           - `user`: username
           - `pasword`: ... password
        """
        if user in self.__auth.keys():
            if self.__auth[user][0] == passwd:
                return True
        return False

    def get_data(self, user, passwd, name):
        """
        Hands over access to the dictionary.

        :Parameters:
           - `user`: username
           - `password`: password
           - `name`: name of the dictionary to access
        """
        if self.__authenticate(user, passwd):
            if name in self.__auth[user][1]:
                if name not in self.__data.keys():
                    self.__data[name] = WriteableDict(self.__data_loc + name + ".data")
                return self.__data[name]
        raise Exception


class DataManager(BaseManager):
    """
    Data Manager.
    """

    def __init__(self, *args, **kwargs):
        """
        Creates an instance of the manager.

        :Parameters:
           - `args`: all other non-keyword arguments
           - `kwargs`: all other keyword arguments
        """
        BaseManager.__init__(self, *args, **kwargs)
        self.register('get_data',
            callable=lambda u, p, s: broker.get_data(u, p, s))


if __name__ == '__main__':
    # Auth information user: (password (dicts, that, they, can, access))
    auth = {'test': ('testing', ('something', ))}
    # Setup the broker and manager
    broker = DataBroker('/tmp/', auth)
    manager = DataManager(address=('', 50000), authkey='abracadabra')
    # and serve until a ctrl+c
    server = manager.get_server()
    try:
        server.serve_forever()
    except KeyboardInterrupt, ki:
        server.shutdown()

 digg it   seed it   del.icio.us   ma.gnolia
Comments: 0 Tags:        


Facebook's tornado rpm spec @ 2009-09-12 15:47:49
Filed under: Code  Fedora  Python  Tech 
Not sure if I'm going to push this up as I don't see myself using it (and thus maintain the package properly) so if you want to run with it, go ahead :-).

Edit: Some feeds were reporting funny results with the rendered code tags ... changed to pre.

[steve@mobileoppressionpalace SPECS]$ cat tornado.spec                                                                   
# sitelib for noarch packages                                                                                            
%{!?python_sitelib: %global python_sitelib %(%{__python} -c \
"from distutils.sysconfig import get_python_lib; print get_python_lib()")}                                                                                                                        

Name:           tornado
Version:        0.1    
Release:        1%{?dist}
Summary:        An open source version of the scalable, non-blocking web server

Group:          Development/Languages
License:        ASL 2.0
URL:            http://www.tornadoweb.org/
Source0:        http://www.tornadoweb.org/static/%{name}-%{version}.tar.gz
Patch0:         tornado-no-hashbang-for-non-exec-scripts.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildArch:      noarch
BuildRequires:  python-devel
Requires:       python-pycurl, python-simplejson


%description
Tornado is an open source version of the scalable, non-blocking web server
and tools that power FriendFeed. The FriendFeed application is written using
a web framework that looks a bit like web.py or Google's webapp, but with
additional tools and optimizations to take advantage of the underlying
non-blocking infrastructure.

%prep
%setup -q
%patch0 -p 1


%build
%{__python} setup.py build


%install
rm -rf $RPM_BUILD_ROOT
%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT


%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%doc README
# For noarch packages: sitelib
%{python_sitelib}/*


%changelog
* Sat Sep 12 2009 Steve 'Ashcrow' Milner  0.1-1
- Initial package
[steve@mobileoppressionpalace SPECS]$ cat ../SOURCES/tornado-no-hashbang-for-non-exec-scripts.patch 
diff -ur tornado-0.1/tornado/auth.py tornado-0.1.mine/tornado/auth.py                               
--- tornado-0.1/tornado/auth.py 2009-09-10 13:32:56.000000000 -0400                                 
+++ tornado-0.1.mine/tornado/auth.py    2009-09-12 14:01:08.716733153 -0400                         
@@ -1,5 +1,3 @@                                                                                     
-#!/usr/bin/env python                                                                              
-#                                                                                                  
 # Copyright 2009 Facebook                                                                          
 #                                                                                                  
 # Licensed under the Apache License, Version 2.0 (the "License"); you may                          
diff -ur tornado-0.1/tornado/database.py tornado-0.1.mine/tornado/database.py                       
--- tornado-0.1/tornado/database.py     2009-09-10 13:32:56.000000000 -0400                         
+++ tornado-0.1.mine/tornado/database.py        2009-09-12 14:02:40.012605235 -0400                 
@@ -1,5 +1,3 @@                                                                                     
-#!/usr/bin/env python                                                                              
-#                                                                                                  
 # Copyright 2009 Facebook                                                                          
 #                                                                                                  
 # Licensed under the Apache License, Version 2.0 (the "License"); you may                          
diff -ur tornado-0.1/tornado/escape.py tornado-0.1.mine/tornado/escape.py                           
--- tornado-0.1/tornado/escape.py       2009-09-10 13:32:56.000000000 -0400                         
+++ tornado-0.1.mine/tornado/escape.py  2009-09-12 14:02:48.993692391 -0400                         
@@ -1,5 +1,3 @@                                                                                     
-#!/usr/bin/env python                                                                              
-#                                                                                                  
 # Copyright 2009 Facebook                                                                          
 #                                                                                                  
 # Licensed under the Apache License, Version 2.0 (the "License"); you may                          
diff -ur tornado-0.1/tornado/httpclient.py tornado-0.1.mine/tornado/httpclient.py                   
--- tornado-0.1/tornado/httpclient.py   2009-09-10 13:32:56.000000000 -0400                         
+++ tornado-0.1.mine/tornado/httpclient.py      2009-09-12 14:03:04.558617851 -0400                 
@@ -1,5 +1,3 @@                                                                                     
-#!/usr/bin/env python                                                                              
-#                                                                                                  
 # Copyright 2009 Facebook                                                                          
 #                                                                                                  
 # Licensed under the Apache License, Version 2.0 (the "License"); you may                          
diff -ur tornado-0.1/tornado/httpserver.py tornado-0.1.mine/tornado/httpserver.py                   
--- tornado-0.1/tornado/httpserver.py   2009-09-10 13:32:56.000000000 -0400                         
+++ tornado-0.1.mine/tornado/httpserver.py      2009-09-12 14:03:15.499707010 -0400                 
@@ -1,5 +1,3 @@                                                                                     
-#!/usr/bin/env python                                                                              
-#                                                                                                  
 # Copyright 2009 Facebook                                                                          
 #                                                                                                  
 # Licensed under the Apache License, Version 2.0 (the "License"); you may                          
diff -ur tornado-0.1/tornado/__init__.py tornado-0.1.mine/tornado/__init__.py                       
--- tornado-0.1/tornado/__init__.py     2009-09-10 13:32:56.000000000 -0400                         
+++ tornado-0.1.mine/tornado/__init__.py        2009-09-12 14:03:24.101684722 -0400                 
@@ -1,5 +1,3 @@                                                                                     
-#!/usr/bin/env python                                                                              
-#                                                                                                  
 # Copyright 2009 Facebook                                                                          
 #                                                                                                  
 # Licensed under the Apache License, Version 2.0 (the "License"); you may                          
diff -ur tornado-0.1/tornado/ioloop.py tornado-0.1.mine/tornado/ioloop.py                           
--- tornado-0.1/tornado/ioloop.py       2009-09-10 13:32:56.000000000 -0400                         
+++ tornado-0.1.mine/tornado/ioloop.py  2009-09-12 14:03:43.310690548 -0400                         
@@ -1,5 +1,3 @@                                                                                     
-#!/usr/bin/env python                                                                              
-#                                                                                                  
 # Copyright 2009 Facebook                                                                          
 #                                                                                                  
 # Licensed under the Apache License, Version 2.0 (the "License"); you may                          
diff -ur tornado-0.1/tornado/iostream.py tornado-0.1.mine/tornado/iostream.py                       
--- tornado-0.1/tornado/iostream.py     2009-09-10 13:32:56.000000000 -0400                         
+++ tornado-0.1.mine/tornado/iostream.py        2009-09-12 14:03:49.922692867 -0400                 
@@ -1,5 +1,3 @@                                                                                     
-#!/usr/bin/env python                                                                              
-#                                                                                                  
 # Copyright 2009 Facebook                                                                          
 #                                                                                                  
 # Licensed under the Apache License, Version 2.0 (the "License"); you may                          
diff -ur tornado-0.1/tornado/locale.py tornado-0.1.mine/tornado/locale.py                           
--- tornado-0.1/tornado/locale.py       2009-09-10 13:32:56.000000000 -0400                         
+++ tornado-0.1.mine/tornado/locale.py  2009-09-12 14:03:56.554607130 -0400                         
@@ -1,5 +1,3 @@                                                                                     
-#!/usr/bin/env python                                                                              
-#                                                                                                  
 # Copyright 2009 Facebook
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may
diff -ur tornado-0.1/tornado/options.py tornado-0.1.mine/tornado/options.py
--- tornado-0.1/tornado/options.py      2009-09-10 13:32:56.000000000 -0400
+++ tornado-0.1.mine/tornado/options.py 2009-09-12 14:04:11.897690510 -0400
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2009 Facebook
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may
diff -ur tornado-0.1/tornado/s3server.py tornado-0.1.mine/tornado/s3server.py
--- tornado-0.1/tornado/s3server.py     2009-09-10 13:32:56.000000000 -0400
+++ tornado-0.1.mine/tornado/s3server.py        2009-09-12 14:04:18.419607955 -0400
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2009 Facebook
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may
diff -ur tornado-0.1/tornado/template.py tornado-0.1.mine/tornado/template.py
--- tornado-0.1/tornado/template.py     2009-09-10 13:32:56.000000000 -0400
+++ tornado-0.1.mine/tornado/template.py        2009-09-12 14:04:25.778730891 -0400
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2009 Facebook
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may
diff -ur tornado-0.1/tornado/web.py tornado-0.1.mine/tornado/web.py
--- tornado-0.1/tornado/web.py  2009-09-10 13:32:56.000000000 -0400
+++ tornado-0.1.mine/tornado/web.py     2009-09-12 14:04:32.843607704 -0400
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2009 Facebook
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may
diff -ur tornado-0.1/tornado/wsgi.py tornado-0.1.mine/tornado/wsgi.py
--- tornado-0.1/tornado/wsgi.py 2009-09-10 13:32:56.000000000 -0400
+++ tornado-0.1.mine/tornado/wsgi.py    2009-09-12 14:04:39.124604938 -0400
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2009 Facebook
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may

 digg it   seed it   del.icio.us   ma.gnolia
Comments: 0 Tags:        


Jython Shell Script Verbosity @ 2009-08-08 18:24:39
Filed under: Code  Jython  Python  Tech 
Frank made me want to send something back today so I added script debugging to the jython shell script ... Now I should go eat something.

[steve@powerhouse shell]$ ./jython
./jython:  contains neither jython-dev.jar nor jython.jar.
Try running this script from the 'bin' directory of an installed Jython or
setting $JYTHON_HOME.
[steve@powerhouse shell]$ ./jython --verbose
+ JYTHON_SHELL_DEBUG=true
+ cygwin=false
+ case "`uname`" in
++ uname
+ PRG=./jython
+ '[' -h ./jython ']'
+ '[' -z '' ']'
+ JAVA_CMD=(java)
+ '[' -z '' ']'
+ '[' ./jython = ./jython ']'
++ pwd
+ JYTHON_HOME_1=/home/steve/Tech/jython/jython/src/shell
+ '[' -f /home/steve/Tech/jython/jython/src/shell/jython.jar -o -f \
 /home/steve/Tech/jython/jython/src/shell/jython-dev.jar ']'
++ dirname /home/steve/Tech/jython/jython/src/shell
+ JYTHON_HOME=/home/steve/Tech/jython/jython/src
+ '[' '!' -f /home/steve/Tech/jython/jython/src/jython.jar -a '!' \
-f /home/steve/Tech/jython/jython/src/jython-dev.jar ']'
+ JYTHON_HOME=
+ '[' -z '' ']'
+ JYTHON_OPTS=
+ CP_DELIMITER=:
+ CP=/jython-dev.jar
+ '[' -f /jython-dev.jar ']'
+ '[' '!' -f /jython.jar ']'
+ echo './jython:  contains neither jython-dev.jar nor jython.jar.'
./jython:  contains neither jython-dev.jar nor jython.jar.
+ echo 'Try running this script from the '\''bin'\'' directory of an installed Jython or '
Try running this script from the 'bin' directory of an installed Jython or
+ echo 'setting $JYTHON_HOME.'
setting $JYTHON_HOME.
+ exit 1
[steve@powerhouse shell]$


Here is the actual patch if you are interested ....

diff --git a/jython/src/shell/jython b/jython/src/shell/jython
index ff8df4a..41f145b 100755
--- a/jython/src/shell/jython
+++ b/jython/src/shell/jython
@@ -12,9 +12,25 @@
 #
 # -----------------------------------------------------------------------------

-cygwin=false
+# ----- Allow for script debug mode -------------------------------------------
+# Someone may want to know what this script is doing :-) ... allow --verbose/-v
+# Note that this is done way before other options so the user can see the
+# results from the start.
+JYTHON_SHELL_DEBUG=false
+function toggle_debug {
+    ARGS=$1
+    if [[ "$ARGS" =~ "--verbose" ]]; then
+        if [ $JYTHON_SHELL_DEBUG == false ]; then
+            set -x && JYTHON_SHELL_DEBUG=true
+        else
+            set +x && JYTHON_SHELL_DEBUG=false
+        fi
+    fi
+}
+toggle_debug $@

 # ----- Identify OS we are running under --------------------------------------
+cygwin=false
 case "`uname`" in
   CYGWIN*) cygwin=true;;
   Darwin) darwin=true;;
@@ -267,6 +283,7 @@ elif [ -n "$help_requested" ] ; then
   echo "--print  : print the Java command instead of executing it" >&2
   echo "--profile: run with the Java Interactive Profiler (http://jiprof.sf.net)" >&2
   echo "--boot   : put jython on the boot classpath (disables the bytecode verifier)" >&2
+  echo "--verbose: shows all information on this shell script as it executes" >&2
   echo "--       : pass remaining arguments through to Jython" >&2
   echo "Jython launcher environment variables:" >&2
   echo "JAVA_HOME  : Java installation directory" >&2
@@ -277,5 +294,6 @@ fi
 if $cygwin; then
   stty icanon echo > /dev/null 2>&1
 fi
-
+# Turn off script debug just incase
+toggle_debug $@
 exit $JYTHON_STATUS

 digg it   seed it   del.icio.us   ma.gnolia
Comments: 0 Tags:        


Random SCM and Python Fun @ 2009-08-03 21:56:05
Filed under: Code  Python  Tech 
The following code abstracts getting branch lists from Mercurial and Git. I may continue fleshing it out for use with the distributed SCM presence system ... or it might just be prototype code, I don't know.

The output I got from my test repos looked like this:

['master']
['default', 'pep8', 'package_creator', 'package_manager', 'repository']


Enjoy, or else!!!!

import os
import re
import subprocess


class SCM(object):
    """
    Parent class for all SCM's.
    """

    def __init__(self, bin=None):
        """
        Creates the instance.

        :Parameters:
           - `bin`: if a binary is required it's location is here.
        """
        self.__bin = bin

    def _execute(self, command):
        """
        Helps execute shell commands.

        :Parameters:
           - `command`: the command to execute.
        """
        process = subprocess.Popen(command, shell=True,
            stdin=subprocess.PIPE, stdout=subprocess.PIPE,
            stderr=subprocess.PIPE, close_fds=True)
        return process.stdout, process.stderr

    def _branch_parser(self, data):
        """
        Parses the branch return results. Defaults to a pass through.

        :Parameters:
           - `data`: the data to parse.
        """
        return data

    def get_branches(self, repo_path):
        """
        Get a list of branches.

        :Parameters:
           - `repo_path`: path on the file system to the repository.
        """
        raise NotImplementedError("_get_branches must be implemented")

    # read-only properties
    bin = property(lambda s: s.__bin)


class Git(SCM):
    """
    The Git SCM.
    """

    def _branch_parser(self, data):
        """
        Parses the branch return results. Defaults to a pass through.

        :Parameters:
           - `data`: the data to parse.
        """
        return re.findall("\* ([^ ]*)\n", data)

    def get_branches(self, repo_path):
        """
        Get a list of branches.

        :Parameters:
           - `repo_path`: path on the file system to the repository.
        """
        out, err = self._execute("%s branch" % self.bin)
        error_info = err.read()
        if error_info:
            raise Exception(error_info)
        return self._branch_parser(out.read())


class Mercurial(SCM):
    """
    The Mercurial (hg) SCM.
    """

    def get_branches(self, repo_path):
        """
        Get a list of branches.

        :Parameters:
           - `repo_path`: path on the file system to the repository.
        """
        from mercurial import ui, hg
        a = hg.repository(ui.ui(), path=repo_path)
        return a.branchmap().keys()


class Repository(object):
    """
    An SCM agnostic repository class.
    """

    def __init__(self, name, location, clone_url, repo_class,
        repo_args=[], repo_kwargs={}):
        """
        Creates an instance of the repostory representation.

        :Parameters:
           - `name`: a nice name for the repository.
           - `location`: location on the filesystem of the repository.
           - `clone_url`: how to clone the repository.
           - `repo_class`: the class to use when getting data from the repo.
           - `repo_args`: non-keyword args to pass through to the repo class.
           - `repo_kwargs`: keword args to pass through to the repo class.
        """
        self.__name = name
        self.__location = location
        self.__repo_class = repo_class
        self.__obj = self.__repo_class(*repo_args, **repo_kwargs)

    def __repr__(self):
        """
        String representation of this instance.
        """
        return "<Repository %s: type='%s',class='%s'>" % (
            self.name, self.location, self.__repo_class.__name__)

    def _get_branches(self):
        """
        Gets all branches in this instance of a repository.
        """
        os.chdir(self.__location)
        return self.__obj.get_branches(self.__location)

    # read-only properties
    name = property(lambda s: s.__name)
    location = property(lambda s: s.__location)
    repo_class = property(lambda s: s.__repo_class)
    branches = property(lambda s: s._get_branches())


# Examples
g = Repository('pyclean', '/home/steve/Tech/pyclean/', 'http://stevemilner.org', Git, ['/usr/bin/git'])
print g.branches
m = Repository('winlibre', '/tmp/winlibre/', 'http://stevemilner.org', Mercurial)
print m.branches

 digg it   seed it   del.icio.us   ma.gnolia
Comments: 1 Tags:      


 
A Django joint.
© 2007-2009 Steve 'Ashcrow' Milner | Studio7designs | Arbutus Photography