Beispiel #1
0
def parseOptions(command, plugin_path):
	so, se, rc = runCommand("./gofed -p %s %s --help" % (plugin_path, command))
	if rc != 0:
		return []

	options = []
	option_f = False
	for line in so.split("\n"):
		if line == "Options:":
			option_f = True
			continue

		if option_f == True:
			if line == "":
				break

			# line must start with two spaces and minus
			if len(line) < 3:
				continue

			if line[:3] != "  -":
				continue

			line = line.strip()
			parts = line.split('  ')[0].split(',')

			if parts == []:
				continue

			# do we have both short and long options?
			opts = map(lambda i: i.strip().split(' ')[0].split('=')[0], parts)
			for opt in opts:
				options.append(opt)
			
	return sorted(options)
Beispiel #2
0
def updateSpec(spec, commit):
    so, se, rc = runCommand(
        "sed -i -e \"s/%%global commit\([[:space:]]\+\)[[:xdigit:]]\{40\}/%%global commit\\1%s/\" %s"
        % (commit, spec))
    if rc != 0:
        return False
    else:
        return True
Beispiel #3
0
def updateSpec(spec, commit):
    so, se, rc = runCommand(
        'sed -i -e "s/%%global commit\([[:space:]]\+\)[[:xdigit:]]\{40\}/%%global commit\\1%s/" %s' % (commit, spec)
    )
    if rc != 0:
        return False
    else:
        return True
Beispiel #4
0
def bumpSpec(spec, commit, last_bug_id):
	if last_bug_id != -1:
		cmd = "rpmdev-bumpspec --comment=\"$(echo \"Bump to upstream %s\n  related: #%s\")\" %s" % (commit, last_bug_id, spec)
	else:
		cmd = "rpmdev-bumpspec --comment=\"Bump to upstream %s\" %s" % (commit, spec)

	so, se, rc = runCommand(cmd)
	if rc != 0:
		return False
	else:
		return True
Beispiel #5
0
def updateSpec(spec, commit, repoprefix):
	if repoprefix == "":
		commit_macro = "commit"
	else:
		commit_macro = "%s_commit" % repoprefix
	cmd = "sed -i -e \"s/%%global %s\([[:space:]]\+\)[[:xdigit:]]\{40\}/%%global %s\\1%s/\" %s" % (commit_macro, commit_macro, commit, spec)

	so, se, rc = runCommand(cmd)
	if rc != 0:
		return False
	else:
		return True
Beispiel #6
0
def showGraph(graph, out_img = "./graph.png"):
	tmp_dir = tempfile.mkdtemp()
	f = open("%s/graph.dot" % (tmp_dir), "w")
	f.write(getGraphvizDotFormat(graph))
	f.close()
	# fdp -Tpng test.dot > test.png
	_, _, rc = runCommand("fdp -Tpng %s/graph.dot > %s" % (tmp_dir, out_img))
	if rc != 0:
		print "Unable to generate graph"
		return

	print "Graph saved to: %s\nYou can use eog %s to open it." % (out_img, out_img)
	# eog test.png
	shutil.rmtree(tmp_dir)
Beispiel #7
0
	archive_url = repository_info.getArchiveInfo().archive_url
	archive = repository_info.getArchiveInfo().archive
	printBasicInfo(url, commit, name, options.format)
	print ""

	# is the package already in Fedora
	fmt_obj.printProgress("(1/%s) Checking if the package already exists in PkgDB" % total)
	isPkgInPkgDB(name, options.force)

	# creating basic folder structure
	createBasicDirectories(name)

	# download tarball
	fmt_obj.printProgress("(2/%s) Downloading tarball" % total)
	downloadTarball(archive_url)
	so, se, rc = runCommand("tar -xf %s" % archive)
	if rc != 0:
		fmt_obj.printErr("Unable to extract %s" % archive)
		exit(1)

	# generate spec file
	fmt_obj.printProgress("(3/%s) Generating spec file" % total)

	if not pkg_obj.decodeProject(os.getcwd()):
		fmt_obj.printError(pkg_obj.getError())
		exit(1)

	spec = SpecGenerator(import_path, commit, skiperrors = options.skiperrors)
	spec.setPackageInfo(pkg_obj)

	try:
Beispiel #8
0
# for each command get its help
options = {}
for pl_name in cmd_list:
    options[pl_name] = {}
    bc_file = "%s/%s_bash_completion" % (gen_bash_completion_plugin_dir,
                                         pl_name)
    with open(bc_file, "w") as fd:
        fd.write("#\n")
        fd.write("#  Completion for %s plugin\n" % pl_name)
        fd.write("#\n")
        fd.write("#  List of commands\n")
        fd.write("pl_commands=\"%s\"\n" % " ".join(cmd_list[pl_name]))

        for cmd in cmd_list[pl_name]:
            fd.write("#  %s %s\n" % ('gofed', cmd))
            so, _, _ = runCommand("python parseOptions.py %s %s" %
                                  (cmd, plugin_dir))
            options[pl_name][cmd] = so.split("\n")[0].split(":")[1]
            if options[pl_name][cmd] == "":
                fd.write("%s_opts=\"#\"\n" % format_string(cmd))
            else:
                fd.write("%s_opts=\"%s\"\n" %
                         (format_string(cmd), options[pl_name][cmd]))

        fd.write("\n")

    print "# %s generated" % pl_name

# generate the main bash completion script
# generate header
fd = sys.stdout
fd.write("#\n")
Beispiel #9
0
def downloadTarball(archive_url):
	so, se, rc = runCommand("wget -nv %s --no-check-certificate" % archive_url)
	if rc != 0:		
		print "%sUnable to download tarball:\n%s%s" % (RED, se, ENDC)
		exit(1)
Beispiel #10
0
	archive_url = repository_info.getArchiveInfo().archive_url
	archive = repository_info.getArchiveInfo().archive
	printBasicInfo(url, commit, name, options.format)
	print ""

	# is the package already in Fedora
	fmt_obj.printProgress("(1/%s) Checking if the package already exists in PkgDB" % total)
	isPkgInPkgDB(name, options.force)

	# creating basic folder structure
	createBasicDirectories(name)

	# download tarball
	fmt_obj.printProgress("(2/%s) Downloading tarball" % total)
	downloadTarball(archive_url)
	so, se, rc = runCommand("tar -xf %s" % archive)
	if rc != 0:
		fmt_obj.printErr("Unable to extract %s" % archive)
		exit(1)

	# generate spec file
	fmt_obj.printProgress("(3/%s) Generating spec file" % total)

	if not pkg_obj.decodeProject(os.getcwd()):
		fmt_obj.printError(pkg_obj.getError())
		exit(1)

	spec = SpecGenerator(import_path, commit, skiperrors = options.skiperrors, with_build = options.withbuild)
	spec.setPackageInfo(pkg_obj)

	try:
Beispiel #11
0
def getSpec():
    so, se, rc = runCommand("ls *.spec")
    if rc != 0:
        return ""
    else:
        return so.strip().split(" ")[0]
Beispiel #12
0
def bumpSpec(spec, commit):
	so, se, rc = runCommand("rpmdev-bumpspec --comment=\"Bump to upstream %s\" %s" % (commit, spec))
	if rc != 0:
		return False
	else:
		return True
Beispiel #13
0
	else:
		tarball = "%s-%s.tar.gz" % (repo, commit[:7])

	# copy tarball to ~/rpmbuild/SOURCES
	print "Copying tarball %s to %s/rpmbuild/SOURCES" % (tarball, expanduser("~"))
	try:
		shutil.copyfile(tarball, '%s/rpmbuild/SOURCES/%s' % (expanduser("~"), tarball))
	except IOError, e:
		print "Unable to copy tarball %s: %s" % (tarball, e)
		exit(1)

	print ""

	# build spec file
	print "Building spec file using rpmbuild"
	so, se, rc = runCommand("rpmbuild -ba %s" % specfile)
	if rc != 0:
		print "  Build failed. Check build.log."
		print "  Error: %s" % se
		exit(1)

	builds = filter(lambda l: l.startswith("Wrote:"), so.split("\n"))
	builds = map(lambda l: l.split(" ")[1], builds)
	srpm = filter(lambda l: l.endswith("src.rpm"), builds)[0]

	for build in builds:
		print "  %s" % build
	print ""

	# rpmlint
	print "Running rpmlint %s" % " ".join(builds)
Beispiel #14
0
    content += "}\n"
    return content


def showGraph(graph, out_img="./graph.png"):
    tmp_dir = tempfile.mkdtemp()
    try:
        f = open("%s/graph.dot" % (tmp_dir), "w")
    except IOError, e:
        sys.stderr.write("%s\n" % e)
        return

    f.write(getGraphvizDotFormat(graph))
    f.close()
    # fdp -Tpng test.dot > test.png
    so, se, rc = runCommand("fdp -Tpng %s/graph.dot > %s" % (tmp_dir, out_img))
    if rc != 0 or se != "":
        if se != "":
            print se
            return
        print "Unable to generate graph"
        return

    print "Graph saved to: %s\nYou can use eog %s to open it." % (out_img,
                                                                  out_img)
    # eog test.png
    shutil.rmtree(tmp_dir)


def truncateGraph(graph, pkg_name, pkg_devel_main_pkg):
    """
Beispiel #15
0
def downloadTarball(archive_url):
	so, se, rc = runCommand("wget -nv %s --no-check-certificate" % archive_url)
	if rc != 0:		
		print "%sUnable to download tarball:\n%s%s" % (RED, se, ENDC)
		exit(1)
Beispiel #16
0
def getSpec():
	so, se, rc = runCommand("ls *.spec")
	if rc != 0:
		return ""
	else:
		return so.strip().split(" ")[0]
Beispiel #17
0
	parser.add_option(
	    "", "", "--repo-prefix", dest="repoprefix", default = "",
	    help = "Update tarball for repo macro prefixed with repo-prefix."
	)

	parser.add_option(
	    "", "", "--no-bump", dest="nobump", action="store_true", default = False,
	    help = "Don't bump spec file"
	)

	options, args = parser.parse_args()

	# must be on master branch
	if not options.skipmaster:
		so, se, rc = runCommand("git branch | grep '*' | sed 's/*//'")
		if rc != 0:
			print "Not in a git repository"
			exit(1)

		branch = so.split('\n')[0].strip()
		if branch != "master":
			print "Not on branch master"
			exit(1)

	# get spec file
	print "Searching for spec file"
	spec = getSpec()
	if spec == "":
		print "Unable to find spec file"
		exit(1)
Beispiel #18
0
		# copy patches if available
		for patch in glob("%s/*.patch" % spec_dir):
			print "Copying patch %s to %s/rpmbuild/SOURCES" % (patch, expanduser("~"))
			try:
				shutil.copyfile(patch, '%s/rpmbuild/SOURCES/%s' % (expanduser("~"), patch))
			except IOError, e:
				print "Unable to copy patch %s: %s" % (patch, e)
				exit(1)

		print ""

		# build spec file
		print "Building spec file using rpmbuild"
		if srpm_only:
			so, se, rc = runCommand("rpmbuild -bs %s" % specfile)
		else:
			so, se, rc = runCommand("rpmbuild -ba %s" % specfile)

		if rc != 0:
			print "  Build failed. Check build.log."
			print "  Error: %s" % se
			exit(1)

		# line with builds end with .rpm sufix and consists of two columns seperated by whitespace
		# in a form "text: pathtorpm.rpm"
		builds = filter(lambda l: l.endswith(".rpm") and len(l.split(" ")) == 2, so.split("\n"))
		builds = map(lambda l: l.split(" ")[1], builds)
		srpm = filter(lambda l: l.endswith("src.rpm"), builds)[0]

		for build in builds:
Beispiel #19
0
    # copy tarball to ~/rpmbuild/SOURCES
    print "Copying tarball %s to %s/rpmbuild/SOURCES" % (tarball,
                                                         expanduser("~"))
    try:
        shutil.copyfile(tarball,
                        '%s/rpmbuild/SOURCES/%s' % (expanduser("~"), tarball))
    except IOError, e:
        print "Unable to copy tarball %s: %s" % (tarball, e)
        exit(1)

    print ""

    # build spec file
    print "Building spec file using rpmbuild"
    so, se, rc = runCommand("rpmbuild -ba %s" % specfile)
    if rc != 0:
        print "  Build failed. Check build.log."
        print "  Error: %s" % se
        exit(1)

    builds = filter(lambda l: l.startswith("Wrote:"), so.split("\n"))
    builds = map(lambda l: l.split(" ")[1], builds)
    srpm = filter(lambda l: l.endswith("src.rpm"), builds)[0]

    for build in builds:
        print "  %s" % build
    print ""

    # rpmlint
    print "Running rpmlint %s" % " ".join(builds)
Beispiel #20
0
    parser.add_option(
        "",
        "",
        "--skip-checks",
        dest="skipchecks",
        action="store_true",
        default=False,
        help="Skip checks for tags and releases.",
    )

    options, args = parser.parse_args()

    # must be on master branch
    if not options.skipmaster:
        so, se, rc = runCommand("git branch | grep '*' | sed 's/*//'")
        if rc != 0:
            print "Not in a git repository"
            exit(1)

        branch = so.split("\n")[0].strip()
        if branch != "master":
            print "Not on branch master"
            exit(1)

            # get spec file
    print "Searching for spec file"
    spec = getSpec()
    if spec == "":
        print "Unable to find spec file"
        exit(1)
Beispiel #21
0
# for each command get its help
options = {}
for pl_name in cmd_list:
	options[pl_name] = {}
	bc_file = "%s/%s_bash_completion" % (gen_bash_completion_plugin_dir, pl_name)
	with open(bc_file, "w") as fd:
		fd.write("#\n")
		fd.write("#  Completion for %s plugin\n" % pl_name)
		fd.write("#\n")
		fd.write("#  List of commands\n")
		fd.write("pl_commands=\"%s\"\n" % " ".join(cmd_list[pl_name]))
	
		for cmd in cmd_list[pl_name]:
			fd.write("#  %s %s\n" % ('gofed', cmd))
			so, _, _ = runCommand("python parseOptions.py %s %s" % (cmd, plugin_dir))
			options[pl_name][cmd] = so.split("\n")[0].split(":")[1]
			if options[pl_name][cmd] == "":
				fd.write("%s_opts=\"#\"\n" % format_string(cmd))
			else:
				fd.write("%s_opts=\"%s\"\n" % (format_string(cmd), options[pl_name][cmd]))

		fd.write("\n")

	print "# %s generated" % pl_name

# generate the main bash completion script
# generate header
fd = sys.stdout
fd.write("#\n")
fd.write("#  Completion for %s:\n" % pkg_name)
Beispiel #22
0
	content += "}\n"
	return content

def showGraph(graph, out_img = "./graph.png"):
	tmp_dir = tempfile.mkdtemp()
	try:
		f = open("%s/graph.dot" % (tmp_dir), "w")
	except IOError, e:
		sys.stderr.write("%s\n" % e)
		return

	f.write(getGraphvizDotFormat(graph))
	f.close()
	# fdp -Tpng test.dot > test.png
	so, se, rc = runCommand("fdp -Tpng %s/graph.dot > %s" % (tmp_dir, out_img))
	if rc != 0 or se != "":
		if se != "":
			print se
			return
		print "Unable to generate graph"
		return

	print "Graph saved to: %s\nYou can use eog %s to open it." % (out_img, out_img)
	# eog test.png
	shutil.rmtree(tmp_dir)

def truncateGraph(graph, pkg_name, pkg_devel_main_pkg):
	"""
	Return graph containing only pkg_name and all its dependencies
	"""