From saces at freenetproject.org Fri Feb 8 20:00:28 2008 From: saces at freenetproject.org (saces at freenetproject.org) Date: Fri, 8 Feb 2008 20:00:28 +0000 (UTC) Subject: [Pyfreenet] r17716 - trunk/apps/pyFreenetHg Message-ID: <20080208200028.31BB447B312@freenetproject.org> Author: saces Date: 2008-02-08 20:00:28 +0000 (Fri, 08 Feb 2008) New Revision: 17716 Added: trunk/apps/pyFreenetHg/.project trunk/apps/pyFreenetHg/.pydevproject trunk/apps/pyFreenetHg/COPYING trunk/apps/pyFreenetHg/FreenetHg.py trunk/apps/pyFreenetHg/INSTALL trunk/apps/pyFreenetHg/ReadMe.html Log: pyFreenetHg - mercurial plugin for freenet support Added: trunk/apps/pyFreenetHg/.project =================================================================== --- trunk/apps/pyFreenetHg/.project (rev 0) +++ trunk/apps/pyFreenetHg/.project 2008-02-08 20:00:28 UTC (rev 17716) @@ -0,0 +1,17 @@ + + + pyFreenetHg + + + + + + org.python.pydev.PyDevBuilder + + + + + + org.python.pydev.pythonNature + + Added: trunk/apps/pyFreenetHg/.pydevproject =================================================================== --- trunk/apps/pyFreenetHg/.pydevproject (rev 0) +++ trunk/apps/pyFreenetHg/.pydevproject 2008-02-08 20:00:28 UTC (rev 17716) @@ -0,0 +1,9 @@ + + + + + +/pyFreenetHg + +python 2.5 + Added: trunk/apps/pyFreenetHg/COPYING =================================================================== --- trunk/apps/pyFreenetHg/COPYING (rev 0) +++ trunk/apps/pyFreenetHg/COPYING 2008-02-08 20:00:28 UTC (rev 17716) @@ -0,0 +1,14 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + 14 rue de Plaisance, 75014 Paris, France + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + Added: trunk/apps/pyFreenetHg/FreenetHg.py =================================================================== --- trunk/apps/pyFreenetHg/FreenetHg.py (rev 0) +++ trunk/apps/pyFreenetHg/FreenetHg.py 2008-02-08 20:00:28 UTC (rev 17716) @@ -0,0 +1,271 @@ +#!/usr/bin/env python + +# This program is free software. It comes without any warranty, to +# the extent permitted by applicable law. You can redistribute it +# and/or modify it under the terms of the Do What The Fuck You Want +# To Public License, Version 2, as published by Sam Hocevar. See +# http://sam.zoy.org/wtfpl/COPYING for more details. */ + + +import os, time +import tempfile +import sys +import dircache +import fcp + +from mercurial import hg +from mercurial import commands + +class myFCP(fcp.FCPNode): + + def putraw(self, id, rawcmd, async=False): + """ + Inserts a raw command. + This is intended for testing and development, not for common use + + Arguments: + - id - job id, must be the same as identifier in raw command (if any) + - rawcmd - data passed as is to the node + - async - whether to do the job asynchronously, returning a job ticket + object (default False) + """ + + opts = {} + opts['async'] = async + opts['rawcmd'] = rawcmd + + return self._submitCmd(id, "", **opts) + + def putraw2(self, id, rawcmd): + """ + mine ;) verbosity hacking + do not print the command + """ + + self.verbosity = fcp.INFO + ticket = self.putraw(id, rawcmd, True) + ticket.waitTillReqSent() + self.verbosity = fcp.DETAIL + return ticket.wait() + +class _static_composer: + """ + a helper class to compose the ClientPutComplexDir + """ + #@ @+others + #@+node:__init__ + def __init__(self, repo): + """ """ + + self._rootdir = repo.url()[5:] + '/.hg/' + self._index = 0; + self._fileitemlist = {} + self._databuff = '' + self._cmdbuff = '' + + a = dircache.listdir(self._rootdir) + + for s in a: + if s == 'hgrc': + pass # it may contains private/local config!! + elif s == 'store': + pass # store parsed later explizit + else: + self._addItem('', s) + + self._parseDir('store') + + def _parseDir(self, dir): + a = dircache.listdir(self._rootdir + dir) + dircache.annotate(self._rootdir + dir, a) + for s in a: + if s[-1:] == '/': + self._parseDir(dir + '/' + s[:-1]) + else: + self._addItem(dir, s) + + def _addItem(self, dir, filename): + """ """ + if dir != "": + dir = dir + '/' + + virtname = dir + filename + realname = self._rootdir + virtname + + f = open(realname) + content = f.read() + f.close() + + self._databuff = self._databuff + content; + idx = str(self._index) + + self._cmdbuff = self._cmdbuff + "Files."+idx+".Name=.hg/" + virtname + '\n' + self._cmdbuff = self._cmdbuff + "Files."+idx+".UploadFrom=direct" + '\n' + self._cmdbuff = self._cmdbuff + "Files."+idx+".Metadata.ContentType=text/plain" + '\n' + self._cmdbuff = self._cmdbuff + "Files."+idx+".DataLength=" + str(len(content)) + '\n' + + self._index = self._index + 1 + + def getCmd(self): + return self._cmdbuff + "Data\n" + + def getRawCmd(self): + return self._cmdbuff + "Data\n" + self._databuff + +# every command must take a ui and and repo as arguments. +# opts is a dict where you can find other command line flags +# +# Other parameters are taken in order from items on the command line that +# don't start with a dash. If no default value is given in the parameter list, +# they are required +def fcp_bundle(ui, repo, **opts): + # The doc string below will show up in hg help + """write bundle to CHK/USK + the bundel will be inserted as CHK@ if no uri is given + see hg help bundle for bundle options + """ + + # setup fcp stuff + # set server, port + + # make tempfile + tmpfd, tmpfname = tempfile.mkstemp('fcpbundle') + + #delete it, the bundle function don't like prexisting files + os.remove(tmpfname) + + #create bundle file, call the origin bundle funcrion + commands.bundle(ui, repo, tmpfname, **opts) + + #read the bundle + f = open(tmpfname, 'r+') + bundledata = f.read() + + #delete the tempfile again + os.remove(tmpfname) + + # now insert the data as chk (first step implementation) + #node = fcp.FCPNode(verbosity=fcp.DETAIL) + node = _make_node(**opts) + + insertresult = node.put(data=bundledata, priority=1, mimetype="mercurial/bundle"); + + node.shutdown(); + + print "bundle inserted: " + insertresult + + +def fcp_unbundle(ui, repo, node, **opts): + # The doc string below will show up in hg help + """unbundle from CHK/USK (not implemented jet)""" + #commands.unbundle(ui, repo, "Filename", **opts) + +def _make_node(**opts): + fcpopts = {} + fcpopts['verbosity'] = fcp.INFO + host = opts.get('fcphost', None) + if host: + fcpopts.put('host', host) + port = opts.get('fcpport', None) + if port: + fcpopts.put('port', port) + #return node2.FCPNode(**fcpopts) + return myFCP(**fcpopts) + +def fcp_makestatic(ui, repo, uri=None, **opts): + """put the repo into freenet for access via static-http + """ + + id = "freenethgid" + str(int(time.time() * 1000000)) + if uri == None: + uri="CHK@" + + cmd = "ClientPutComplexDir\n" + "URI=" + uri + "\nIdentifier=" + id + cmd = cmd + "\nVerbosity=-1\nPriorityClass=1\n" + + composer = _static_composer(repo) + + print "Debug: " + cmd + composer.getCmd() + + print "site composer done." + print "insert now. this may take a while..." + + node = _make_node(**opts) + + #testresult = node.putraw(id, cmd + composer.getRawCmd()) + testresult = node.putraw2(id, cmd + composer.getRawCmd()) + + node.shutdown(); + + print "success? " + testresult + +def fcp_createstatic(ui, repo, uri=None, **opts): + """put the repo into freenet for access via static-http, updatedable (not implemented jet) + """ + + #conf = repo.url()[5:] + '/.hg/fhc.rc' + #self.ui = ui + + #if os.path.exists(conf): + # print "Error: allready created" + # return + + #print conf + #uri = repo.config('freenethg', 'uri') + #if uri: + # print "ttttt " + uri + + # self.ui.readsections(cfg, 'usersubs', 'reposubs') + # self.repo = repo + # self.stripcount = int(self.ui.config('notify', 'strip', 0)) + # self.root = self.strip(self.repo.root) + # self.domain = self.ui.config('notify', 'domain') + # self.subs = self.subscribers() + + +def fcp_updatestatic(ui, repo, **opts): + """update the repo in freenet for access via static-http + """ + + print ui + print repo.url() + +def updatestatic_hook(ui, repo, hooktype, node=None, source=None, **kwargs): + """update static (not implemented jet)""" + + +remoteopts = [ + ('e', 'ssh', '', 'specify ssh command to use'), + ('', 'remotecmd', '', 'specify hg command to run on the remote side'), +] + +fcpopts = [ + ('', 'fcphost', None, 'specify fcphost if not 127.0.0.1'), + ('', 'fcpport', None, 'specify fcpport if not 9481'), +] + +cmdtable = { + # cmd name function call + "fcp-bundle": (fcp_bundle, + [('f', 'force', None, 'run even when remote repository is unrelated'), + ('r', 'rev', [], 'a changeset you would like to bundle'), + ('', 'base', [], 'a base changeset to specify instead of a destination'), + ('', 'uri', None, 'use insert uri generate chk'), + ]+ remoteopts + fcpopts, + 'hg fcp-bundle [--uri INSERTURI] [-f] [-r REV]... [--base REV]... [DEST]'), + "fcp-unbundle": (fcp_unbundle, + [('u', 'update', None, 'update to new tip if changesets were unbundled'), + ] + fcpopts, + 'hg fcp-unbundle [-u] FREENETKEY'), + "fcp-makestatic": (fcp_makestatic, + [('', 'uri', None, 'use insert uri instead generate chk') + ] + fcpopts, + 'hg fcp-makestatic [INSERTURI]'), + #"fcp-createstatic": (fcp_createstatic, + # [('a', 'auto', None, 'install update hook'), + # ] + fcpopts, + # 'hg fcp-createstatic'), + "fcp-updatestatic": (fcp_updatestatic, + [] + fcpopts, + 'hg fcp-updatestatic') +} Added: trunk/apps/pyFreenetHg/INSTALL =================================================================== --- trunk/apps/pyFreenetHg/INSTALL (rev 0) +++ trunk/apps/pyFreenetHg/INSTALL 2008-02-08 20:00:28 UTC (rev 17716) @@ -0,0 +1,38 @@ +INSTALL file for PyFreenetHg + +System requirements: + + This package requires: + + - Python2.3 or later + - pyFCP (http://downloads.freenetproject.org/alpha/pyFreenet/pyFreenet-latest.tbz) + - access to a freenet FCP port, on same or other machine + +Installation: + +download FreenetHg.py and put it somethere. + +add the following to your ~/.hgrc: + +[extensions] +hgk=/path/to/FreenetHg.py + +[freenethg] +config=/path/to/config.file + +--- + +the config file must exist, but can be emty (0 Bytes) +if its read only, you need to add the keys for the updater by yourself: + +[/path/to/repo] +inserturi=USK at bar +requesturi=USK at foo + +--- + +now run "hg help", it should show you new fcp-* commands. + +type "hg help commandname" for further details + +more about plugin install: http://www.selenic.com/mercurial/wiki/index.cgi/UsingExtensions \ No newline at end of file Added: trunk/apps/pyFreenetHg/ReadMe.html =================================================================== --- trunk/apps/pyFreenetHg/ReadMe.html (rev 0) +++ trunk/apps/pyFreenetHg/ReadMe.html 2008-02-08 20:00:28 UTC (rev 17716) @@ -0,0 +1,69 @@ + + + + +Freenet and mercurial + + +
+

Freenet & mercurial

+

 

+

licence

+

this document and pyFreenetHg is published under the strong WTFPL

+licence +

pyFreenetHg

+

+Mercurial is written in phyton and have a plugin system. so it should not be to much difficulty to get it +working with freenet.
+

+the basic idea: wrap around (selected) commands and use freenet as transport instead files
+     hg fcp-bundle   -> wraps around hg bundle and put a chk/usk instead a local file
+     hg fcp-unbundle -> wraps around hg unbundle and get it from a chk/usk instead a local file	
+     hg fcp-makestatic -> create a site thats accessible via static-http://127.0.0.1:8888/freenetkey
+     hg fcp-updatestatic -> update a site, see install/config
+
+

requirements

+

+python >= 2.3
+mercurial >= 0.9.x (for accessing pyFreenetHg's repository you need 0.9.3 or later)
+pyFCP
+last not least: a running freenet node ;) +

+

getting

+

download from here

+

hg clone|pull static-http://127.0.0.1:8888/USK at fQGiK~CfI8zO4cuNyhPRLqYZ5TyGUme8lMiRnS9TCaU,E3S1MLoeeeEM45fDLdVV~n8PCr9pt6GMq0tuH4dRP7c,AQACAAE/freenethg/1/ /tmp/your/local/path

+

install

+

read install instructions

+ +

download FreenetHg.py and put it somewhere.
+add the following to your ~/.hgrc: +

+
+[extensions]
+hgk=/path/to/FreenetHg.py
+
+[freenethg]
+config=/path/to/config.file
+
+

config

+

the configfile is needed if you want to make your repository accessible via static-http

+

the config file have the following syntax:

+
+[/path/to/repos]
+InsertURI=USK at foo/projectname/1
+RequestURI=USK at bar/projectname/1
+
+ +

adding hook for auto update (hgrc):

+
+[hooks]
+incoming = python:FreenetHq.updatestatic_hook
+commit = python:FreenetHq.updatestatic_hook
+
+

eclipse

+

modified MercurialEclipse plugin (vectrace, 0.1.102) to fire fcp-createstatic and fcp-updatestatic from within eclipse

+

use this key as eclipse update site or open it in your browser and download & install it manually.

+

http://127.0.0.1:8888/USK at MYLAnId-ZEyXhDGGbYOa1gOtkZZrFNTXjFl1dibLj9E,Xpu27DoAKKc8b0718E-ZteFrGqCYROe7XBBJI57pB4M,AQACAAE/EclipseUpdateSite/1/

+
+ + From saces at freenetproject.org Fri Feb 8 20:08:15 2008 From: saces at freenetproject.org (saces at freenetproject.org) Date: Fri, 8 Feb 2008 20:08:15 +0000 (UTC) Subject: [Pyfreenet] r17717 - trunk/apps/pyFreenetHg Message-ID: <20080208200815.DCC3428015A@freenetproject.org> Author: saces Date: 2008-02-08 20:08:15 +0000 (Fri, 08 Feb 2008) New Revision: 17717 Modified: trunk/apps/pyFreenetHg/ Log: set ignore ".hg" Property changes on: trunk/apps/pyFreenetHg ___________________________________________________________________ Name: svn:ignore + .hg