You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2014/01/10 22:23:08 UTC
[12/36] PEP8 cleanup
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeDiscussion/forgediscussion/widgets/forum_widgets.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/widgets/forum_widgets.py b/ForgeDiscussion/forgediscussion/widgets/forum_widgets.py
index 1b04323..7e9debb 100644
--- a/ForgeDiscussion/forgediscussion/widgets/forum_widgets.py
+++ b/ForgeDiscussion/forgediscussion/widgets/forum_widgets.py
@@ -29,131 +29,158 @@ from allura.lib.widgets.subscriptions import SubscribeForm
from forgediscussion import model as M
+
class _ForumSummary(ew_core.Widget):
- template='jinja:forgediscussion:templates/discussion_widgets/forum_summary.html'
- defaults=dict(
+ template = 'jinja:forgediscussion:templates/discussion_widgets/forum_summary.html'
+ defaults = dict(
ew_core.Widget.defaults,
name=None,
value=None,
show_label=True,
label=None)
+
class _ForumsTable(ew.TableField):
+
class fields(ew_core.NameList):
- _id=ew.HiddenField(validator=V.Ming(M.ForumThread))
- num_topics=ffw.DisplayOnlyField(show_label=True, label='Topics')
- num_posts=ffw.DisplayOnlyField(show_label=True, label='Posts')
- last_post=ffw.DisplayOnlyField(show_label=True)
- subscribed=ew.Checkbox(suppress_label=True, show_label=True)
+ _id = ew.HiddenField(validator=V.Ming(M.ForumThread))
+ num_topics = ffw.DisplayOnlyField(show_label=True, label='Topics')
+ num_posts = ffw.DisplayOnlyField(show_label=True, label='Posts')
+ last_post = ffw.DisplayOnlyField(show_label=True)
+ subscribed = ew.Checkbox(suppress_label=True, show_label=True)
fields.insert(0, _ForumSummary())
+
class ForumSubscriptionForm(CsrfForm):
+
class fields(ew_core.NameList):
- forums=_ForumsTable()
- page_list=ffw.PageList()
- submit_text='Update Subscriptions'
+ forums = _ForumsTable()
+ page_list = ffw.PageList()
+ submit_text = 'Update Subscriptions'
+
class _ThreadsTable(DW._ThreadsTable):
+
class fields(ew_core.NameList):
- _id=ew.HiddenField(validator=V.Ming(M.ForumThread))
- subject=ffw.DisplayOnlyField(show_label=True, label='Subject')
- url=ffw.DisplayOnlyField()
- num_replies=ffw.DisplayOnlyField(show_label=True, label='Num Replies')
- num_views=ffw.DisplayOnlyField(show_label=True)
- flags=ffw.DisplayOnlyField(show_label=True)
- last_post=ffw.DisplayOnlyField(show_label=True)
- subscription=ew.Checkbox(suppress_label=True, show_label=True)
- defaults=dict(DW._ThreadsTable.defaults, div_id='forum_threads')
+ _id = ew.HiddenField(validator=V.Ming(M.ForumThread))
+ subject = ffw.DisplayOnlyField(show_label=True, label='Subject')
+ url = ffw.DisplayOnlyField()
+ num_replies = ffw.DisplayOnlyField(
+ show_label=True, label='Num Replies')
+ num_views = ffw.DisplayOnlyField(show_label=True)
+ flags = ffw.DisplayOnlyField(show_label=True)
+ last_post = ffw.DisplayOnlyField(show_label=True)
+ subscription = ew.Checkbox(suppress_label=True, show_label=True)
+ defaults = dict(DW._ThreadsTable.defaults, div_id='forum_threads')
+
class ThreadSubscriptionForm(DW.SubscriptionForm):
+
class fields(ew_core.NameList):
- threads=_ThreadsTable()
- page_list=ffw.PageList()
- page_size=ffw.PageSize()
+ threads = _ThreadsTable()
+ page_list = ffw.PageList()
+ page_size = ffw.PageSize()
+
class AnnouncementsTable(DW._ThreadsTable):
+
class fields(ew_core.NameList):
- _id=ew.HiddenField(validator=V.Ming(M.ForumThread))
- subject=ffw.DisplayOnlyField(show_label=True, label='Subject')
- url=ffw.DisplayOnlyField()
- num_replies=ffw.DisplayOnlyField(show_label=True, label='Num Replies')
- num_views=ffw.DisplayOnlyField(show_label=True)
- flags=ffw.DisplayOnlyField(show_label=True)
- last_post=ffw.DisplayOnlyField(show_label=True)
- defaults=dict(DW._ThreadsTable.defaults, div_id='announcements')
- name='announcements'
+ _id = ew.HiddenField(validator=V.Ming(M.ForumThread))
+ subject = ffw.DisplayOnlyField(show_label=True, label='Subject')
+ url = ffw.DisplayOnlyField()
+ num_replies = ffw.DisplayOnlyField(
+ show_label=True, label='Num Replies')
+ num_views = ffw.DisplayOnlyField(show_label=True)
+ flags = ffw.DisplayOnlyField(show_label=True)
+ last_post = ffw.DisplayOnlyField(show_label=True)
+ defaults = dict(DW._ThreadsTable.defaults, div_id='announcements')
+ name = 'announcements'
+
class _ForumSelector(ew.SingleSelectField):
+
def options(self):
return [
ew.Option(label=f.name, py_value=f, html_value=f.shortname)
- for f in c.app.forums ]
+ for f in c.app.forums]
+
def to_python(self, value, state):
- result = M.Forum.query.get(shortname=value, app_config_id=c.app.config._id)
+ result = M.Forum.query.get(
+ shortname=value, app_config_id=c.app.config._id)
if not result:
- raise fev.Invalid('Illegal forum shortname: %s' % value, value, state)
+ raise fev.Invalid('Illegal forum shortname: %s' %
+ value, value, state)
return result
+
def from_python(self, value, state):
return value.shortname
+
class ModerateThread(CsrfForm):
- submit_text='Save Changes'
+ submit_text = 'Save Changes'
+
class fields(ew_core.NameList):
- discussion=_ForumSelector(label='New Forum')
- flags=ew.CheckboxSet(options=['Sticky', 'Announcement'])
+ discussion = _ForumSelector(label='New Forum')
+ flags = ew.CheckboxSet(options=['Sticky', 'Announcement'])
class buttons(ew_core.NameList):
- delete=ew.SubmitButton(label='Delete Thread')
+ delete = ew.SubmitButton(label='Delete Thread')
class ModeratePost(CsrfForm):
- submit_text=None
- fields=[
+ submit_text = None
+ fields = [
ew.FieldSet(legend='Promote post to its own thread', fields=[
- ew.TextField(name='subject', label='Thread title'),
- ew.SubmitButton(name='promote', label='Promote to thread')])]
+ ew.TextField(name='subject', label='Thread title'),
+ ew.SubmitButton(name='promote', label='Promote to thread')])]
+
class PromoteToThread(CsrfForm):
- submit_text=None
- fields=[
+ submit_text = None
+ fields = [
ew.TextField(name='subject', label='Thread title'),
ew.SubmitButton(name='promote', label='Promote to thread')]
+
class ForumHeader(DW.DiscussionHeader):
- template='jinja:forgediscussion:templates/discussion_widgets/forum_header.html'
- widgets=dict(DW.DiscussionHeader.widgets,
- announcements_table=AnnouncementsTable(),
- forum_subscription_form=ForumSubscriptionForm())
+ template = 'jinja:forgediscussion:templates/discussion_widgets/forum_header.html'
+ widgets = dict(DW.DiscussionHeader.widgets,
+ announcements_table=AnnouncementsTable(),
+ forum_subscription_form=ForumSubscriptionForm())
+
class ThreadHeader(DW.ThreadHeader):
- template='jinja:forgediscussion:templates/discussion_widgets/thread_header.html'
- defaults=dict(DW.ThreadHeader.defaults,
- show_subject=True,
- show_moderate=True)
- widgets=dict(DW.ThreadHeader.widgets,
- moderate_thread=ModerateThread(),
- announcements_table=AnnouncementsTable())
+ template = 'jinja:forgediscussion:templates/discussion_widgets/thread_header.html'
+ defaults = dict(DW.ThreadHeader.defaults,
+ show_subject=True,
+ show_moderate=True)
+ widgets = dict(DW.ThreadHeader.widgets,
+ moderate_thread=ModerateThread(),
+ announcements_table=AnnouncementsTable())
+
class Post(DW.Post):
- show_subject=False
- widgets=dict(DW.Post.widgets,
- promote_to_thread=PromoteToThread())
+ show_subject = False
+ widgets = dict(DW.Post.widgets,
+ promote_to_thread=PromoteToThread())
+
class Thread(DW.Thread):
- defaults=dict(
+ defaults = dict(
DW.Thread.defaults,
show_subject=False)
- widgets=dict(DW.Thread.widgets,
- thread_header=ThreadHeader(),
- post=Post())
+ widgets = dict(DW.Thread.widgets,
+ thread_header=ThreadHeader(),
+ post=Post())
+
class Forum(DW.Discussion):
- template='jinja:forgediscussion:templates/discussion_widgets/discussion.html'
- allow_create_thread=True
+ template = 'jinja:forgediscussion:templates/discussion_widgets/discussion.html'
+ allow_create_thread = True
show_subject = True
- widgets=dict(DW.Discussion.widgets,
- discussion_header=ForumHeader(),
- forum_subscription_form=ForumSubscriptionForm(),
- whole_forum_subscription_form=SubscribeForm(),
- subscription_form=ThreadSubscriptionForm()
- )
+ widgets = dict(DW.Discussion.widgets,
+ discussion_header=ForumHeader(),
+ forum_subscription_form=ForumSubscriptionForm(),
+ whole_forum_subscription_form=SubscribeForm(),
+ subscription_form=ThreadSubscriptionForm()
+ )
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeDiscussion/setup.py
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/setup.py b/ForgeDiscussion/setup.py
index 812c8a0..c978edd 100644
--- a/ForgeDiscussion/setup.py
+++ b/ForgeDiscussion/setup.py
@@ -16,7 +16,8 @@
# under the License.
from setuptools import setup, find_packages
-import sys, os
+import sys
+import os
from forgediscussion.version import __version__
@@ -25,7 +26,8 @@ setup(name='ForgeDiscussion',
description="",
long_description="""\
""",
- classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+ # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+ classifiers=[],
keywords='',
author='',
author_email='',
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeGit/forgegit/git_main.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/git_main.py b/ForgeGit/forgegit/git_main.py
index 1d11e41..fda6914 100644
--- a/ForgeGit/forgegit/git_main.py
+++ b/ForgeGit/forgegit/git_main.py
@@ -42,17 +42,19 @@ from .controllers import BranchBrowser
log = logging.getLogger(__name__)
+
class ForgeGitApp(RepositoryApp):
+
'''This is the Git app for PyForge'''
__version__ = version.__version__
- tool_label='Git'
- tool_description="""
+ tool_label = 'Git'
+ tool_description = """
Git is a distributed version control system designed to
handle everything from small to very large projects with speed
and efficiency.
"""
- ordinal=2
- forkable=True
+ ordinal = 2
+ forkable = True
def __init__(self, project, config):
super(ForgeGitApp, self).__init__(project, config)
@@ -68,7 +70,8 @@ class ForgeGitApp(RepositoryApp):
@property
def default_branch_name(self):
- default_branch_name = getattr(self.repo, 'default_branch_name', 'master')
+ default_branch_name = getattr(
+ self.repo, 'default_branch_name', 'master')
if not default_branch_name:
default_branch_name = 'master'
return default_branch_name
@@ -76,9 +79,10 @@ class ForgeGitApp(RepositoryApp):
def admin_menu(self):
links = []
links.append(SitemapEntry(
- 'Set default branch',
- c.project.url()+'admin/'+self.config.options.mount_point+'/' + 'set_default_branch_name',
- className='admin_modal'))
+ 'Set default branch',
+ c.project.url() + 'admin/' + self.config.options.mount_point +
+ '/' + 'set_default_branch_name',
+ className='admin_modal'))
links += super(ForgeGitApp, self).admin_menu()
return links
@@ -91,7 +95,8 @@ class ForgeGitApp(RepositoryApp):
status='initializing',
fs_path=self.config.options.get('fs_path'))
ThreadLocalORMSession.flush_all()
- cloned_from_project_id = self.config.options.get('cloned_from_project_id')
+ cloned_from_project_id = self.config.options.get(
+ 'cloned_from_project_id')
cloned_from_repo_id = self.config.options.get('cloned_from_repo_id')
init_from_url = self.config.options.get('init_from_url')
init_from_path = self.config.options.get('init_from_path')
@@ -112,7 +117,8 @@ class ForgeGitApp(RepositoryApp):
def git_timers():
return [
- Timer('git_lib.{method_name}', git.Repo, 'rev_parse', 'iter_commits', 'commit'),
+ Timer('git_lib.{method_name}', git.Repo,
+ 'rev_parse', 'iter_commits', 'commit'),
Timer('git_lib.{method_name}', GM.git_repo.GitLibCmdWrapper, 'log'),
]
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 961539c..e5dce43 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -50,7 +50,9 @@ log = logging.getLogger(__name__)
gitdb.util.mman = gitdb.util.mman.__class__(
max_open_handles=128)
+
class GitLibCmdWrapper(object):
+
def __init__(self, client):
self.client = client
@@ -60,12 +62,14 @@ class GitLibCmdWrapper(object):
def log(self, *args, **kwargs):
return self.client.log(*args, **kwargs)
+
class Repository(M.Repository):
- tool_name='Git'
- repo_id='git'
- type_s='Git Repository'
+ tool_name = 'Git'
+ repo_id = 'git'
+ type_s = 'Git Repository'
+
class __mongometa__:
- name='git-repository'
+ name = 'git-repository'
@LazyProperty
def _impl(self):
@@ -86,11 +90,11 @@ class Repository(M.Repository):
)
else:
fetch_command = (
- 'git remote add merge_request {}\n'
- 'git fetch merge_request'
- ).format(
- merge_request.downstream_repo_url,
- )
+ 'git remote add merge_request {}\n'
+ 'git fetch merge_request'
+ ).format(
+ merge_request.downstream_repo_url,
+ )
return 'git checkout %s\n%s\ngit merge %s' % (
merge_request.target_branch,
fetch_command,
@@ -100,6 +104,7 @@ class Repository(M.Repository):
def rev_to_commit_id(self, rev):
return self._impl.rev_parse(rev).hexsha
+
class GitImplementation(M.RepositoryImplementation):
post_receive_template = string.Template(
'#!/bin/bash\n'
@@ -157,7 +162,8 @@ class GitImplementation(M.RepositoryImplementation):
shutil.rmtree(fullname)
if self.can_hotcopy(source_url):
shutil.copytree(source_url, fullname)
- post_receive = os.path.join(self._repo.full_fs_path, 'hooks', 'post-receive')
+ post_receive = os.path.join(
+ self._repo.full_fs_path, 'hooks', 'post-receive')
if os.path.exists(post_receive):
os.rename(post_receive, post_receive + '-user')
repo = git.Repo(fullname)
@@ -188,7 +194,8 @@ class GitImplementation(M.RepositoryImplementation):
url = ' at ' + request.url
except:
pass
- log.exception('Error with rev_parse(%s)%s' % (str(rev) + '^0', url))
+ log.exception('Error with rev_parse(%s)%s' %
+ (str(rev) + '^0', url))
if result:
result.set_context(self._repo)
return result
@@ -201,21 +208,23 @@ class GitImplementation(M.RepositoryImplementation):
return # empty repo
seen = set()
for ci in self._git.iter_commits(all=True, topo_order=True):
- if ci.binsha in seen: continue
+ if ci.binsha in seen:
+ continue
seen.add(ci.binsha)
yield ci.hexsha
def new_commits(self, all_commits=False):
graph = {}
- to_visit = [ self._git.commit(rev=hd.object_id) for hd in self.heads ]
+ to_visit = [self._git.commit(rev=hd.object_id) for hd in self.heads]
while to_visit:
obj = to_visit.pop()
- if obj.hexsha in graph: continue
+ if obj.hexsha in graph:
+ continue
if not all_commits:
# Look up the object
if M.repo.Commit.query.find(dict(_id=obj.hexsha)).count():
- graph[obj.hexsha] = set() # mark as parentless
+ graph[obj.hexsha] = set() # mark as parentless
continue
graph[obj.hexsha] = set(p.hexsha for p in obj.parents)
to_visit += obj.parents
@@ -224,21 +233,22 @@ class GitImplementation(M.RepositoryImplementation):
def refresh_commit_info(self, oid, seen, lazy=True):
from allura.model.repo import CommitDoc
ci_doc = CommitDoc.m.get(_id=oid)
- if ci_doc and lazy: return False
+ if ci_doc and lazy:
+ return False
ci = self._git.rev_parse(oid)
args = dict(
tree_id=ci.tree.hexsha,
- committed = Object(
+ committed=Object(
name=h.really_unicode(ci.committer.name),
email=h.really_unicode(ci.committer.email),
date=datetime.utcfromtimestamp(ci.committed_date)),
- authored = Object(
+ authored=Object(
name=h.really_unicode(ci.author.name),
email=h.really_unicode(ci.author.email),
date=datetime.utcfromtimestamp(ci.authored_date)),
message=h.really_unicode(ci.message or ''),
child_ids=[],
- parent_ids = [ p.hexsha for p in ci.parents ])
+ parent_ids=[p.hexsha for p in ci.parents])
if ci_doc:
ci_doc.update(**args)
ci_doc.m.save()
@@ -247,19 +257,21 @@ class GitImplementation(M.RepositoryImplementation):
try:
ci_doc.m.insert(safe=True)
except DuplicateKeyError:
- if lazy: return False
+ if lazy:
+ return False
self.refresh_tree_info(ci.tree, seen, lazy)
return True
def refresh_tree_info(self, tree, seen, lazy=True):
from allura.model.repo import TreeDoc
- if lazy and tree.binsha in seen: return
+ if lazy and tree.binsha in seen:
+ return
seen.add(tree.binsha)
doc = TreeDoc(dict(
- _id=tree.hexsha,
- tree_ids=[],
- blob_ids=[],
- other_ids=[]))
+ _id=tree.hexsha,
+ tree_ids=[],
+ blob_ids=[],
+ other_ids=[]))
for o in tree:
if o.type == 'submodule':
continue
@@ -313,37 +325,38 @@ class GitImplementation(M.RepositoryImplementation):
if renamed and renamed['to'] == path:
rename_details['path'] = '/' + renamed['from']
# get first rev **before** rename
- _iter = self._git.iter_commits(revs, renamed['from'], max_count=2)
+ _iter = self._git.iter_commits(
+ revs, renamed['from'], max_count=2)
prev_rev = list(_iter)[1]
rename_details['commit_url'] = self._repo.url_for_commit(
prev_rev.hexsha
)
try:
- node = ci.tree/path
+ node = ci.tree / path
size = node.size if node.type == 'blob' else None
except KeyError as e:
size = None
if rename_details:
path = rename_details['path'].strip('/')
yield {
- 'id': ci.hexsha,
- 'message': h.really_unicode(ci.message or '--none--'),
- 'authored': {
- 'name': h.really_unicode(ci.author.name or '--none--'),
- 'email': h.really_unicode(ci.author.email),
- 'date': datetime.utcfromtimestamp(ci.authored_date),
- },
- 'committed': {
- 'name': h.really_unicode(ci.committer.name or '--none--'),
- 'email': h.really_unicode(ci.committer.email),
- 'date': datetime.utcfromtimestamp(ci.committed_date),
- },
- 'refs': refs,
- 'parents': [pci.hexsha for pci in ci.parents],
- 'size': size,
- 'rename_details': rename_details,
- }
+ 'id': ci.hexsha,
+ 'message': h.really_unicode(ci.message or '--none--'),
+ 'authored': {
+ 'name': h.really_unicode(ci.author.name or '--none--'),
+ 'email': h.really_unicode(ci.author.email),
+ 'date': datetime.utcfromtimestamp(ci.authored_date),
+ },
+ 'committed': {
+ 'name': h.really_unicode(ci.committer.name or '--none--'),
+ 'email': h.really_unicode(ci.committer.email),
+ 'date': datetime.utcfromtimestamp(ci.committed_date),
+ },
+ 'refs': refs,
+ 'parents': [pci.hexsha for pci in ci.parents],
+ 'size': size,
+ 'rename_details': rename_details,
+ }
def _iter_commits_with_refs(self, *args, **kwargs):
"""
@@ -376,7 +389,8 @@ class GitImplementation(M.RepositoryImplementation):
D\t<some path> # other cases
etc
"""
- proc = self._git.git.log(*args, format='%H%x00%d', as_process=True, **kwargs)
+ proc = self._git.git.log(*args,
+ format='%H%x00%d', as_process=True, **kwargs)
stream = proc.stdout
commit_lines = []
while True:
@@ -390,9 +404,11 @@ class GitImplementation(M.RepositoryImplementation):
]
if commit_lines:
hexsha, decoration = commit_lines[0].split('\x00')
- refs = decoration.strip(' ()').split(', ') if decoration else []
+ refs = decoration.strip(' ()').split(
+ ', ') if decoration else []
renamed = {}
- if len(commit_lines) > 1: # merge commits don't have any --name-status output
+ # merge commits don't have any --name-status output
+ if len(commit_lines) > 1:
name_stat_parts = commit_lines[1].split(' ')
if name_stat_parts[0] in ['R100', 'R096']:
renamed['from'] = name_stat_parts[1]
@@ -416,7 +432,8 @@ class GitImplementation(M.RepositoryImplementation):
'Set up the git post-commit hook'
text = self.post_receive_template.substitute(
url=self._repo.refresh_url())
- fn = os.path.join(self._repo.fs_path, self._repo.name, 'hooks', 'post-receive')
+ fn = os.path.join(self._repo.fs_path, self._repo.name,
+ 'hooks', 'post-receive')
with open(fn, 'w') as fp:
fp.write(text)
os.chmod(fn, 0755)
@@ -425,8 +442,8 @@ class GitImplementation(M.RepositoryImplementation):
evens = oid[::2]
odds = oid[1::2]
binsha = ''
- for e,o in zip(evens, odds):
- binsha += chr(int(e+o, 16))
+ for e, o in zip(evens, odds):
+ binsha += chr(int(e + o, 16))
return git.Object.new_from_sha(self._git, binsha)
def rev_parse(self, rev):
@@ -434,7 +451,8 @@ class GitImplementation(M.RepositoryImplementation):
def symbolics_for_commit(self, commit):
try:
- branches = [b.name for b in self.branches if b.object_id == commit._id]
+ branches = [
+ b.name for b in self.branches if b.object_id == commit._id]
tags = [t.name for t in self.tags if t.object_id == commit._id]
return branches, tags
except git.GitCommandError:
@@ -449,11 +467,14 @@ class GitImplementation(M.RepositoryImplementation):
if not os.path.exists(self._repo.tarball_path):
os.makedirs(self._repo.tarball_path)
archive_name = self._repo.tarball_filename(commit)
- filename = os.path.join(self._repo.tarball_path, '%s%s' % (archive_name, '.zip'))
- tmpfilename = os.path.join(self._repo.tarball_path, '%s%s' % (archive_name, '.tmp'))
+ filename = os.path.join(self._repo.tarball_path, '%s%s' %
+ (archive_name, '.zip'))
+ tmpfilename = os.path.join(self._repo.tarball_path, '%s%s' %
+ (archive_name, '.tmp'))
try:
with open(tmpfilename, 'wb') as archive_file:
- self._git.archive(archive_file, format='zip', treeish=commit, prefix=archive_name + '/')
+ self._git.archive(archive_file,
+ format='zip', treeish=commit, prefix=archive_name + '/')
os.rename(tmpfilename, filename)
finally:
if os.path.exists(tmpfilename):
@@ -466,7 +487,7 @@ class GitImplementation(M.RepositoryImplementation):
path = path.strip('/')
ci = self._git.rev_parse(rev)
try:
- node = ci.tree/path
+ node = ci.tree / path
return node.type == 'blob'
except KeyError as e:
return False
@@ -507,11 +528,11 @@ class GitImplementation(M.RepositoryImplementation):
skip = 0
while commit_id and not files:
output = self._git.git.log(
- commit_id, '--', *paths,
- pretty='format:%H',
- name_only=True,
- max_count=1,
- skip=skip)
+ commit_id, '--', *paths,
+ pretty='format:%H',
+ name_only=True,
+ max_count=1,
+ skip=skip)
lines = output.split('\n')
commit_id = lines[0]
files = prefix_paths_union(paths, set(lines[1:]))
@@ -525,13 +546,14 @@ class GitImplementation(M.RepositoryImplementation):
def get_changes(self, commit_id):
return self._git.git.log(
- commit_id,
- name_only=True,
- pretty='format:',
- max_count=1).splitlines()[1:]
+ commit_id,
+ name_only=True,
+ pretty='format:',
+ max_count=1).splitlines()[1:]
+
class _OpenedGitBlob(object):
- CHUNK_SIZE=4096
+ CHUNK_SIZE = 4096
def __init__(self, stream):
self._stream = stream
@@ -548,16 +570,18 @@ class _OpenedGitBlob(object):
# Replenish buffer until we have a line break
while '\n' not in buffer:
chars = self._stream.read(self.CHUNK_SIZE)
- if not chars: break
+ if not chars:
+ break
buffer += chars
- if not buffer: break
+ if not buffer:
+ break
eol = buffer.find('\n')
if eol == -1:
# end without \n
yield buffer
break
- yield buffer[:eol+1]
- buffer = buffer[eol+1:]
+ yield buffer[:eol + 1]
+ buffer = buffer[eol + 1:]
def close(self):
pass
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeGit/forgegit/tests/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/__init__.py b/ForgeGit/forgegit/tests/__init__.py
index fc1d735..b693039 100644
--- a/ForgeGit/forgegit/tests/__init__.py
+++ b/ForgeGit/forgegit/tests/__init__.py
@@ -18,7 +18,7 @@
# under the License.
-## Make our own Git tool test decorator
+# Make our own Git tool test decorator
from allura.tests.decorators import with_tool
with_git = with_tool('test', 'Git', 'src-git', 'Git', type='git')
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeGit/forgegit/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/functional/test_auth.py b/ForgeGit/forgegit/tests/functional/test_auth.py
index 4a16aab..93a1af0 100644
--- a/ForgeGit/forgegit/tests/functional/test_auth.py
+++ b/ForgeGit/forgegit/tests/functional/test_auth.py
@@ -77,8 +77,8 @@ class TestGitUserPermissions(TestController):
def _check_repo(self, path, username='test-admin', **kw):
url = '/auth/repo_permissions'
r = self.app.get(url, params=dict(
- repo_path=path,
- username=username), **kw)
+ repo_path=path,
+ username=username), **kw)
try:
return r.json
except:
@@ -86,7 +86,8 @@ class TestGitUserPermissions(TestController):
@with_git
def test_list_repos(self):
- r = self.app.get('/auth/repo_permissions', params=dict(username='test-admin'), status=200)
+ r = self.app.get('/auth/repo_permissions',
+ params=dict(username='test-admin'), status=200)
assert_equal(json.loads(r.body), {"allow_write": [
'/git/test/src-git',
]})
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeGit/forgegit/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index f1c8a49..68d117e 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -35,6 +35,7 @@ from allura.tests.decorators import with_tool
from forgegit.tests import with_git
from forgegit import model as GM
+
class _TestCase(TestController):
def setUp(self):
@@ -104,45 +105,53 @@ class TestRootController(_TestCase):
def test_commit_browser_data(self):
resp = self.app.get('/src-git/commit_browser_data')
- data = json.loads(resp.body);
+ data = json.loads(resp.body)
assert data['max_row'] == 4
assert data['next_column'] == 1
- assert_equal(data['built_tree']['df30427c488aeab84b2352bdf88a3b19223f9d7a'],
- {u'url': u'/p/test/src-git/ci/df30427c488aeab84b2352bdf88a3b19223f9d7a/',
- u'oid': u'df30427c488aeab84b2352bdf88a3b19223f9d7a',
- u'short_id': u'[df3042]',
- u'column': 0,
- u'parents': [u'6a45885ae7347f1cac5103b0050cc1be6a1496c8'],
- u'message': u'Add README', u'row': 2})
+ assert_equal(
+ data['built_tree']['df30427c488aeab84b2352bdf88a3b19223f9d7a'],
+ {u'url': u'/p/test/src-git/ci/df30427c488aeab84b2352bdf88a3b19223f9d7a/',
+ u'oid': u'df30427c488aeab84b2352bdf88a3b19223f9d7a',
+ u'short_id': u'[df3042]',
+ u'column': 0,
+ u'parents': [u'6a45885ae7347f1cac5103b0050cc1be6a1496c8'],
+ u'message': u'Add README', u'row': 2})
def test_log(self):
- resp = self.app.get('/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/log/')
+ resp = self.app.get(
+ '/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/log/')
assert 'Initial commit' in resp
assert '<div class="markdown_content"><p>Change README</p></div>' in resp
assert 'tree/README?format=raw">Download</a>' not in resp
- assert 'Tree' in resp.html.findAll('td')[2].text, resp.html.findAll('td')[2].text
- resp = self.app.get('/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/log/?path=/README')
+ assert 'Tree' in resp.html.findAll(
+ 'td')[2].text, resp.html.findAll('td')[2].text
+ resp = self.app.get(
+ '/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/log/?path=/README')
assert 'View' in resp.html.findAll('td')[2].text
assert 'Change README' in resp
assert 'tree/README?format=raw">Download</a>' in resp
assert 'Add README' in resp
assert "Initial commit " not in resp
- resp = self.app.get('/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/log/?path=/a/b/c/')
+ resp = self.app.get(
+ '/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/log/?path=/a/b/c/')
assert 'Remove file' in resp
assert 'Initial commit' in resp
assert 'Add README' not in resp
assert 'Change README' not in resp
- resp = self.app.get('/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/log/?path=/not/exist')
+ resp = self.app.get(
+ '/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/log/?path=/not/exist')
assert 'No (more) commits' in resp
def test_diff_ui(self):
- r = self.app.get('/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/log/?path=/README')
+ r = self.app.get(
+ '/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/log/?path=/README')
assert '<div class="grid-19"><input type="button" value="Compare" class="compare_revision"></div>' in r
assert '<input type="checkbox" class="revision"' in r
assert 'revision="1e146e67985dcd71c74de79613719bef7bddca4a"' in r
assert 'url_commit="/p/test/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/">' in r
- r = self.app.get('/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/log/')
+ r = self.app.get(
+ '/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/log/')
assert '<div class="grid-19"><input type="button" value="Compare" class="compare_revision"></div>' not in r
assert '<input type="checkbox" class="revision"' not in r
assert 'revision="1e146e67985dcd71c74de79613719bef7bddca4a"' not in r
@@ -174,7 +183,8 @@ class TestRootController(_TestCase):
title = channel.find('title').text
assert_equal(title, 'test Git changes')
description = channel.find('description').text
- assert_equal(description, 'Recent changes to Git repository in test project')
+ assert_equal(description,
+ 'Recent changes to Git repository in test project')
link = channel.find('link').text
assert_equal(link, 'http://localhost/p/test/src-git/')
commit = channel.find('item')
@@ -200,7 +210,7 @@ class TestRootController(_TestCase):
assert len(resp.html.findAll('tr')) == 2, resp.showbrowser()
resp = self.app.get(ci + 'tree/')
assert 'README' in resp, resp.showbrowser()
- links = [ a.get('href') for a in resp.html.findAll('a') ]
+ links = [a.get('href') for a in resp.html.findAll('a')]
assert 'README' in links, resp.showbrowser()
assert 'README/' not in links, resp.showbrowser()
@@ -219,8 +229,10 @@ class TestRootController(_TestCase):
def test_file(self):
ci = self._get_ci()
resp = self.app.get(ci + 'tree/README')
- assert 'README' in resp.html.find('h2', {'class':'dark title'}).contents[2]
- content = str(resp.html.find('div', {'class':'clip grid-19 codebrowser'}))
+ assert 'README' in resp.html.find(
+ 'h2', {'class': 'dark title'}).contents[2]
+ content = str(
+ resp.html.find('div', {'class': 'clip grid-19 codebrowser'}))
assert 'This is readme' in content, content
assert '<span id="l1" class="code_block">' in resp
assert 'var hash = window.location.hash.substring(1);' in resp
@@ -231,7 +243,8 @@ class TestRootController(_TestCase):
def test_diff(self):
ci = self._get_ci()
- resp = self.app.get(ci + 'tree/README?diff=df30427c488aeab84b2352bdf88a3b19223f9d7a')
+ resp = self.app.get(
+ ci + 'tree/README?diff=df30427c488aeab84b2352bdf88a3b19223f9d7a')
assert 'readme' in resp, resp.showbrowser()
assert '+++' in resp, resp.showbrowser()
@@ -239,7 +252,8 @@ class TestRootController(_TestCase):
ci = self._get_ci()
fn = 'tree/README?diff=df30427c488aeab84b2352bdf88a3b19223f9d7a'
r = self.app.get(ci + fn + '&diformat=regular')
- assert fn + '&diformat=sidebyside">Switch to side-by-side view</a>' in r
+ assert fn + \
+ '&diformat=sidebyside">Switch to side-by-side view</a>' in r
r = self.app.get(ci + fn + '&diformat=sidebyside')
assert fn + '&diformat=regular">Switch to unified view</a>' in r
@@ -249,7 +263,8 @@ class TestRootController(_TestCase):
notification = M.Notification.query.find(
dict(subject='[test:src-git] 5 new commits to Test Project Git')).first()
assert notification
- domain = '.'.join(reversed(c.app.url[1:-1].split('/'))).replace('_', '-')
+ domain = '.'.join(
+ reversed(c.app.url[1:-1].split('/'))).replace('_', '-')
common_suffix = tg.config.get('forgemail.domain', '.sourceforge.net')
email = 'noreply@%s%s' % (domain, common_suffix)
assert email in notification['reply_to_address']
@@ -257,7 +272,8 @@ class TestRootController(_TestCase):
def test_file_force_display(self):
ci = self._get_ci()
resp = self.app.get(ci + 'tree/README?force=True')
- content = str(resp.html.find('div', {'class':'clip grid-19 codebrowser'}))
+ content = str(
+ resp.html.find('div', {'class': 'clip grid-19 codebrowser'}))
assert re.search(r'<pre>.*This is readme', content), content
assert '</pre>' in content, content
@@ -270,7 +286,8 @@ class TestRootController(_TestCase):
r = self.app.get(ci + 'tree/index.html')
header = r.html.find('h2', {'class': 'dark title'}).contents[2]
assert 'index.html' in header, header
- content = str(r.html.find('div', {'class': 'clip grid-19 codebrowser'}))
+ content = str(
+ r.html.find('div', {'class': 'clip grid-19 codebrowser'}))
assert ('<span class="nt"><h1></span>'
'index.html'
'<span class="nt"></h1></span>') in content, content
@@ -284,7 +301,8 @@ class TestRootController(_TestCase):
header = r.html.find('h2', {'class': 'dark title'})
assert 'index' in header.contents[3], header.contents[3]
assert 'index.htm' in header.contents[4], header.contents[4]
- content = str(r.html.find('div', {'class': 'clip grid-19 codebrowser'}))
+ content = str(
+ r.html.find('div', {'class': 'clip grid-19 codebrowser'}))
assert ('<span class="nt"><h1></span>'
'index/index.htm'
'<span class="nt"></h1></span>') in content, content
@@ -296,27 +314,27 @@ class TestRootController(_TestCase):
# user is not subscribed
assert not M.Mailbox.subscribed(user_id=user._id)
r = self.app.get(ci + 'tree/',
- extra_environ={'username': str(user.username)})
+ extra_environ={'username': str(user.username)})
link = r.html.find('a', 'artifact_subscribe')
assert link is not None, r.html
# subscribe
self.app.get(ci + 'tree/subscribe?subscribe=True',
- extra_environ={'username': str(user.username)}).follow()
+ extra_environ={'username': str(user.username)}).follow()
# user is subscribed
assert M.Mailbox.subscribed(user_id=user._id)
r = self.app.get(ci + 'tree/',
- extra_environ={'username': str(user.username)})
+ extra_environ={'username': str(user.username)})
link = r.html.find('a', 'artifact_unsubscribe active')
assert link is not None, r.html
# unsubscribe
self.app.get(ci + 'tree/subscribe?unsubscribe=True',
- extra_environ={'username': str(user.username)}).follow()
+ extra_environ={'username': str(user.username)}).follow()
# user is not subscribed
assert not M.Mailbox.subscribed(user_id=user._id)
r = self.app.get(ci + 'tree/',
- extra_environ={'username': str(user.username)})
+ extra_environ={'username': str(user.username)})
link = r.html.find('a', 'artifact_subscribe')
assert link is not None, r.html
@@ -363,7 +381,8 @@ class TestRootController(_TestCase):
self.setup_testgit_index_repo()
r = self.app.get('/p/test/testgit-index/ci/master/tree/index/')
form = r.html.find('form', 'tarball')
- assert_equal(form.get('action'), '/p/test/testgit-index/ci/master/tarball')
+ assert_equal(
+ form.get('action'), '/p/test/testgit-index/ci/master/tarball')
assert_equal(form.input.get('value'), '/index')
def test_default_branch(self):
@@ -376,14 +395,17 @@ class TestRootController(_TestCase):
def test_set_default_branch(self):
r = self.app.get('/p/test/admin/src-git/set_default_branch_name')
assert '<input type="text" name="branch_name" id="branch_name" value="master"/>' in r
- self.app.post('/p/test/admin/src-git/set_default_branch_name', params={'branch_name':'zz'})
+ self.app.post('/p/test/admin/src-git/set_default_branch_name',
+ params={'branch_name': 'zz'})
r = self.app.get('/p/test/admin/src-git/set_default_branch_name')
assert '<input type="text" name="branch_name" id="branch_name" value="zz"/>' in r
r = self.app.get('/p/test/src-git/').follow().follow()
assert '<span class="scm-branch-label">zz</span>' in r
- assert_in('<span>bad</span>', r) # 'bad' is a file name which in zz, but not in master
+ # 'bad' is a file name which in zz, but not in master
+ assert_in('<span>bad</span>', r)
- self.app.post('/p/test/admin/src-git/set_default_branch_name', params={'branch_name':'master'})
+ self.app.post('/p/test/admin/src-git/set_default_branch_name',
+ params={'branch_name': 'master'})
r = self.app.get('/p/test/src-git/').follow().follow()
assert_not_in('<span>bad</span>', r)
assert_in('<span>README</span>', r)
@@ -397,6 +419,7 @@ class TestRestController(_TestCase):
def test_commits(self):
self.app.get('/rest/p/test/src-git/commits', status=200)
+
class TestFork(_TestCase):
def setUp(self):
@@ -404,18 +427,19 @@ class TestFork(_TestCase):
to_project = M.Project.query.get(
shortname='test2', neighborhood_id=c.project.neighborhood_id)
r = self.app.post('/src-git/fork', params=dict(
- project_id=str(to_project._id),
- mount_point='code',
- mount_label='Test forked repository'))
+ project_id=str(to_project._id),
+ mount_point='code',
+ mount_label='Test forked repository'))
assert "{status: 'error'}" not in str(r.follow())
cloned_from = c.app.repo
with h.push_context('test2', 'code', neighborhood='Projects'):
c.app.repo.init_as_clone(
- cloned_from.full_fs_path,
- cloned_from.app.config.script_name(),
- cloned_from.full_fs_path)
+ cloned_from.full_fs_path,
+ cloned_from.app.config.script_name(),
+ cloned_from.full_fs_path)
# Add commit to a forked repo, thus merge requests will not be empty
- # clone repo to tmp location first (can't add commit to bare repos directly)
+ # clone repo to tmp location first (can't add commit to bare repos
+ # directly)
clone_path = tempfile.mkdtemp()
cloned = c.app.repo._impl._git.clone(clone_path)
with open(clone_path + '/README', 'w+') as f:
@@ -473,8 +497,8 @@ class TestFork(_TestCase):
def test_fork_links_go_to_fork(self):
r = self._fork_page()
- hrefs = ( a.get('href') for a in r.html('a') )
- hrefs = ( href for href in hrefs if href and '/ci/' in href )
+ hrefs = (a.get('href') for a in r.html('a'))
+ hrefs = (href for href in hrefs if href and '/ci/' in href)
for href in hrefs:
assert href.startswith('/p/test2/code/'), href
@@ -504,7 +528,8 @@ class TestFork(_TestCase):
c_id = self.forked_repo.get_heads()[0]['object_id']
assert_equal(rev_links[0].get('href'), '/p/test2/code/ci/%s/' % c_id)
assert_equal(rev_links[0].getText(), '[%s]' % c_id[:6])
- assert_equal(browse_links[0].get('href'), '/p/test2/code/ci/%s/tree' % c_id)
+ assert_equal(browse_links[0].get('href'),
+ '/p/test2/code/ci/%s/tree' % c_id)
assert_equal(browse_links[0].getText(), 'Tree')
merge_instructions = r.html.findAll('textarea')[0].getText()
assert 'git checkout master' in merge_instructions
@@ -523,7 +548,8 @@ class TestFork(_TestCase):
assert 'Merge Request #%s: (rejected)' % mr_num in r, r
def test_merge_request_default_branches(self):
- _select_val = lambda r, n: r.html.find('select', {'name': n}).find(selected=True).string
+ _select_val = lambda r, n: r.html.find(
+ 'select', {'name': n}).find(selected=True).string
r = self.app.get('/p/test2/code/request_merge')
assert_equal(_select_val(r, 'source_branch'), 'master')
assert_equal(_select_val(r, 'target_branch'), 'master')
@@ -539,6 +565,7 @@ class TestFork(_TestCase):
assert_equal(_select_val(r, 'source_branch'), 'zz')
assert_equal(_select_val(r, 'target_branch'), 'zz')
+
class TestDiff(TestController):
def setUp(self):
@@ -559,14 +586,17 @@ class TestDiff(TestController):
ThreadLocalORMSession.flush_all()
def test_diff(self):
- r = self.app.get('/src-git/ci/d961abbbf10341ee18a668c975842c35cfc0bef2/tree/1.png?barediff=2ce83a24e52c21e8d2146b1a04a20717c0bb08d7')
+ r = self.app.get(
+ '/src-git/ci/d961abbbf10341ee18a668c975842c35cfc0bef2/tree/1.png?barediff=2ce83a24e52c21e8d2146b1a04a20717c0bb08d7')
assert 'alt="2ce83a2..."' in r
assert 'alt="d961abb..."' in r
- r = self.app.get('/src-git/ci/d961abbbf10341ee18a668c975842c35cfc0bef2/tree/1.png?diff=2ce83a24e52c21e8d2146b1a04a20717c0bb08d7')
+ r = self.app.get(
+ '/src-git/ci/d961abbbf10341ee18a668c975842c35cfc0bef2/tree/1.png?diff=2ce83a24e52c21e8d2146b1a04a20717c0bb08d7')
assert 'alt="2ce83a2..."' in r
assert 'alt="d961abb..."' in r
+
class TestGitRename(TestController):
def setUp(self):
@@ -587,17 +617,18 @@ class TestGitRename(TestController):
ThreadLocalORMSession.flush_all()
def test_log(self):
- resp = self.app.get('/src-git/ci/259c77dd6ee0e6091d11e429b56c44ccbf1e64a3/log/?path=/f2.txt')
+ resp = self.app.get(
+ '/src-git/ci/259c77dd6ee0e6091d11e429b56c44ccbf1e64a3/log/?path=/f2.txt')
assert '<b>renamed from</b>' in resp
assert '/f.txt' in resp
assert '(27 Bytes)' in resp
assert '(19 Bytes)' in resp
- resp = self.app.get('/src-git/ci/fbb0644603bb6ecee3ebb62efe8c86efc9b84ee6/log/?path=/f.txt')
+ resp = self.app.get(
+ '/src-git/ci/fbb0644603bb6ecee3ebb62efe8c86efc9b84ee6/log/?path=/f.txt')
assert '(19 Bytes)' in resp
assert '(10 Bytes)' in resp
- resp = self.app.get('/src-git/ci/7c09182e61af959e4f1fb0e354bab49f14ef810d/tree/f.txt')
+ resp = self.app.get(
+ '/src-git/ci/7c09182e61af959e4f1fb0e354bab49f14ef810d/tree/f.txt')
assert "2 lines (1 with data), 10 Bytes" in resp
-
-
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 33875bd..eb68a1b 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -45,6 +45,7 @@ from forgegit import model as GM
from forgegit.tests import with_git
from forgewiki import model as WM
+
class TestNewGit(unittest.TestCase):
def setUp(self):
@@ -61,7 +62,7 @@ class TestNewGit(unittest.TestCase):
c.app.repo.fs_path = repo_dir
c.app.repo.name = 'testgit.git'
self.repo = c.app.repo
- #self.repo = GM.Repository(
+ # self.repo = GM.Repository(
# name='testgit.git',
# fs_path=repo_dir,
# url_path = '/test/',
@@ -80,7 +81,8 @@ class TestNewGit(unittest.TestCase):
assert self.rev.tree._id == self.rev.tree_id
assert self.rev.summary == self.rev.message.splitlines()[0]
assert self.rev.shorthand_id() == '[1e146e]'
- assert self.rev.symbolic_ids == (['master'], ['foo']), self.rev.symbolic_ids
+ assert self.rev.symbolic_ids == (
+ ['master'], ['foo']), self.rev.symbolic_ids
assert self.rev.url() == (
'/p/test/src-git/ci/'
'1e146e67985dcd71c74de79613719bef7bddca4a/')
@@ -112,6 +114,7 @@ class TestNewGit(unittest.TestCase):
'/p/test/src-git/ci/'
'1e146e67985dcd71c74de79613719bef7bddca4a/')
+
class TestGitRepo(unittest.TestCase, RepoImplTestBase):
def setUp(self):
@@ -127,9 +130,9 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
self.repo = GM.Repository(
name='testgit.git',
fs_path=repo_dir,
- url_path = '/test/',
- tool = 'git',
- status = 'creating')
+ url_path='/test/',
+ tool='git',
+ status='creating')
self.repo.refresh()
ThreadLocalORMSession.flush_all()
ThreadLocalORMSession.close_all()
@@ -137,10 +140,10 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
def test_init(self):
repo = GM.Repository(
name='testgit.git',
- fs_path=g.tmpdir+'/',
- url_path = '/test/',
- tool = 'git',
- status = 'creating')
+ fs_path=g.tmpdir + '/',
+ url_path='/test/',
+ tool='git',
+ status='creating')
dirname = os.path.join(repo.fs_path, repo.name)
if os.path.exists(dirname):
shutil.rmtree(dirname)
@@ -151,9 +154,9 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
repo = GM.Repository(
name='testgit.git',
fs_path=g.tmpdir + '/',
- url_path = '/test/',
- tool = 'git',
- status = 'creating')
+ url_path='/test/',
+ tool='git',
+ status='creating')
repo_path = pkg_resources.resource_filename(
'forgegit', 'tests/data/testgit.git')
dirname = os.path.join(repo.fs_path, repo.name)
@@ -161,19 +164,23 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
shutil.rmtree(dirname)
repo.init()
repo._impl.clone_from(repo_path)
- assert not os.path.exists(os.path.join(g.tmpdir, 'testgit.git/hooks/update'))
- assert not os.path.exists(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive-user'))
- assert os.path.exists(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))
- assert os.stat(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))[0] & stat.S_IXUSR
+ assert not os.path.exists(
+ os.path.join(g.tmpdir, 'testgit.git/hooks/update'))
+ assert not os.path.exists(
+ os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive-user'))
+ assert os.path.exists(
+ os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))
+ assert os.stat(
+ os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))[0] & stat.S_IXUSR
@mock.patch('forgegit.model.git_repo.g.post_event')
def test_clone(self, post_event):
repo = GM.Repository(
name='testgit.git',
fs_path=g.tmpdir + '/',
- url_path = '/test/',
- tool = 'git',
- status = 'creating')
+ url_path='/test/',
+ tool='git',
+ status='creating')
repo_path = pkg_resources.resource_filename(
'forgegit', 'tests/data/testgit.git')
dirname = os.path.join(repo.fs_path, repo.name)
@@ -182,12 +189,18 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
repo.init()
repo._impl.clone_from(repo_path)
assert len(list(repo.log()))
- assert not os.path.exists(os.path.join(g.tmpdir, 'testgit.git/hooks/update'))
- assert not os.path.exists(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive-user'))
- assert os.path.exists(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))
- assert os.stat(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))[0] & stat.S_IXUSR
- with open(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive')) as f: c = f.read()
- self.assertIn('curl -s http://localhost/auth/refresh_repo/p/test/src-git/\n', c)
+ assert not os.path.exists(
+ os.path.join(g.tmpdir, 'testgit.git/hooks/update'))
+ assert not os.path.exists(
+ os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive-user'))
+ assert os.path.exists(
+ os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))
+ assert os.stat(
+ os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))[0] & stat.S_IXUSR
+ with open(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive')) as f:
+ c = f.read()
+ self.assertIn(
+ 'curl -s http://localhost/auth/refresh_repo/p/test/src-git/\n', c)
self.assertIn('exec $DIR/post-receive-user\n', c)
shutil.rmtree(dirname)
@@ -197,10 +210,10 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
with h.push_config(tg.config, **{'scm.git.hotcopy': 'True'}):
repo = GM.Repository(
name='testgit.git',
- fs_path=g.tmpdir+'/',
- url_path = '/test/',
- tool = 'git',
- status = 'creating')
+ fs_path=g.tmpdir + '/',
+ url_path='/test/',
+ tool='git',
+ status='creating')
repo.app.config.options['hotcopy'] = True
repo_path = pkg_resources.resource_filename(
'forgegit', 'tests/data/testgit.git')
@@ -211,12 +224,18 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
repo._impl.clone_from(repo_path)
assert not clone_from.called
assert len(list(repo.log()))
- assert os.path.exists(os.path.join(g.tmpdir, 'testgit.git/hooks/update'))
- assert os.path.exists(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive-user'))
- assert os.path.exists(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))
- assert os.stat(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))[0] & stat.S_IXUSR
- with open(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive')) as f: c = f.read()
- self.assertIn('curl -s http://localhost/auth/refresh_repo/p/test/src-git/\n', c)
+ assert os.path.exists(
+ os.path.join(g.tmpdir, 'testgit.git/hooks/update'))
+ assert os.path.exists(
+ os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive-user'))
+ assert os.path.exists(
+ os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))
+ assert os.stat(
+ os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive'))[0] & stat.S_IXUSR
+ with open(os.path.join(g.tmpdir, 'testgit.git/hooks/post-receive')) as f:
+ c = f.read()
+ self.assertIn(
+ 'curl -s http://localhost/auth/refresh_repo/p/test/src-git/\n', c)
self.assertIn('exec $DIR/post-receive-user\n', c)
shutil.rmtree(dirname)
@@ -283,7 +302,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
'refs': [],
'size': None,
'rename_details': {}},
- ])
+ ])
def test_log_unicode(self):
entries = list(self.repo.log(path=u'völundr', id_only=False))
@@ -316,7 +335,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
'refs': [],
'size': 15,
'rename_details': {}},
- ])
+ ])
def test_commit(self):
entry = self.repo.commit('HEAD')
@@ -342,13 +361,15 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
self.assertEqual(new_tree.other_ids, orig_tree.other_ids)
def test_notification_email(self):
- send_notifications(self.repo, ['1e146e67985dcd71c74de79613719bef7bddca4a', ])
+ send_notifications(
+ self.repo, ['1e146e67985dcd71c74de79613719bef7bddca4a', ])
ThreadLocalORMSession.flush_all()
n = M.Notification.query.find(
dict(subject='[test:src-git] [1e146e] - Rick Copeland: Change README')).first()
assert n
assert 'master: ' in n.text, n.text
- send_notifications(self.repo, ['1e146e67985dcd71c74de79613719bef7bddca4a', 'df30427c488aeab84b2352bdf88a3b19223f9d7a'])
+ send_notifications(
+ self.repo, ['1e146e67985dcd71c74de79613719bef7bddca4a', 'df30427c488aeab84b2352bdf88a3b19223f9d7a'])
ThreadLocalORMSession.flush_all()
assert M.Notification.query.find(
dict(subject='[test:src-git] 2 new commits to Test Project Git')).first()
@@ -356,50 +377,59 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
def test_tarball(self):
tmpdir = tg.config['scm.repos.tarball.root']
if os.path.isfile(os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.zip")):
- os.remove(os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.zip"))
- assert_equal(self.repo.tarball_path, os.path.join(tmpdir, 'git/t/te/test/testgit.git'))
- assert_equal(self.repo.tarball_url('HEAD'), 'file:///git/t/te/test/testgit.git/test-src-git-HEAD.zip')
+ os.remove(
+ os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.zip"))
+ assert_equal(self.repo.tarball_path,
+ os.path.join(tmpdir, 'git/t/te/test/testgit.git'))
+ assert_equal(self.repo.tarball_url('HEAD'),
+ 'file:///git/t/te/test/testgit.git/test-src-git-HEAD.zip')
self.repo.tarball('HEAD')
- assert os.path.isfile(os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.zip"))
+ assert os.path.isfile(
+ os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.zip"))
def test_all_commit_ids(self):
cids = list(self.repo.all_commit_ids())
heads = [
- '1e146e67985dcd71c74de79613719bef7bddca4a', # master
- '5c47243c8e424136fd5cdd18cd94d34c66d1955c', # zz
- ]
+ '1e146e67985dcd71c74de79613719bef7bddca4a', # master
+ '5c47243c8e424136fd5cdd18cd94d34c66d1955c', # zz
+ ]
self.assertIn(cids[0], heads) # repo head comes first
for head in heads:
self.assertIn(head, cids) # all branches included
- self.assertEqual(cids[-1], '9a7df788cf800241e3bb5a849c8870f2f8259d98') # repo root comes last
+ # repo root comes last
+ self.assertEqual(cids[-1], '9a7df788cf800241e3bb5a849c8870f2f8259d98')
def test_ls(self):
lcd_map = self.repo.commit('HEAD').tree.ls()
self.assertEqual(lcd_map, [{
- 'href': u'README',
- 'kind': 'BLOB',
- 'last_commit': {
+ 'href': u'README',
+ 'kind': 'BLOB',
+ 'last_commit': {
'author': u'Rick Copeland',
- 'author_email': u'rcopeland@geek.net',
- 'author_url': None,
- 'date': datetime.datetime(2010, 10, 7, 18, 44, 11),
- 'href': u'/p/test/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/',
- 'shortlink': u'[1e146e]',
- 'summary': u'Change README'},
- 'name': u'README'}])
+ 'author_email': u'rcopeland@geek.net',
+ 'author_url': None,
+ 'date': datetime.datetime(2010, 10, 7, 18, 44, 11),
+ 'href': u'/p/test/src-git/ci/1e146e67985dcd71c74de79613719bef7bddca4a/',
+ 'shortlink': u'[1e146e]',
+ 'summary': u'Change README'},
+ 'name': u'README'}])
def test_tarball_status(self):
tmpdir = tg.config['scm.repos.tarball.root']
if os.path.isfile(os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.zip")):
- os.remove(os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.zip"))
+ os.remove(
+ os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.zip"))
if os.path.isfile(os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.tmp")):
- os.remove(os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.tmp"))
+ os.remove(
+ os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.tmp"))
if os.path.isdir(os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD/")):
- os.removedirs(os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD/"))
+ os.removedirs(
+ os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD/"))
self.repo.tarball('HEAD')
assert_equal(self.repo.get_tarball_status('HEAD'), 'complete')
- os.remove(os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.zip"))
+ os.remove(
+ os.path.join(tmpdir, "git/t/te/test/testgit.git/test-src-git-HEAD.zip"))
assert_equal(self.repo.get_tarball_status('HEAD'), None)
def test_tarball_status_task(self):
@@ -415,7 +445,7 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
'task_name': 'allura.tasks.repo_tasks.tarball',
'args': ['HEAD', ''],
'state': {'$in': ['busy', 'ready']},
- })
+ })
# task is running
task.state = 'busy'
@@ -433,25 +463,29 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
repo2 = GM.Repository(
name='test',
fs_path=d.path,
- url_path = '/test/',
- tool = 'git',
- status = 'creating')
+ url_path='/test/',
+ tool='git',
+ status='creating')
repo2.init()
assert repo2.is_empty()
repo2.refresh()
ThreadLocalORMSession.flush_all()
assert repo2.is_empty()
+
class TestGitImplementation(unittest.TestCase):
+
def test_branches(self):
repo_dir = pkg_resources.resource_filename(
'forgegit', 'tests/data/testgit.git')
repo = mock.Mock(full_fs_path=repo_dir)
impl = GM.git_repo.GitImplementation(repo)
self.assertEqual(impl.branches, [
- Object(name='master', object_id='1e146e67985dcd71c74de79613719bef7bddca4a'),
- Object(name='zz', object_id='5c47243c8e424136fd5cdd18cd94d34c66d1955c')
- ])
+ Object(name='master',
+ object_id='1e146e67985dcd71c74de79613719bef7bddca4a'),
+ Object(name='zz',
+ object_id='5c47243c8e424136fd5cdd18cd94d34c66d1955c')
+ ])
def test_tags(self):
repo_dir = pkg_resources.resource_filename(
@@ -459,8 +493,9 @@ class TestGitImplementation(unittest.TestCase):
repo = mock.Mock(full_fs_path=repo_dir)
impl = GM.git_repo.GitImplementation(repo)
self.assertEqual(impl.tags, [
- Object(name='foo', object_id='1e146e67985dcd71c74de79613719bef7bddca4a'),
- ])
+ Object(name='foo',
+ object_id='1e146e67985dcd71c74de79613719bef7bddca4a'),
+ ])
def test_last_commit_ids(self):
repo_dir = pkg_resources.resource_filename(
@@ -469,12 +504,12 @@ class TestGitImplementation(unittest.TestCase):
impl = GM.git_repo.GitImplementation(repo)
lcd = lambda c, p: impl.last_commit_ids(mock.Mock(_id=c), p)
self.assertEqual(lcd('13951944969cf45a701bf90f83647b309815e6d5', ['f2.txt', 'f3.txt']), {
- 'f2.txt': '259c77dd6ee0e6091d11e429b56c44ccbf1e64a3',
- 'f3.txt': '653667b582ef2950c1954a0c7e1e8797b19d778a',
- })
+ 'f2.txt': '259c77dd6ee0e6091d11e429b56c44ccbf1e64a3',
+ 'f3.txt': '653667b582ef2950c1954a0c7e1e8797b19d778a',
+ })
self.assertEqual(lcd('259c77dd6ee0e6091d11e429b56c44ccbf1e64a3', ['f2.txt', 'f3.txt']), {
- 'f2.txt': '259c77dd6ee0e6091d11e429b56c44ccbf1e64a3',
- })
+ 'f2.txt': '259c77dd6ee0e6091d11e429b56c44ccbf1e64a3',
+ })
def test_last_commit_ids_threaded(self):
with h.push_config(tg.config, lcd_thread_chunk_size=1):
@@ -488,7 +523,8 @@ class TestGitImplementation(unittest.TestCase):
repo = mock.Mock(full_fs_path=repo_dir)
_git.side_effect = ValueError
impl = GM.git_repo.GitImplementation(repo)
- lcds = impl.last_commit_ids(mock.Mock(_id='13951944969cf45a701bf90f83647b309815e6d5'), ['f2.txt', 'f3.txt'])
+ lcds = impl.last_commit_ids(
+ mock.Mock(_id='13951944969cf45a701bf90f83647b309815e6d5'), ['f2.txt', 'f3.txt'])
self.assertEqual(lcds, {})
@@ -507,9 +543,9 @@ class TestGitCommit(unittest.TestCase):
self.repo = GM.Repository(
name='testgit.git',
fs_path=repo_dir,
- url_path = '/test/',
- tool = 'git',
- status = 'creating')
+ url_path='/test/',
+ tool='git',
+ status='creating')
self.repo.refresh()
self.rev = self.repo.commit('HEAD')
ThreadLocalORMSession.flush_all()
@@ -517,7 +553,8 @@ class TestGitCommit(unittest.TestCase):
def test_url(self):
assert self.rev.url().endswith('ca4a/')
- assert self.repo._impl.url_for_commit('master').endswith('master/'), self.repo._impl.url_for_commit('master')
+ assert self.repo._impl.url_for_commit('master').endswith(
+ 'master/'), self.repo._impl.url_for_commit('master')
def test_committer_url(self):
assert self.rev.committer_url is None
@@ -530,9 +567,9 @@ class TestGitCommit(unittest.TestCase):
def test_diff(self):
diffs = (self.rev.diffs.added
- +self.rev.diffs.removed
- +self.rev.diffs.changed
- +self.rev.diffs.copied)
+ + self.rev.diffs.removed
+ + self.rev.diffs.changed
+ + self.rev.diffs.copied)
for d in diffs:
print d
@@ -540,30 +577,33 @@ class TestGitCommit(unittest.TestCase):
# path only
commits = list(self.repo.log(id_only=True))
assert_equal(commits, [
- "1e146e67985dcd71c74de79613719bef7bddca4a",
- "df30427c488aeab84b2352bdf88a3b19223f9d7a",
- "6a45885ae7347f1cac5103b0050cc1be6a1496c8",
- "9a7df788cf800241e3bb5a849c8870f2f8259d98",
- ])
+ "1e146e67985dcd71c74de79613719bef7bddca4a",
+ "df30427c488aeab84b2352bdf88a3b19223f9d7a",
+ "6a45885ae7347f1cac5103b0050cc1be6a1496c8",
+ "9a7df788cf800241e3bb5a849c8870f2f8259d98",
+ ])
commits = list(self.repo.log(self.repo.head, 'README', id_only=True))
assert_equal(commits, [
- "1e146e67985dcd71c74de79613719bef7bddca4a",
- "df30427c488aeab84b2352bdf88a3b19223f9d7a",
- ])
- commits = list(self.repo.log("df30427c488aeab84b2352bdf88a3b19223f9d7a", 'README', id_only=True))
+ "1e146e67985dcd71c74de79613719bef7bddca4a",
+ "df30427c488aeab84b2352bdf88a3b19223f9d7a",
+ ])
+ commits = list(
+ self.repo.log("df30427c488aeab84b2352bdf88a3b19223f9d7a", 'README', id_only=True))
assert_equal(commits, [
- "df30427c488aeab84b2352bdf88a3b19223f9d7a",
- ])
+ "df30427c488aeab84b2352bdf88a3b19223f9d7a",
+ ])
commits = list(self.repo.log(self.repo.head, '/a/b/c/', id_only=True))
assert_equal(commits, [
- "6a45885ae7347f1cac5103b0050cc1be6a1496c8",
- "9a7df788cf800241e3bb5a849c8870f2f8259d98",
- ])
- commits = list(self.repo.log("9a7df788cf800241e3bb5a849c8870f2f8259d98", '/a/b/c/', id_only=True))
+ "6a45885ae7347f1cac5103b0050cc1be6a1496c8",
+ "9a7df788cf800241e3bb5a849c8870f2f8259d98",
+ ])
+ commits = list(
+ self.repo.log("9a7df788cf800241e3bb5a849c8870f2f8259d98", '/a/b/c/', id_only=True))
assert_equal(commits, [
- "9a7df788cf800241e3bb5a849c8870f2f8259d98",
- ])
- commits = list(self.repo.log(self.repo.head, '/does/not/exist/', id_only=True))
+ "9a7df788cf800241e3bb5a849c8870f2f8259d98",
+ ])
+ commits = list(
+ self.repo.log(self.repo.head, '/does/not/exist/', id_only=True))
assert_equal(commits, [])
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeGit/forgegit/tests/test_git_app.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/test_git_app.py b/ForgeGit/forgegit/tests/test_git_app.py
index 5d745b4..0b59396 100644
--- a/ForgeGit/forgegit/tests/test_git_app.py
+++ b/ForgeGit/forgegit/tests/test_git_app.py
@@ -25,6 +25,7 @@ from alluratest.controller import setup_basic_test, setup_global_objects
from allura.lib import helpers as h
from forgegit.tests import with_git
+
class TestGitApp(unittest.TestCase):
def setUp(self):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeGit/forgegit/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/test_tasks.py b/ForgeGit/forgegit/tests/test_tasks.py
index 0f82c08..3f003d6 100644
--- a/ForgeGit/forgegit/tests/test_tasks.py
+++ b/ForgeGit/forgegit/tests/test_tasks.py
@@ -27,6 +27,7 @@ from allura.tasks import repo_tasks
from allura import model as M
from forgegit.tests import with_git
+
class TestGitTasks(unittest.TestCase):
def setUp(self):
@@ -52,7 +53,8 @@ class TestGitTasks(unittest.TestCase):
with mock.patch.object(c.app.repo, 'init_as_clone') as f:
c.app.config.options['init_from_path'] = 'test_path'
c.app.config.options['init_from_url'] = 'test_url'
- repo_tasks.reclone_repo(prefix='p', shortname='test', mount_point='src-git')
+ repo_tasks.reclone_repo(
+ prefix='p', shortname='test', mount_point='src-git')
M.main_orm_session.flush()
f.assert_called_with('test_path', None, 'test_url')
assert ns + 1 == M.Notification.query.find().count()
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeGit/setup.py
----------------------------------------------------------------------
diff --git a/ForgeGit/setup.py b/ForgeGit/setup.py
index 3d14ef3..ee01f0b 100644
--- a/ForgeGit/setup.py
+++ b/ForgeGit/setup.py
@@ -16,7 +16,8 @@
# under the License.
from setuptools import setup, find_packages
-import sys, os
+import sys
+import os
from forgegit.version import __version__
@@ -25,7 +26,8 @@ setup(name='ForgeGit',
description="",
long_description="""\
""",
- classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+ # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+ classifiers=[],
keywords='',
author='',
author_email='',
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/docs/conf.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/docs/conf.py b/ForgeImporters/docs/conf.py
index 07430a5..b19661b 100644
--- a/ForgeImporters/docs/conf.py
+++ b/ForgeImporters/docs/conf.py
@@ -28,18 +28,20 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
-import sys, os
+import sys
+import os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
-#sys.path.append(os.path.abspath('.'))
+# sys.path.append(os.path.abspath('.'))
-# -- General configuration -----------------------------------------------------
+# -- General configuration -----------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.ifconfig']
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx',
+ 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.ifconfig']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
@@ -104,7 +106,7 @@ pygments_style = 'sphinx'
#modindex_common_prefix = []
-# -- Options for HTML output ---------------------------------------------------
+# -- Options for HTML output ---------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
@@ -178,7 +180,7 @@ html_static_path = ['_static']
htmlhelp_basename = 'alluradoc'
-# -- Options for LaTeX output --------------------------------------------------
+# -- Options for LaTeX output --------------------------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
@@ -189,8 +191,8 @@ htmlhelp_basename = 'alluradoc'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
- ('index', 'allura.tex', u'allura Documentation',
- u'Cory Johns, Tim Van Steenburgh, Dave Brondsema', 'manual'),
+ ('index', 'allura.tex', u'allura Documentation',
+ u'Cory Johns, Tim Van Steenburgh, Dave Brondsema', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/base.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/base.py b/ForgeImporters/forgeimporters/base.py
index 922367d..9be397b 100644
--- a/ForgeImporters/forgeimporters/base.py
+++ b/ForgeImporters/forgeimporters/base.py
@@ -57,6 +57,7 @@ log = logging.getLogger(__name__)
class ProjectImportForm(schema.Schema):
+
def __init__(self, source):
super(ProjectImportForm, self).__init__()
provider = ProjectRegistrationProvider.get()
@@ -69,6 +70,7 @@ class ProjectImportForm(schema.Schema):
class ToolImportForm(schema.Schema):
+
def __init__(self, tool_class):
super(ToolImportForm, self).__init__()
self.add_field('mount_point', v.MountPointValidator(tool_class))
@@ -76,6 +78,7 @@ class ToolImportForm(schema.Schema):
class ImportErrorHandler(object):
+
def __init__(self, importer, project_name, project):
self.importer = importer
self.project_name = project_name
@@ -89,19 +92,19 @@ class ImportErrorHandler(object):
self.importer.clear_pending(self.project)
if exc_type:
g.post_event('import_tool_task_failed',
- error=str(exc_val),
- traceback=traceback.format_exc(),
- importer_source=self.importer.source,
- importer_tool_label=self.importer.tool_label,
- project_name=self.project_name,
- )
+ error=str(exc_val),
+ traceback=traceback.format_exc(),
+ importer_source=self.importer.source,
+ importer_tool_label=self.importer.tool_label,
+ project_name=self.project_name,
+ )
def success(self, app):
with h.push_config(c, project=self.project, app=app):
g.post_event('import_tool_task_succeeded',
- self.importer.source,
- self.importer.tool_label,
- )
+ self.importer.source,
+ self.importer.tool_label,
+ )
def object_from_path(path):
@@ -117,9 +120,10 @@ def object_from_path(path):
def import_tool(importer_path, project_name=None, mount_point=None, mount_label=None, **kw):
importer = object_from_path(importer_path)()
with ImportErrorHandler(importer, project_name, c.project) as handler,\
- M.session.substitute_extensions(M.artifact_orm_session, [M.session.BatchIndexer]):
- app = importer.import_tool(c.project, c.user, project_name=project_name,
- mount_point=mount_point, mount_label=mount_label, **kw)
+ M.session.substitute_extensions(M.artifact_orm_session, [M.session.BatchIndexer]):
+ app = importer.import_tool(
+ c.project, c.user, project_name=project_name,
+ mount_point=mount_point, mount_label=mount_label, **kw)
M.artifact_orm_session.flush()
M.session.BatchIndexer.flush()
if app:
@@ -127,6 +131,7 @@ def import_tool(importer_path, project_name=None, mount_point=None, mount_label=
class ProjectExtractor(object):
+
"""Base class for project extractors.
Subclasses should use :meth:`urlopen` to make HTTP requests, as it provides
@@ -147,7 +152,8 @@ class ProjectExtractor(object):
@staticmethod
def urlopen(url, retries=3, codes=(408,), **kw):
req = urllib2.Request(url, **kw)
- req.add_header('User-Agent', 'Allura Data Importer (https://forge-allura.apache.org/p/allura/)')
+ req.add_header(
+ 'User-Agent', 'Allura Data Importer (https://forge-allura.apache.org/p/allura/)')
return h.urlopen(req, retries=retries, codes=codes)
def get_page(self, page_name_or_url, parser=None, **kw):
@@ -175,7 +181,7 @@ class ProjectExtractor(object):
if parser is None:
parser = self.parse_page
self.page = self._page_cache[self.url] = \
- parser(self.urlopen(self.url))
+ parser(self.urlopen(self.url))
return self.page
def get_page_url(self, page_name, **kw):
@@ -185,7 +191,7 @@ class ProjectExtractor(object):
"""
return self.PAGE_MAP[page_name].format(
- project_name = urllib.quote(self.project_name), **kw)
+ project_name=urllib.quote(self.project_name), **kw)
def parse_page(self, page):
"""Transforms the result of a `urlopen` call before returning it from
@@ -205,6 +211,7 @@ class ProjectExtractor(object):
class ProjectImporter(BaseController):
+
"""
Base class for project importers.
@@ -264,16 +271,20 @@ class ProjectImporter(BaseController):
message indicating that some data will not be available immediately.
"""
try:
- c.project = self.neighborhood.register_project(kw['project_shortname'],
- project_name=kw['project_name'])
+ c.project = self.neighborhood.register_project(
+ kw['project_shortname'],
+ project_name=kw['project_name'])
except exceptions.ProjectOverlimitError:
- flash("You have exceeded the maximum number of projects you are allowed to create", 'error')
+ flash(
+ "You have exceeded the maximum number of projects you are allowed to create", 'error')
redirect('.')
except exceptions.ProjectRatelimitError:
- flash("Project creation rate limit exceeded. Please try again later.", 'error')
+ flash(
+ "Project creation rate limit exceeded. Please try again later.", 'error')
redirect('.')
except Exception:
- log.error('error registering project: %s', kw['project_shortname'], exc_info=True)
+ log.error('error registering project: %s',
+ kw['project_shortname'], exc_info=True)
flash('Internal Error. Please try again later.', 'error')
redirect('.')
@@ -314,6 +325,7 @@ class ProjectImporter(BaseController):
class ToolImporter(object):
+
"""
Base class for tool importers.
@@ -377,16 +389,16 @@ class ToolImporter(object):
limit = config.get('tool_import.rate_limit', 1)
pending_key = 'tool_data.%s.pending' % self.classname
modified_project = M.Project.query.find_and_modify(
- query={
- '_id': project._id,
- '$or': [
- {pending_key: None},
- {pending_key: {'$lt': limit}},
- ],
- },
- update={'$inc': {pending_key: 1}},
- new=True,
- )
+ query={
+ '_id': project._id,
+ '$or': [
+ {pending_key: None},
+ {pending_key: {'$lt': limit}},
+ ],
+ },
+ update={'$inc': {pending_key: 1}},
+ new=True,
+ )
return modified_project is not None
def clear_pending(self, project):
@@ -396,13 +408,13 @@ class ToolImporter(object):
"""
pending_key = 'tool_data.%s.pending' % self.classname
M.Project.query.find_and_modify(
- query={'_id': project._id},
- update={'$inc': {pending_key: -1}},
- new=True,
- )
+ query={'_id': project._id},
+ update={'$inc': {pending_key: -1}},
+ new=True,
+ )
def import_tool(self, project, user, project_name=None,
- mount_point=None, mount_label=None, **kw):
+ mount_point=None, mount_label=None, **kw):
"""
Override this method to perform the tool import.
@@ -450,12 +462,14 @@ class ToolImporter(object):
class ToolsValidator(fev.Set):
+
"""
Validates the list of tool importers during a project import.
This verifies that the tools selected are available and valid
for this source.
"""
+
def __init__(self, source, *a, **kw):
super(ToolsValidator, self).__init__(*a, **kw)
self.source = source
@@ -472,10 +486,13 @@ class ToolsValidator(fev.Set):
invalid.append(name)
if invalid:
pl = 's' if len(invalid) > 1 else ''
- raise fev.Invalid('Invalid tool%s selected: %s' % (pl, ', '.join(invalid)), value, state)
+ raise fev.Invalid('Invalid tool%s selected: %s' %
+ (pl, ', '.join(invalid)), value, state)
return valid
+
class ProjectToolsImportController(object):
+
'''List all importers available'''
@with_trailing_slash
@@ -503,24 +520,28 @@ class ProjectToolsImportController(object):
else:
raise exc.HTTPNotFound
+
class ImportAdminExtension(AdminExtension):
+
'''Add import link to project admin sidebar'''
project_admin_controllers = {'import': ProjectToolsImportController}
def update_project_sidebar_menu(self, sidebar_links):
base_url = c.project.url() + 'admin/ext/'
- link = SitemapEntry('Import', base_url+'import/')
+ link = SitemapEntry('Import', base_url + 'import/')
sidebar_links.append(link)
def stringio_parser(page):
return {
- 'content-type': page.info()['content-type'],
- 'data': StringIO(page.read()),
- }
+ 'content-type': page.info()['content-type'],
+ 'data': StringIO(page.read()),
+ }
+
class File(object):
+
def __init__(self, url, filename=None):
extractor = ProjectExtractor(None, url, parser=stringio_parser)
self.url = url
@@ -546,12 +567,13 @@ def get_importer_upload_path(project):
elif not project.is_root:
shortname = project.shortname.split('/')[0]
upload_path = config['importer_upload_path'].format(
- nbhd=project.neighborhood.url_prefix.strip('/'),
- project=shortname,
- c=c,
- )
+ nbhd=project.neighborhood.url_prefix.strip('/'),
+ project=shortname,
+ c=c,
+ )
return upload_path
+
def save_importer_upload(project, filename, data):
dest_path = get_importer_upload_path(project)
dest_file = os.path.join(dest_path, filename)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c93733ac/ForgeImporters/forgeimporters/forge/__init__.py
----------------------------------------------------------------------
diff --git a/ForgeImporters/forgeimporters/forge/__init__.py b/ForgeImporters/forgeimporters/forge/__init__.py
index 77505f1..144e298 100644
--- a/ForgeImporters/forgeimporters/forge/__init__.py
+++ b/ForgeImporters/forgeimporters/forge/__init__.py
@@ -14,4 +14,3 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-