comparison upmana/mercurial/statichttprepo.py @ 121:496dbf12a6cb alpha

Traipse Alpha 'OpenRPG' {091030-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Cleaning up for Beta): Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code. Fix to remote admin commands Minor fix to texted based server, works in /System/ folder Some Core changes to gametree to correctly disply Pretty Print, thanks David! Fix to Splitter Nodes not being created. Added images to Plugin Control panel for Autostart feature Fix to massive amounts of images loading; from Core fix to gsclient so with_statement imports Added 'boot' command to remote admin Prep work in Pass tool for remote admin rankings and different passwords, ei, Server, Admin, Moderator, etc. Remote Admin Commands more organized, more prep work. Added Confirmation window for sent nodes. Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without breaking) {091028} Made changes to gametree to start working with Element Tree, mostly from Core Minor changes to Map to start working with Element Tree, from Core Preliminary changes to map efficiency, from FlexiRPG Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Changes to main.py to start working with Element Tree {091029} Changes made to server to start working with Element Tree. Changes made to Meta Server Lib. Prepping test work for a multi meta network page. Minor bug fixed with mini to gametree Zoom Mouse plugin added. {091030} Getting ready for Beta. Server needs debugging so Alpha remains bugged. Plugin UI code cleaned. Auto start works with a graphic, pop-up asks to enable or disable plugin. Update Manager now has a partially working Status Bar. Status Bar captures terminal text, so Merc out put is visible. Manifest.xml file, will be renamed, is now much cleaner. Debug Console has a clear button and a Report Bug button. Prep work for a Term2Win class in Debug Console. Known: Current Alpha fails in Windows.
author sirebral
date Fri, 30 Oct 2009 22:21:40 -0500
parents
children
comparison
equal deleted inserted replaced
120:d86e762a994f 121:496dbf12a6cb
1 # statichttprepo.py - simple http repository class for mercurial
2 #
3 # This provides read-only repo access to repositories exported via static http
4 #
5 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
6 #
7 # This software may be used and distributed according to the terms of the
8 # GNU General Public License version 2, incorporated herein by reference.
9
10 from i18n import _
11 import changelog, byterange, url, error
12 import localrepo, manifest, util, store
13 import urllib, urllib2, errno
14
15 class httprangereader(object):
16 def __init__(self, url, opener):
17 # we assume opener has HTTPRangeHandler
18 self.url = url
19 self.pos = 0
20 self.opener = opener
21 def seek(self, pos):
22 self.pos = pos
23 def read(self, bytes=None):
24 req = urllib2.Request(self.url)
25 end = ''
26 if bytes:
27 end = self.pos + bytes - 1
28 req.add_header('Range', 'bytes=%d-%s' % (self.pos, end))
29
30 try:
31 f = self.opener.open(req)
32 data = f.read()
33 if hasattr(f, 'getcode'):
34 # python 2.6+
35 code = f.getcode()
36 elif hasattr(f, 'code'):
37 # undocumented attribute, seems to be set in 2.4 and 2.5
38 code = f.code
39 else:
40 # Don't know how to check, hope for the best.
41 code = 206
42 except urllib2.HTTPError, inst:
43 num = inst.code == 404 and errno.ENOENT or None
44 raise IOError(num, inst)
45 except urllib2.URLError, inst:
46 raise IOError(None, inst.reason[1])
47
48 if code == 200:
49 # HTTPRangeHandler does nothing if remote does not support
50 # Range headers and returns the full entity. Let's slice it.
51 if bytes:
52 data = data[self.pos:self.pos + bytes]
53 else:
54 data = data[self.pos:]
55 elif bytes:
56 data = data[:bytes]
57 self.pos += len(data)
58 return data
59
60 def build_opener(ui, authinfo):
61 # urllib cannot handle URLs with embedded user or passwd
62 urlopener = url.opener(ui, authinfo)
63 urlopener.add_handler(byterange.HTTPRangeHandler())
64
65 def opener(base):
66 """return a function that opens files over http"""
67 p = base
68 def o(path, mode="r"):
69 f = "/".join((p, urllib.quote(path)))
70 return httprangereader(f, urlopener)
71 return o
72
73 return opener
74
75 class statichttprepository(localrepo.localrepository):
76 def __init__(self, ui, path):
77 self._url = path
78 self.ui = ui
79
80 self.path, authinfo = url.getauthinfo(path.rstrip('/') + "/.hg")
81
82 opener = build_opener(ui, authinfo)
83 self.opener = opener(self.path)
84
85 # find requirements
86 try:
87 requirements = self.opener("requires").read().splitlines()
88 except IOError, inst:
89 if inst.errno != errno.ENOENT:
90 raise
91 # check if it is a non-empty old-style repository
92 try:
93 self.opener("00changelog.i").read(1)
94 except IOError, inst:
95 if inst.errno != errno.ENOENT:
96 raise
97 # we do not care about empty old-style repositories here
98 msg = _("'%s' does not appear to be an hg repository") % path
99 raise error.RepoError(msg)
100 requirements = []
101
102 # check them
103 for r in requirements:
104 if r not in self.supported:
105 raise error.RepoError(_("requirement '%s' not supported") % r)
106
107 # setup store
108 def pjoin(a, b):
109 return a + '/' + b
110 self.store = store.store(requirements, self.path, opener, pjoin)
111 self.spath = self.store.path
112 self.sopener = self.store.opener
113 self.sjoin = self.store.join
114
115 self.manifest = manifest.manifest(self.sopener)
116 self.changelog = changelog.changelog(self.sopener)
117 self.tagscache = None
118 self.nodetagscache = None
119 self.encodepats = None
120 self.decodepats = None
121
122 def url(self):
123 return self._url
124
125 def local(self):
126 return False
127
128 def lock(self, wait=True):
129 raise util.Abort(_('cannot lock static-http repository'))
130
131 def instance(ui, path, create):
132 if create:
133 raise util.Abort(_('cannot create new static-http repository'))
134 return statichttprepository(ui, path[7:])