Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

fixes #25 #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/patchbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from http_post_file import post_multipart

from trac import scrape, pull_from_trac
from trac import scrape, fetch_from_trac, merge_ticket, inplace_safe, clone_sandbox
from util import (now_str as datetime, prune_pending, do_or_die,
get_version, current_reports, git_commit, ConfigException)
import version as patchbot_version
Expand Down Expand Up @@ -189,13 +189,14 @@ def sha1file(path, blocksize=2**16):

class Patchbot:

def __init__(self, sage_root, server, config_path, dry_run=False, plugin_only=False):
def __init__(self, sage_root, server, config_path, dry_run=False, plugin_only=False, safe_only=False):
self.sage_root = sage_root
self.server = server
self.base = get_version(sage_root)
self.behind_base = {}
self.dry_run = dry_run
self.plugin_only = plugin_only
self.safe_only = safe_only
self.config_path = config_path
self.reload_config()
self.last_pull = 0
Expand Down Expand Up @@ -403,6 +404,14 @@ def test_a_ticket(self, ticket=None):
history = open("%s/history.txt" % self.log_dir, "a")
history.write("%s %s\n" % (datetime(), ticket['id']))
history.close()
if not ticket['spkgs']:
ticket_id = ticket['id']
fetch_from_trac(ticket_id)
ticket_is_safe = inplace_safe()
if self.safe_only and not ticket_is_safe:
print "Unsafe ticket and --safe-only set. Bailing out..."
time.sleep(10)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the extra sleep here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. When testing this I had the impression the server locked upon me.
But there appears to be a general delay of 5 min between failed tickets the
cause of which I haven't examined. It just seemed safe at the time.

On Tue, May 20, 2014 at 4:34 PM, Robert Bradshaw
[email protected]:

In src/patchbot.py:

@@ -403,6 +404,14 @@ def test_a_ticket(self, ticket=None):
history = open("%s/history.txt" % self.log_dir, "a")
history.write("%s %s\n" % (datetime(), ticket['id']))
history.close()

  •    if not ticket['spkgs']:
    
  •        ticket_id = ticket['id']
    
  •        fetch_from_trac(ticket_id)
    
  •        ticket_is_safe = inplace_safe()
    
  •        if self.safe_only and not ticket_is_safe:
    
  •            print "Unsafe ticket and --safe-only set. Bailing out..."
    
  •            time.sleep(10)
    

Why the extra sleep here?


Reply to this email directly or view it on GitHubhttps://github.com//pull/27/files#r12846649
.

return
if not self.plugin_only:
self.report_ticket(ticket, status='Pending', log=log)
plugins_results = []
Expand Down Expand Up @@ -432,7 +441,12 @@ def test_a_ticket(self, ticket=None):
os.environ['GIT_AUTHOR_NAME'] = os.environ['GIT_COMMITTER_NAME'] = 'patchbot'
os.environ['GIT_AUTHOR_EMAIL'] = os.environ['GIT_COMMITTER_EMAIL'] = 'patchbot@localhost'
os.environ['GIT_AUTHOR_DATE'] = os.environ['GIT_COMMITTER_DATE'] = '1970-01-01T00:00:00'
pull_from_trac(self.sage_root, ticket['id'], force=True, use_ccache=self.config['use_ccache'])
ticket_id = ticket['id']
if ticket_is_safe:
os.chdir(self.sage_root)
merge_ticket(ticket_id)
else:
clone_sandbox(ticket_id, use_ccache=self.config['use_ccache'])
t.finish("Apply")
state = 'applied'
if not self.plugin_only:
Expand Down Expand Up @@ -700,6 +714,7 @@ def main(args):
parser.add_option("--skip-base", action="store_true", dest="skip_base", default=False)
parser.add_option("--dry-run", action="store_true", dest="dry_run", default=False)
parser.add_option("--plugin-only", action="store_true", dest="plugin_only", default=False)
parser.add_option("--safe-only", action="store_true", dest="safe_only", default=False)
(options, args) = parser.parse_args(args)

conf_path = options.config and os.path.abspath(options.config)
Expand All @@ -710,7 +725,7 @@ def main(args):
tickets = None
count = int(options.count)

patchbot = Patchbot(os.path.abspath(options.sage_root), options.server, conf_path, dry_run=options.dry_run, plugin_only=options.plugin_only)
patchbot = Patchbot(os.path.abspath(options.sage_root), options.server, conf_path, dry_run=options.dry_run, plugin_only=options.plugin_only, safe_only=options.safe_only)

conf = patchbot.get_config()
if options.list:
Expand Down
56 changes: 34 additions & 22 deletions src/trac.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,62 +268,74 @@ def inplace_safe():
"""
safe = True
# TODO: Are removed files sufficiently cleaned up?
for file in subprocess.check_output(["git", "diff", "--name-only", "patchbot/base..patchbot/ticket_merged"]).split('\n'):
commit = subprocess.check_output(['git', 'merge-base', 'patchbot/base', 'patchbot/ticket_upstream']).split('\n')[0]
for file in subprocess.check_output(["git", "diff", "--name-only", "%s..patchbot/ticket_upstream" % commit]).split('\n'):
if not file:
continue
if file.startswith("src/sage") or file in ("src/setup.py", "src/module_list.py", "README.txt", ".gitignore"):
if file.startswith("src/sage") or file.startswith("src/doc") or file in ("src/setup.py", "src/module_list.py", "README.txt", ".gitignore"):
continue
else:
print "Unsafe file:", file
safe = False
return safe

def pull_from_trac(sage_root, ticket, branch=None, force=None, interactive=None, inplace=None, use_ccache=False):
def fetch_from_trac(ticket_id):
# There are four branches at play here:
# patchbot/base -- the latest release that all tickets are merged into for testing
# patchbot/base_upstream -- temporary staging area for patchbot/base
# patchbot/ticket_upstream -- pristine clone of the ticket on trac
# patchbot/ticket_merged -- merge of patchbot/ticket_upstream into patchbot/base
merge_failure = False
try:
ticket_id = ticket
info = scrape(ticket_id)
os.chdir(sage_root)
info = scrape(ticket_id)
do_or_die("git checkout patchbot/base")
if ticket_id == 0:
do_or_die("git branch -f patchbot/ticket_upstream patchbot/base")
do_or_die("git branch -f patchbot/ticket_merged patchbot/base")
return
branch = info['git_branch']
repo = info['git_repo']
do_or_die("git fetch %s +%s:patchbot/ticket_upstream" % (repo, branch))
do_or_die("git rev-list --left-right --count patchbot/base..patchbot/ticket_upstream")
do_or_die("git branch -f patchbot/ticket_merged patchbot/base")
except Exception, exn:
raise ConfigException, exn.message


def merge_ticket(ticket_id):
merge_failure = False
try:
if ticket_id == 0:
do_or_die("git branch -f patchbot/ticket_merged patchbot/base")
return
do_or_die("git branch -f patchbot/ticket_merged patchbot/base")
do_or_die("git checkout patchbot/ticket_merged")
try:
do_or_die("git merge -X patience patchbot/ticket_upstream")
except Exception:
do_or_die("git merge --abort")
merge_failure = True
raise
if not inplace_safe():
tmp_dir = tempfile.mkdtemp("-sage-git-temp-%s" % ticket_id)
do_or_die("git clone . '%s'" % tmp_dir)
os.chdir(tmp_dir)
os.symlink(os.path.join(sage_root, "upstream"), "upstream")
os.environ['SAGE_ROOT'] = tmp_dir
do_or_die("git branch -f patchbot/base remotes/origin/patchbot/base")
do_or_die("git branch -f patchbot/ticket_upstream remotes/origin/patchbot/ticket_upstream")
if use_ccache:
if not os.path.exists('logs'):
os.mkdir('logs')
do_or_die("./sage -i ccache")
except Exception, exn:
if merge_failure:
raise
else:
raise ConfigException, exn.message

def clone_sandbox(ticket_id, use_ccache=False):
try:
tmp_dir = tempfile.mkdtemp("-sage-git-temp-%s" % ticket_id)
do_or_die("git clone . '%s'" % tmp_dir)
os.chdir(tmp_dir)
fetch_from_trac(ticket_id)
merge_ticket(ticket_id)
os.symlink(os.path.join(os.environ['SAGE_ROOT'], "upstream"), "upstream")
os.environ['SAGE_ROOT'] = tmp_dir
do_or_die("git branch -f patchbot/base remotes/origin/patchbot/base")
do_or_die("git branch -f patchbot/ticket_upstream remotes/origin/patchbot/ticket_upstream")
if use_ccache:
if not os.path.exists('logs'):
os.mkdir('logs')
do_or_die("./sage -i ccache")
except Exception, exn:
raise Exception, exn.message

def push_from_trac(sage_root, ticket, branch=None, force=None, interactive=None):
raise NotImplementedError

Expand Down