import optparse
import os
import re
-import shutil
import signal
import stat
import sys
import time
from commands import getstatusoutput
-from fileinput import input
-from grp import getgrnam
from itertools import izip
from stat import S_ISDIR, ST_CTIME
portage.dep._dep_check_strict = True
import portage.exception
from portage import cvstree, normalize_path
+from portage import util
from portage.exception import ParseError
from portage.manifest import Manifest
from portage.process import find_binary, spawn
-from portage.util import initialize_logger
from portage.output import bold, create_color_func, darkgreen, \
green, nocolor, red, turquoise, yellow
from portage.output import ConsoleStyleFile, StyleWriter
-initialize_logger()
+util.initialize_logger()
# 14 is the length of DESCRIPTION=""
max_desc_len = 100
'fix' : 'Fix simple QA issues (stray digests, missing digests)',
'full' : 'Scan directory tree and print all issues (not a summary)',
'help' : 'Show this screen',
- 'last' : 'Remember report from last ru',
+ 'last' : 'Remember report from last run',
'lfull' : 'Remember report from last run (full listing)',
'manifest' : 'Generate a Manifest (fetches files if necessary)',
'scan' : 'Scan directory tree for QA issues'
qawarnings.append(x)
valid_restrict = frozenset(["binchecks", "bindist",
- "fetch", "installsources", "mirror",
+ "fetch", "installsources", "mirror",
"primaryuri", "strip", "test", "userpriv"])
# file.executable
no_exec = frozenset(["Manifest","ChangeLog","metadata.xml"])
-def editor_is_executable(editor):
- """
- Given an EDITOR string, validate that it refers to
- an executable. This uses shlex.split() to split the
- first component and do a PATH lookup if necessary.
-
- @param editor: An EDITOR value from the environment.
- @type: string
- @rtype: bool
- @returns: True if an executable is found, False otherwise.
- """
- import shlex
- editor_split = shlex.split(editor)
- if not editor_split:
- return False
- filename = editor_split[0]
- if not os.path.isabs(filename):
- return find_binary(filename) is not None
- return os.access(filename, os.X_OK) and os.path.isfile(filename)
-
-def get_commit_message_with_editor(editor, message=None):
- """
- Execute editor with a temporary file as it's argument
- and return the file content afterwards.
-
- @param editor: An EDITOR value from the environment
- @type: string
- @param message: An iterable of lines to show in the editor.
- @type: iterable
- @rtype: string or None
- @returns: A string on success or None if an error occurs.
- """
- from tempfile import mkstemp
- fd, filename = mkstemp()
- try:
- os.write(fd, "\n# Please enter the commit message " + \
- "for your changes.\n# (Comment lines starting " + \
- "with '#' will not be included)\n")
- if message:
- os.write(fd, "#\n")
- for line in message:
- os.write(fd, "#" + line)
- os.close(fd)
- retval = os.system(editor + " '%s'" % filename)
- if not (os.WIFEXITED(retval) and os.WEXITSTATUS(retval) == os.EX_OK):
- return None
- try:
- mylines = open(filename).readlines()
- except OSError, e:
- if e.errno != errno.ENOENT:
- raise
- del e
- return None
- return "".join(line for line in mylines if not line.startswith("#"))
- finally:
- try:
- os.unlink(filename)
- except OSError:
- pass
-
-def get_commit_message_with_stdin():
- """
- Read a commit message from the user and return it.
-
- @rtype: string or None
- @returns: A string on success or None if an error occurs.
- """
- print "Please enter a commit message. Use Ctrl-d to finish or Ctrl-c to abort."
- commitmessage = []
- while True:
- commitmessage.append(sys.stdin.readline())
- if not commitmessage[-1]:
- break
- commitmessage = "".join(commitmessage)
- return commitmessage
-
-def format_qa_output(f, stats, fails, dofull, dofail):
- full = options.mode in ("full", "lfull")
- for x in qacats:
- if not stats[x]:
- continue
- f.add_literal_data(" " + x.ljust(30))
- if x in qawarnings:
- f.push_style("WARN")
- else:
- f.push_style("BAD")
- f.add_literal_data(str(stats[x]))
- f.pop_style()
- f.add_line_break()
- if not dofull:
- if not full and dofail and x in qawarnings:
- # warnings are considered noise when there are failures
- continue
- fails_list = fails[x]
- if not full and len(fails_list) > 12:
- fails_list = fails_list[:12]
- for y in fails_list:
- f.add_literal_data(" "+y)
- f.add_line_break()
def last(full=False):
"""Print the results of the last repoman run
console_writer = StyleWriter(file=style_file, maxcol=9999)
console_writer.style_listener = style_file.new_styles
f = formatter.AbstractFormatter(console_writer)
- format_qa_output(f, stats, fails, dofull, dofail)
+ utilities.format_qa_output(f, stats, fails, dofull, dofail, options, qawarnings)
print
if dofull:
print bold("Note: type \"repoman lfull\" for a complete listing of repomans last run.")
#this can be problematic if xmllint changes their output
xmllint_capable=True
-if options.mode == 'commit':
- retval = ("","")
- if isCvs:
- print
- print "Performing a " + green("cvs -n up") + \
- " with a little magic grep to check for updates."
- retval = getstatusoutput("/usr/bin/cvs -n up 2>&1 | " + \
- "egrep '^[^\?] .*' | " + \
- "egrep -v '^. .*/digest-[^/]+|^cvs server: .* -- ignored$'")
-
- mylines = retval[1].splitlines()
- myupdates = []
- for x in mylines:
- if not x:
- continue
- if x[0] not in "UPMAR": # Updates,Patches,Modified,Added,Removed
- print red("!!! Please fix the following issues reported " + \
- "from cvs: ")+green("(U,P,M,A,R are ok)")
- print red("!!! Note: This is a pretend/no-modify pass...")
- print retval[1]
- print
- sys.exit(1)
- elif x[0] in "UP":
- myupdates.append(x[2:])
-
- if myupdates:
- print green("Fetching trivial updates...")
- if options.pretend:
- print "(/usr/bin/cvs up "+" ".join(myupdates)+")"
- retval = os.EX_OK
- else:
- retval = os.system("/usr/bin/cvs up " + " ".join(myupdates))
- if retval != os.EX_OK:
- print "!!! cvs exited with an error. Terminating."
- sys.exit(retval)
+if options.mode == 'commit' and isCvs:
+ utilties.detect_vcs_conflicts(options, vcs="cvs")
if options.mode == "manifest":
pass
f = formatter.AbstractFormatter(console_writer)
-format_qa_output(f, stats, fails, dofull, dofail)
+utilities.format_qa_output(f, stats, fails, dofull, dofail, options, qawarnings)
style_file.flush()
del console_writer, f, style_file
if not commitmessage or not commitmessage.strip():
try:
editor = os.environ.get("EDITOR")
- if editor and editor_is_executable(editor):
- commitmessage = get_commit_message_with_editor(
+ if editor and utilities.editor_is_executable(editor):
+ commitmessage = utilties.get_commit_message_with_editor(
editor, message=qa_output)
else:
- commitmessage = get_commit_message_with_stdin()
+ commitmessage = utilties.get_commit_message_with_stdin()
except KeyboardInterrupt:
exithandler()
if not commitmessage or not commitmessage.strip():