Kiln » Kiln Extensions
Clone URL:  
Pushed to 2 repositories · View In Graph Contained in tip

Kiln 2.8.30 extensions (bug fixes)

Changeset 105bd3eb46a4

Parent 0b1d58ee5c34

by Profile picture of User 276Kevin Gessner <kevin@fogcreek.com>

Changes to 4 files · Browse files at 105bd3eb46a4 Showing diff from parent 0b1d58ee5c34 Diff from another changeset...

Change 1 of 4 Show Entire File gestalt.py Stacked
 
1
 
2
3
4
 
9
10
11
12
 
13
14
15
 
85
86
87
88
 
89
90
91
 
92
93
94
95
 
96
97
 
98
99
100
 
176
177
178
179
180
181
182
 
 
1
2
3
4
 
9
10
11
 
12
13
14
15
 
85
86
87
 
88
89
90
 
91
92
93
94
 
95
96
 
97
98
99
100
 
176
177
178
 
179
180
181
@@ -1,4 +1,4 @@
-# Copyright (C) 2009-2011 Fog Creek Software. All rights reserved. +# Copyright (C) 2009-2012 Fog Creek Software. All rights reserved.  #  # To enable the "gestalt" extension put these lines in your ~/.hgrc:  # [extensions] @@ -9,7 +9,7 @@
 #  # This program is free software; you can redistribute it and/or modify  # it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or +# the Free Software Foundation; either version 3 of the License, or  # (at your option) any later version.  #  # This program is distributed in the hope that it will be useful, @@ -85,16 +85,16 @@
  1.5 redefined parseurl()'s return values, and 1.6 split up the   branches parameter into a two-tuple.   ''' - url, branches = hg.parseurl(source, None)[:2] + uri, branches = hg.parseurl(source, None)[:2]   if _HG_VERSION >= (1, 6, 0):   # branches will be None because we passed None into - # parseurl(), so we can ignore that safely. + # parseuri(), so we can ignore that safely.   hashbranch, branches = branches   else:   # branches will contain one element or fewer because we passed - # None into parseurl(). + # None into parseuri().   hashbranch = branches and branches[0] or None - return url, hashbranch + return uri, hashbranch    def addbranchrevs(lrepo, repo, hashbranch):   '''wrap hg.addbranchrevs to work on 1.5 and 1.6 and returns the @@ -176,7 +176,6 @@
 '''))   return True   - target = ui.config('paths', 'default-push') and ui.expandpath('default-push') or source   source, hashbranch = parseurl(source)   other = hg.repository(remoteui(repo, opts), source)   revs = addbranchrevs(repo, other, hashbranch)
Change 1 of 5 Show Entire File kiln.py Stacked
 
40
41
42
 
43
44
45
 
573
574
575
576
 
577
578
579
 
612
613
614
615
 
616
617
618
619
620
 
 
 
 
621
 
 
 
622
623
624
 
731
732
733
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
734
735
736
 
760
761
762
763
764
765
766
767
768
769
770
 
 
 
 
 
 
 
 
 
 
 
 
 
 
771
772
773
 
40
41
42
43
44
45
46
 
574
575
576
 
577
578
579
580
 
613
614
615
 
616
617
618
619
620
 
621
622
623
624
625
626
627
628
629
630
631
 
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
 
793
794
795
 
 
 
 
 
 
 
 
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
@@ -40,6 +40,7 @@
 pushing to Kiln. See :hg:`help push` and  http://kiln.stackexchange.com/questions/4679/ for more information.  ''' +import itertools  import os  import re  import unicodedata @@ -573,7 +574,7 @@
  return call_api(repo.ui, baseurl, 'Api/1.0/Repo/Create', params, post=True)   except APIError, e:   if 'RepoNameAlreadyUsed' in e.errors: - repo.ui.write_err(_('error: a repo with this name already exists: %s\n') % name) + repo.ui.warn(_('error: kiln: a repo with this name already exists: %s\n') % name)   return   raise   @@ -612,13 +613,19 @@
  reviewers.append(name_to_ix[reviewer])   print_list(ui, [ix_to_name[r] for r in reviewers], 'reviewers:')   -def review(ui, repo, pats, opts): +def review(ui, repo, dest, opts):   '''Associates the pushed changesets with a new or existing Kiln review.'''   if not opts['review'] or not repo.ui.config('kiln', 'node'):   return   - url = repo.ui.expandpath(pats[0] if pats else 'default-push', default='default') + url = repo.ui.expandpath(dest if dest else 'default-push') + if url == 'default-push': + raise util.Abort(_('kiln: please specify a default-push path before using --review')) +   baseurl = get_api_url(url) + if baseurl == url: + ui.write_err(_('kiln: warning: this does not appear to be a Kiln URL: %s\n') % baseurl) +   token = get_token(ui, baseurl)   kiln_repo = get_repo_record(repo, url, token)   @@ -731,6 +738,32 @@
  '''   return opts['path'] != dest and dest or None   +def _standin_expand(paths): + '''given a sequence of filenames, returns a set of filenames -- + relative to the current working directory! -- prefixed with all + possible standin prefixes e.g. .hglf or .kbf in addition to the + originals''' + paths = [os.path.relpath(os.path.abspath(p), os.getcwd()) for p in paths] + choices = [[p, os.path.join('.kbf', p), os.path.join('.hglf', p)] for p in paths] + return set(itertools.chain(*choices)) + +def _filename_match(repo, ctx, paths): + '''returns a set of filenames contained in both paths and the + ctx's manifest, accounting for standins''' + try: + match = scmutil.match(ctx, paths) + match.bad = lambda *a: None + paths = set(ctx.walk(match)) + return paths + except ImportError: + # Make every path normalized and relative to the current + # working directory, similar to scmutil. + needles = set(map(os.path.normpath, paths)) + haystacks = [os.path.relpath(os.path.join(repo.root, p), os.getcwd()) + for p in ctx.manifest().iterkeys()] + haystacks = set(map(os.path.normpath, haystacks)) + return needles.intersection(haystacks) +  def kiln(ui, repo, **opts):   '''show the relevant page of the repository in Kiln   @@ -760,14 +793,20 @@
  default = True     def files(key): - allpaths = [] - for f in opts[key]: - paths = [path for path in repo['.'].manifest().iterkeys() if re.search(match._globre(f) + '$', path)] - paths = [re.sub(r'^\.kbf', '', path) for path in paths] - if not paths: - ui.warn(_('cannot find %s') % f) - allpaths += paths - return allpaths + paths = _filename_match(repo, repo['.'], _standin_expand(opts[key])) + if not paths: + ui.warn(_('error: kiln: cannot find any paths matching %s\n') % ', '.join(opts[key])) + if len(paths) > 5: + # If we're passed a directory, we should technically open + # a tab for each file in that directory because that's how + # other hg commands e.g. cat work. However, since that's + # quite annoying to do by accident when opening browsers, + # let's prompt. (This is only relevant when scmutil + # exists.) + char = ui.prompt(_('about to open %d browser tabs or windows, abort? [Yn]') % len(paths)).lower() + if char != 'n': + raise SystemExit(0) + return paths     if opts['rev']:   default = False
Change 1 of 3 Show Changes Only kilnauth.py Stacked
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
 
 
 
 
 
 
121
122
123
124
125
126
 
 
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
 
 
 
 
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
 
93
94
 
 
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 
118
119
120
121
122
123
124
125
126
127
 
 
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
 
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
 # Copyright (C) 2009-2011 Fog Creek Software. All rights reserved.  #  # To enable the "kilnauth" extension put these lines in your ~/.hgrc:  # [extensions]  # kilnauth = /path/to/kilnauth.py  #  # For help on the usage of kilnauth use:  # hg help kilnauth  #  # This program is free software; you can redistribute it and/or modify  # it under the terms of the GNU General Public License as published by  # the Free Software Foundation; either version 2 of the License, or  # (at your option) any later version.  #  # This program is distributed in the hope that it will be useful,  # but WITHOUT ANY WARRANTY; without even the implied warranty of  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the  # GNU General Public License for more details.  #  # You should have received a copy of the GNU General Public License  # along with this program; if not, write to the Free Software  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.    '''stores authentication cookies for HTTP repositories    This extension knows how to capture Kiln authentication tokens when pushing  over HTTP. This means you only need to enter your login and password once;  after that, the FogBugz token will be stored in your home directory, allowing  pushing without a password.    If you ever need to logout of Kiln, simply run ``hg logout''  '''    from cookielib import MozillaCookieJar, Cookie  from urllib2 import Request  import os  import re  import shutil  import stat  import sys  import tempfile    try:   from hashlib import md5  except:   # Python 2.4   import md5    try:   WindowsError  except NameError:   WindowsError = None    from mercurial.i18n import _  import mercurial.url  from mercurial import commands    current_user = None    class CookieJar(MozillaCookieJar, object):   def __init__(self, filename, *args, **kwargs):   self.__original_path = filename   tf = tempfile.NamedTemporaryFile(delete=False)   self.__temporary_path = tf.name   tf.close()   if os.path.exists(filename):   shutil.copyfile(filename, self.__temporary_path)   return super(CookieJar, self).__init__(self.__temporary_path, *args, **kwargs)     def __enter__(self):   pass     def __exit__(self, exc_type, exc_value, traceback):   os.unlink(self.__temporary_path)   self.__temporary_path = None     def __del__(self):   try:   if self.__temporary_path:   os.unlink(self.__temporary_path)   except (OSError, IOError):   pass     def save(self, *args, **kwargs):   with open(self.__temporary_path, 'rb') as f:   before = md5(f.read()).digest()   super(CookieJar, self).save(*args, **kwargs)   with open(self.__temporary_path, 'rb') as f:   after = md5(f.read()).digest()   if before != after:   try:   os.rename(self.__temporary_path, self.__original_path) - except WindowsError: + except (IOError, OSError, WindowsError):   shutil.copyfile(self.__temporary_path, self.__original_path) - except (IOError, OSError): - pass    def get_cookiejar(ui):   global current_user   if os.name == 'nt':   cookie_path = os.path.expanduser('~\\_hgcookies')   else:   cookie_path = os.path.expanduser('~/.hgcookies')     if not os.path.isdir(cookie_path):   if os.path.exists(cookie_path):   os.remove(cookie_path)   os.mkdir(cookie_path)   if os.name == 'posix':   os.chmod(cookie_path, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)     cookie_path = os.path.join(cookie_path, md5(current_user).hexdigest())   # Cygwin's Python does not always expanduser() properly...   if re.match(r'^[A-Za-z]:', cookie_path) is not None and re.match(r'[A-Za-z]:\\', cookie_path) is None:   cookie_path = re.sub(r'([A-Za-z]):', r'\1:\\', cookie_path)     try:   cj = CookieJar(cookie_path)   if not os.path.exists(cookie_path): - cj.save() + try: + cj.save() + except Exception, e: + ui.warn(_('unable to save cookies: %s') % str(e)) + # save() destroys the tempfile; get a new one + cj = CookieJar(cookie_path)   if os.name == 'posix':   os.chmod(cookie_path, stat.S_IREAD | stat.S_IWRITE)   cj.load(ignore_discard=True, ignore_expires=True)   return cj - except IOError: - ui.warn(_('Cookie file %s exists, but could not be opened.\nContinuing without cookie authentication.\n') % cookie_path) + except IOError, e: + ui.warn(_('Cookie file %s exists, but could not be opened (%s).\nContinuing without cookie authentication.\n') % (cookie_path, e))   return MozillaCookieJar(tempfile.NamedTemporaryFile().name)    def make_cookie(request, name, value):   domain = request.get_host()   port = None   if ':' in domain:   domain, port = domain.split(':', 1)   if '.' not in domain:   domain += ".local"   return Cookie(version=0,   name=name, value=value,   port=port, port_specified=False,   domain=domain, domain_specified=False, domain_initial_dot=False,   path='/', path_specified=False, secure=False,   expires=None, discard=False,   comment=None, comment_url=None,   rest={})    def get_username(url):   url = re.sub(r'https?://', '', url)   url = re.sub(r'/.*', '', url)   if '@' in url:   # There should be some login info   # rfind in case it's an email address   username = url[:url.rfind('@')]   if ':' in username:   username = url[:url.find(':')]   return username   # Didn't find anything...   return ''    def get_dest(ui):   from mercurial.dispatch import _parse   try:   cmd_info = _parse(ui, sys.argv[1:])   cmd = cmd_info[0]   dest = cmd_info[2]   if dest:   dest = dest[0]   elif cmd in ['outgoing', 'push']:   dest = 'default-push'   else:   dest = 'default'   except:   dest = 'default'   return ui.expandpath(dest)    def reposetup(ui, repo):   global current_user   if repo.local():   try:   current_user = get_username(get_dest(ui))   except:   current_user = ''    def extsetup():   global current_user   ui = mercurial.ui.ui()   current_user = get_username(get_dest(ui))     def open_wrapper(func):   def open(*args, **kwargs):   if isinstance(args[0], Request):   request = args[0]   cj = get_cookiejar(ui)   cj.set_cookie(make_cookie(args[0], 'fSetNewFogBugzAuthCookie', '1'))   cj.add_cookie_header(request)   response = func(*args, **kwargs)   cj.extract_cookies(response, args[0]) - cj.save(ignore_discard=True, ignore_expires=True) + try: + cj.save(ignore_discard=True, ignore_expires=True) + except Exception, e: + ui.warn(_('unable to save cookies: %s') % str(e))   else:   response = func(*args, **kwargs)   return response   return open     old_opener = mercurial.url.opener   def opener(*args, **kwargs):   urlopener = old_opener(*args, **kwargs)   urlopener.open = open_wrapper(urlopener.open)   return urlopener   mercurial.url.opener = opener    def logout(ui, domain=None):   """log out of http repositories     Clears the cookies stored for HTTP repositories. If [domain] is   specified, only that domain will be logged out. Otherwise,   all domains will be logged out.   """     cj = get_cookiejar(ui)   try:   cj.clear(domain=domain)   cj.save()   except KeyError:   ui.write("Not logged in to '%s'\n" % (domain,))    commands.norepo += ' logout'    cmdtable = {   'logout': (logout, [], '[domain]')  }
Change 1 of 1 Show Entire File setup.py Stacked
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
 
 
 
 
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
 
 
 
 
 
 
36
37
38
39
40
41
 
 
42
43
44
45
46
47
 
 
 
 
 
 
 
 
 
 
 
48
49
50
 
51
 
2
3
4
 
 
 
 
5
6
7
 
 
 
 
 
 
 
 
 
 
8
9
10
11
12
13
 
 
 
 
 
 
 
 
 
 
 
 
 
14
15
16
17
18
19
20
21
22
 
 
 
 
23
24
25
26
 
 
 
 
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@@ -2,50 +2,41 @@
 import os  import zipfile   -folders = ['bfiles', '_custom'] -extensions = ['.py'] -excludes = ['setup.py'] -  def compile_extensions():   compileall.compile_dir(os.path.dirname(__file__), force=1)   -def check_item(item): - for exclude in excludes: - if item[1].endswith(exclude): - return False - if item[1] in folders: - return True - for extension in extensions: - if item[1].endswith(extension): - return True - return False +def walk(dir_root): + for dirpath, dirnames, filenames in os.walk(dir_root): + dirnames_set = set(dirnames) + if 'tests' in dirnames_set: + dirnames.remove('tests')   -def list_files(dir_root, zip_root): - subdirs = [] - items = [] - for item in os.listdir(dir_root): - path = os.path.join(dir_root, item) - zip_path = os.path.join(zip_root, item) - if os.path.isfile(path): - items.append([path, zip_path]) - else: - subdirs.append([path, zip_path]) - for subdir in subdirs: - items.extend(list_files(subdir[0], subdir[1])) - return [f for f in items if check_item(f)] + for filename in filenames: + ignore, ext = os.path.splitext(filename) + if filename == 'setup.py': + continue + if ext not in ('.py', '.pyc'): + continue + yield os.path.join(dirpath, filename)    def build_release(): - compile_extensions() - dir = os.path.dirname(__file__) - absdir = os.path.abspath(dir) - files = list_files(absdir, '.') + absdir = os.path.abspath(os.path.dirname(__file__)) + target = os.path.join(absdir, 'kiln_extensions.zip')     print 'Creating ZIP archive...' - zip = zipfile.ZipFile(os.path.join(absdir, 'kiln_extensions.zip'), 'w') - for file in files: - zip.write(file[0], file[1]) - zip.close() + f = None + try: + f = zipfile.ZipFile(target, 'w') + for filename in walk(absdir): + zip_filename = os.path.join( + 'kiln_extensions', + os.path.relpath(filename, absdir)) + print ' %s' % zip_filename + f.write(filename, zip_filename) + finally: + if f: f.close()   print 'Success!'    if __name__ == '__main__': + compile_extensions()   build_release()