common: Incorporate old scripts, add bump for pspec packages

This commit is contained in:
Ikey Doherty 2015-06-14 17:09:58 +01:00
parent 274958788a
commit 75b57e5e57
17 changed files with 1336 additions and 12 deletions

View file

@ -1,4 +1,5 @@
SHELL = /bin/bash
TOPLVL = "../."
build:
if [[ -e pspec.xml ]]; then \
@ -7,9 +8,6 @@ build:
sudo evobuild build package.yml -p unstable-x86_64; \
fi;
.PHONY:
build
cvecheck:
if [[ -e pspec.xml ]]; then \
cve-check-tool pspec.xml; \
@ -17,6 +15,19 @@ cvecheck:
cve-check-tool package.yml; \
fi;
bump:
if [[ -e pspec.xml ]]; then \
$(TOPLVL)/common/Scripts/pbump.py pspec.xml; \
else \
python /usr/share/ypkg/ybump.py package.yml; \
fi;
clean:
if [[ `ls *.eopkg` ]]; then \
rm *.eopkg -fv; \
fi;
help:
@echo "build - Build the current package"
@echo "bump - Bump current release"
@ -24,12 +35,5 @@ help:
@echo "clean - Clean current tree"
bump:
if [[ -e package.yml ]]; then \
python /usr/share/ypkg/ybump.py package.yml; \
fi;
clean:
if [[ `ls *.eopkg` ]]; then \
rm *.eopkg -fv; \
fi;
.PHONY:
build

32
common/Scripts/README.md Normal file
View file

@ -0,0 +1,32 @@
SolusOS Package Helper Scripts
==============================
These scripts are really simple and will help you to create PiSi packages
for SolusOS much faster.
Creating a package
------------------
mkdir PKGNAME
cd PKGNAME
autopackage.py $URLOFPACKAGE
Two files should be created in the current directory, the pspec.xml and actions.py
Customise to your needs, and fill in the blanks. A good practice is to fist build
the package without the <Path> sections complete, and run "lspisi" against the .pisi
package, and then fill in the <Path>'s :) You can save time by doing:
pisi build pspec.xml --package
Completing the dependencies
---------------------------
This one is real simple. It outputs all of the **binary** package dependencies it
can find. It will not find all! But it helps :) It will also attempt to add the
relevant -devel build-deps.
dep_check.py name_of_installed_pisi_package
Notes
-----
You should add this Scripts directory to your path for ease-of-use :)
Feel free to report bugs on Maniphest

294
common/Scripts/autopackage.py Executable file
View file

@ -0,0 +1,294 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# yauto.py
#
# Copyright 2013 Ikey Doherty <ikey@solusos.com>
# Copyright 2015 Ikey Doherty <iikey@solus-project.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
import os
import sys
import os.path
import dloader
import datetime
import shutil
from configobj import ConfigObj
''' Example config file
~/.evolveos/packager
[Packager]
Name=Your Name Goes Here
Email=Your Email Goes Here
'''
# What we term as needed doc files
KnownDocFiles = [ "COPYING", "COPYING.LESSER", "ChangeLog", "COPYING.GPL", "AUTHORS", "BUGS", "CHANGELOG", "LICENSE"]
# Compile type to build 'actions.py'
GNOMEY = 1
AUTOTOOLS = 2
CMAKE = 3
PYTHON_MODULES = 4
PERL_MODULES = 5
class DepObject:
name = None
version = None
class AutoPackage:
package_prefix = ""
def __init__(self, uri):
self.package_uri = uri
homeDir = os.environ ["HOME"]
config = ".evolveos/packager"
self.config_dir = os.path.join (homeDir, config)
if not os.path.exists (self.config_dir):
print "Config file not found at %s" % self.config_dir
sys.exit (-1)
# See the above commentary for details on the file format
self.config = ConfigObj (self.config_dir)
self.email = self.config["Packager"]["Email"]
self.packager_name = self.config["Packager"]["Name"]
# Templates
us = os.path.dirname(os.path.abspath(__file__))
base_dir = "/".join (us.split ("/")[:-1])
self.template_dir = os.path.join (base_dir, "Templates")
self.build_deps = list()
self.doc_files = list()
def verify (self):
print "Verifying %s" % self.package_uri
self.file_name = self.package_uri.split ("/")[-1]
self.file_name_full = os.path.abspath (self.file_name)
print self.file_name
try:
dloader.download_file (self.package_uri)
self.sha1sum = dloader.get_sha1sum (self.file_name)
except Exception, e:
print e
return False
return True
def examine_source (self):
splits = self.file_name.split (".")
suffix = "".join(splits [-2:]).replace ("bzip2", "bz2")
# Find out pspec file type
if suffix.endswith ("zip"):
suffix = "zip"
self.file_type = suffix
# Work out the version number
path,ext = os.path.splitext (self.file_name)
version = path.split ("-")[-1].split(".")[:-1]
version_string = ".".join(version)
self.version_string = version_string
# Package name, including hyphens
self.package_name = "-".join(path.split("-")[:-1])
self.compile_type = None
print "Package: %s\nVersion: %s" % (self.package_name, self.version_string)
print "SHA1 Sum: %s" % self.sha1sum
# Set up temporary
self.temp_dir = os.path.abspath ("./TEMP")
os.mkdir (self.temp_dir)
self.current_dir = os.getcwd ()
os.chdir (self.temp_dir)
os.system ("tar xf \"%s\"" % self.file_name_full)
known_types = list()
# Check for certain files..
for root,dirs,files in os.walk (os.getcwd ()):
depth = root[len(path) + len(os.path.sep):].count(os.path.sep)
if depth == 3:
print "bailing"
# We're currently two directories in, so all subdirs have depth 3
dirs[:] = [] # Don't recurse any deeper
for file in files:
if file in KnownDocFiles:
# Append files for pisitools.dodoc ()
if file not in self.doc_files:
self.doc_files.append (file)
print "Added %s" % file
if "configure.ac" in file:
# Examine this fella for build deps
self.build_deps = self.check_build_deps(os.path.join(root, file))
if "configure" in file:
# Check if we need to employ certain hacks needed in gnome packages
fPath = os.path.join (root, file)
print "Checking %s for use of g-ir-scanner" % fPath
if self.check_is_gnomey (fPath):
known_types.append(GNOMEY)
else:
known_types.append(AUTOTOOLS)
if "CMakeLists.txt" in file:
# This will use the actions with cmake
known_types.append(CMAKE)
if "setup.py" in file:
# this is a python module.
known_types.append(PYTHON_MODULES)
if "Makefile.PL" in file:
# This is a perl module
known_types.append(PERL_MODULES)
# We may have hit several systems..
if CMAKE in known_types:
print "cmake"
self.compile_type = CMAKE
elif GNOMEY in known_types:
print "gnomey"
self.compile_type = GNOMEY
elif AUTOTOOLS in known_types:
print "autotools"
self.compile_type = AUTOTOOLS
elif PYTHON_MODULES in known_types:
print "python"
self.compile_type = PYTHON_MODULES
self.package_prefix = "python"
elif PERL_MODULES in known_types:
print "perl"
self.compile_type = PERL_MODULES
self.package_prefix = "perl"
else:
print "unknown"
# Clean up on aisle 3
os.chdir (self.current_dir)
shutil.rmtree (self.temp_dir)
# Always delete
if os.path.exists (self.file_name):
os.remove (self.file_name)
def check_build_deps(self, path):
deps = list()
with open(path, "r") as read:
for line in read.readlines():
line = line.replace("\n","").replace("\r","").strip()
# Currently only handles configure.ac
if "PKG_CHECK_MODULES" in line:
part = line.split(",")[1]
part = part.replace("[","").replace(")","").replace("]","")
splits = part.split(">=")
pkg = splits[0].strip()
dep = DepObject()
dep.name = pkg
if len(splits) > 1:
version = splits[1].strip()
# Can happen, we don't handle variable expansion.
if "$" in version:
continue
dep.version = version
# Check it hasn't been added
objs = [x for x in deps if x.name == dep.name]
if len(objs) == 0:
deps.append(dep)
return deps
def create_pspec (self):
''' Now the interesting stuff happens. We'll create a pspec.xml automagically :) '''
sample_pspec = os.path.join (self.template_dir, "pspec.sample.xml")
self.package_name = self.package_name if self.package_prefix == "" else "%s-%s" % (self.package_prefix, self.package_name)
self.package_name = self.package_name.lower()
date = datetime.datetime.now().strftime ("%m-%d-%Y")
deps = ""
for dep in self.build_deps:
depStr = ""
if dep.version is not None:
depStr = "<Dependency type=\"pkgconfig\" versionFrom=\"%s\">%s</Dependency>" % (dep.version, dep.name)
else:
depStr = "<Dependency type=\"pkgconfig\">%s</Dependency>" % dep.name
deps += " %s\n" % depStr
deps = deps.replace("\n\n","\n")
with open (sample_pspec, "r") as sample:
mapping = { 'PackagerName' : self.packager_name, \
'PackagerEmail' : self.email, \
'PackageName' : self.package_name, \
'Summary': 'Add summary', \
'Description': 'Add description', \
'License': 'GPLv2+', \
'HashSum': self.sha1sum, \
'ArchiveType': self.file_type, \
'ArchiveURI': self.package_uri, \
'Date': date, \
'Version': self.version_string, \
'BuildDeps': deps}
lines = sample.read () % mapping
with open ("pspec.xml", "w") as pspec:
pspec.write (lines)
pspec.flush ()
def create_actions (self):
''' Create actions.py '''
if self.compile_type == GNOMEY:
sample_actions = os.path.join (self.template_dir, "actions.gnome.sample.py")
elif self.compile_type == AUTOTOOLS:
sample_actions = os.path.join (self.template_dir, "actions.sample.py")
elif self.compile_type == CMAKE:
sample_actions = os.path.join (self.template_dir, "actions.cmake.sample.py")
elif self.compile_type == PYTHON_MODULES:
sample_actions = os.path.join (self.template_dir, "actions.pythonmodules.sample.py")
elif self.compile_type == PERL_MODULES:
sample_actions = os.path.join (self.template_dir, "actions.perlmodules.sample.py")
elif self.compile_type == None:
sample_actions = os.path.join (self.template_dir, "actions.sample.py")
doc_str = ""
if len(self.doc_files) > 0:
doc_str = "pisitools.dodoc("
for doc in self.doc_files:
if doc == self.doc_files[-1]:
doc_str += "\"%s\"" % doc
else:
doc_str += "\"%s\", " % doc
doc_str += ")"
with open (sample_actions, "r") as sample:
lines = sample.read ().replace ("#EXTRADOCS#", doc_str)
# Write out the actions.py
with open ("actions.py", "w") as actions:
actions.write (lines)
actions.flush ()
def check_is_gnomey (self, path):
with open (path, "r") as makefile:
lines = makefile.read ()
if "g-ir-scanner" in lines or "g_ir_scanner" in lines:
return True
return False
if __name__ == "__main__":
if len (sys.argv) < 2:
print "%s: <URI>" % sys.argv[0]
sys.exit (-1)
p = AutoPackage (sys.argv[1])
if not p.verify ():
print "Unable to locate given URI"
else:
print "Completed verification"
p.examine_source ()
p.create_pspec ()
p.create_actions ()

108
common/Scripts/dep_check.py Executable file
View file

@ -0,0 +1,108 @@
#!/usr/bin/env python
import pisi.api
import commands
import sys
import os
blacklist = ('/lib/linux-gate.','/lib/libm.', '/lib/ld-linux.', '/lib/libc.', '/lib/librt.', 'linux-gate.so.1', '/lib/libpthread.', '/lib/libdl.')
def package_for_file (filename):
return pisi.api.search_file (filename)
def blacklisted (filename):
if not filename.startswith("/"):
filename = "/%s" % filename
for f in blacklist:
if f in filename:
return True
return False
def ldd (filename):
if "usr/share" in filename:
return
ldd = commands.getoutput ("ldd %s" % filename)
for line in ldd.split ("\n"):
line = line.replace("\n","").replace("\r","").strip()
if line == "":
continue
splits = line.split ("=>")
sourceLib = splits[0].strip()
if len(splits) > 1:
sourceLib = splits[1].strip().split (" ")[0]
else:
sourceLib = sourceLib.split (" ")[0].strip()
# Skip blacklisted
if blacklisted (sourceLib):
continue
if os.path.exists (sourceLib):
dep = package_for_file (sourceLib)
if len(dep) > 0:
# Circular dependencies are ugly :p
if dep[0][0] == sys.argv[1]:
break
# Check its not accounted for
if not dep[0][0] in dependsOn:
dependsOn[ dep[0][0] ] = "/%s" % dep [0][1][0]
if __name__ == "__main__":
if len(sys.argv) != 2:
print "Usage: %s package_name" % sys.argv[0]
sys.exit (1)
pkg = sys.argv[1]
try:
meta,files,other = pisi.api.info_name (pkg, True)
except:
print "Could not find package: %s" % pkg
sys.exit (1)
dependsOn = dict()
for file in files.list:
filename = file.path
if not filename.startswith("/"):
filename = "/%s" % filename
if hasattr(file, 'type'):
if file.type == "executable":
ldd (filename)
elif file.type == "library" and ".so" in filename:
ldd (filename)
else:
if ".so" in filename:
ldd (filename)
print "[ Dependencies ]"
for dep in dependsOn:
print "Depends on %s from %s" % (dependsOn[dep], dep)
print "\n[ XML Dependencies ]"
print "<RuntimeDependencies>"
for dep in dependsOn:
print " <Dependency>%s</Dependency>" % dep
print "</RuntimeDependencies>"
# Suggest build dependencies
print "\n[XML Build Dependencies]"
print "<BuildDependencies>"
for dep in dependsOn:
package = "%s-devel" % dep
try:
subject = pisi.api.info_name (package, True)
print " <Dependency>%s</Dependency>" % package
except:
print " <!-- Info: no %s package - consider splitting -->" % package
print "</BuildDependencies>"

32
common/Scripts/distrocheck.py Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python
import pisi.db.packagedb
import pisi.config
if __name__ == "__main__":
config = pisi.config.Config()
distro = config.values.general.distribution
db = pisi.db.packagedb.PackageDB()
bads = dict()
goods = dict()
for pkgname in db.list_packages(None):
pkg = db.get_package(pkgname)
pdistro = pkg.distribution
if pdistro != distro:
src = pkg.source.name
if src not in bads:
bads[src] = list()
bads[src].append(pkg.name)
else:
src = pkg.source.name
if src not in goods:
goods[src] = list()
goods[src].append(pkg.name)
binCount = 0
for src in bads:
binCount += len(bads[src])
print "%s - %s packages" % (src, len(bads[src]))
print
top = len(bads.keys()) + len(goods.keys())
print "%s of %s source packages have an incorrect distribution string (%s binary)" % (len(bads.keys()), top, binCount)
print "%s have the correct distribution string" % len(goods.keys())
print "Progress: %0.2f%%" % ((float(len(goods.keys())) / float(top))*100)

72
common/Scripts/dloader.py Normal file
View file

@ -0,0 +1,72 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# yauto.py
#
# Copyright 2013 Ikey Doherty <ikey@solusos.com>
# Copyright 2015 Ikey Doherty <iikey@solus-project.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
import urllib2
import hashlib
def download_file(url):
file_name = url.split('/')[-1]
output = file_name
u = urllib2.urlopen(url)
f = open(output, 'wb')
meta = u.info()
headers = meta.getheaders("Content-Length")
file_size = 0
if len(headers) >= 1:
file_size = int(headers[0])
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
if file_size > 0:
status = r" [%3.2f%%] %s/%s %s" % (file_size_dl * 100. / file_size, sizeof_fmt(file_size_dl), sizeof_fmt(file_size), file_name)
else:
status = r" %s/unknown_size %s" % (sizeof_fmt(file_size_dl), file_name)
status = status + chr(8)*(len(status)+1)
print status,
print "\n"
f.close()
def sizeof_fmt(num):
for x in ['bytes','KB','MB','GB']:
if num < 1024.0:
return "%3.1f%s" % (num, x)
num /= 1024.0
return "%3.1f%s" % (num, 'TB')
def get_sha256sum (filename):
sh = hashlib.sha256 ()
f = open (filename, "r")
sh.update (f.read())
ret = sh.hexdigest ()
f.close ()
return ret
def get_sha1sum (filename):
sh = hashlib.sha1 ()
f = open (filename, "r")
sh.update (f.read())
ret = sh.hexdigest ()
f.close ()
return ret

126
common/Scripts/ep-update.py Executable file
View file

@ -0,0 +1,126 @@
#!/usr/bin/env python
# ep-update.py: Update a package using a tarball
#
# USAGE: ep-update.py VERSION UPSTREAM_URL
# Copyright 2015 Ikey Doherty <iikey@solus-project.com>
#
# WARNING: Not well tested, strips comments, and reorders attributes. Crap error handling
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
import xml.etree.ElementTree as ET
import sys
import os
import xml.dom.minidom as minidom
import datetime
import commands
from configobj import ConfigObj
''' Example config file
~/.evolveos/packager
[Packager]
Name=Your Name Goes Here
Email=Your Email Goes Here
'''
if __name__ == "__main__":
#if len(sys.argv) != 2:
# print "Not enough arguments - aborting"
# sys.exit(1)
homeDir = os.environ ["HOME"]
config = ".evolveos/packager"
config_p = os.path.join(homeDir, config)
if not os.path.exists(config_p):
print "Config file not found at %s" % config_p
sys.exit (1)
config = ConfigObj(config_p)
newname = config["Packager"]["Name"]
newemail = config["Packager"]["Email"]
if not os.path.exists("pspec.xml"):
print "pspec.xml doesn\'t exist - aborting"
sys.exit(1)
url = sys.argv[2]
file = url.split("/")[-1]
newversion = sys.argv[1]
r = 0
try:
r = os.system("wget \"%s\"" % url)
except:
print "Failed to download file"
sys.exit(1)
if r != 0:
print "Failed to download file"
sys.exit(1)
sha1 = commands.getoutput("sha1sum %s" % file).split()[0].strip()
mapping = dict()
mapping["tar.bz2"] = "tarbz2"
mapping["tbz2"] = "tarbz"
mapping["tar.xz"] = "tarxz"
mapping["txz"] = "tarxz"
mapping["tar.gz" ] = "targz"
mapping["tgz"] = "targz"
mapping["zip"] = "zip"
extype = ".".join(url.split(".")[-2:])
if extype in mapping:
extension = mapping[extype]
elif extype.endswith("tar"):
extension = "tar"
else:
extension = "binary"
tree = ET.parse("pspec.xml")
root = tree.getroot()
archive = root.findall("Source/Archive")[0]
archive.attrib['sha1sum'] = sha1
archive.attrib['type'] = extension
archive.text = url
hist = root.findall("History")
last_update = hist[0].findall("Update")[0]
rel = int(last_update.attrib['release'])
# 10-06-2014
d = datetime.date.today()
f = d.strftime('%m-%d-%Y')
# normal shmaz.
rel += 1
newrel = ET.Element("Update")
newrel.tail = "\n\n "
newrel.text = "\n "
hist[0].insert(0, newrel)
ent = ET.SubElement(newrel, "Date")
ent.tail = "\n "
ent.text = f
ent = ET.SubElement(newrel, "Version")
ent.tail = "\n "
ent.text = newversion
ent = ET.SubElement(newrel, "Comment")
ent.tail = "\n "
ent.text = "Update to %s" % (newversion)
newrel.attrib['release'] = str(rel)
ent = ET.SubElement(newrel, "Name")
ent.tail = "\n "
ent.text = newname
ent = ET.SubElement(newrel, "Email")
ent.text = newemail
ent.tail = "\n "
s = ET.tostring(root, 'utf-8').replace("\r\n", "\n").replace("\t", " ")
complete = "<?xml version=\"1.0\" ?>\n<!DOCTYPE PISI SYSTEM \"https://solus-project.com/standard/pisi-spec.dtd\">\n" + s
os.unlink(file)
with open ("pspec.xml", "w") as output:
output.writelines(complete)
print "Now please build to verify your changes"

41
common/Scripts/epcsearch.py Executable file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# epcsearch.py - find pkg-config names
#
# Copyright 2015 Ikey Doherty <ikey@solus-project.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
import os
import sys
import pisi
def usage(ext=1):
print "Usage: %s [pkg-config names]" % sys.argv[0]
sys.exit(ext)
def main():
if len(sys.argv) < 2:
usage(0)
pcs = sys.argv[1:]
idb = pisi.db.installdb.InstallDB()
pdb = pisi.db.packagedb.PackageDB()
for pkgconfig in pcs:
pc = pdb.get_package_by_pkgconfig(pkgconfig)
if not pc:
pc = idb.get_package_by_pkgconfig(pkgconfig)
if pc:
print "%s found in: %s" % (pkgconfig, pc.name)
print "Warning: Package does not appear in repository"
else:
print "Error: %s not found in repository or local install" % pkgconfig
else:
print "%s found in: %s" % (pkgconfig, pc.name)
if __name__ == "__main__":
main()

89
common/Scripts/pbump.py Executable file
View file

@ -0,0 +1,89 @@
#!/usr/bin/env python
# pbump.py: Bump pspec.xml
#
# Copyright 2015 Ikey Doherty <iikey@solus-project.com>
#
# WARNING: Not well tested, strips comments, and reorders attributes. Crap error handling
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
import xml.etree.ElementTree as ET
import sys
import os
import xml.dom.minidom as minidom
import datetime
import commands
from configobj import ConfigObj
''' Example config file
~/.solus/packager
[Packager]
Name=Your Name Goes Here
Email=Your Email Goes Here
'''
if __name__ == "__main__":
#if len(sys.argv) != 2:
# print "Not enough arguments - aborting"
# sys.exit(1)
homeDir = os.environ ["HOME"]
config = ".solus/packager"
config_p = os.path.join(homeDir, config)
if not os.path.exists(config_p):
print "Config file not found at %s" % config_p
sys.exit (1)
config = ConfigObj(config_p)
newname = config["Packager"]["Name"]
newemail = config["Packager"]["Email"]
if not os.path.exists("pspec.xml"):
print "pspec.xml doesn\'t exist - aborting"
sys.exit(1)
tree = ET.parse("pspec.xml")
root = tree.getroot()
hist = root.findall("History")
last_update = hist[0].findall("Update")[0]
rel = int(last_update.attrib['release'])
vers = str(last_update.findall("Version")[0].text)
# 10-06-2014
d = datetime.date.today()
f = d.strftime('%m-%d-%Y')
# normal shmaz.
rel += 1
newrel = ET.Element("Update")
newrel.tail = "\n\n "
newrel.text = "\n "
hist[0].insert(0, newrel)
ent = ET.SubElement(newrel, "Date")
ent.tail = "\n "
ent.text = f
ent = ET.SubElement(newrel, "Version")
ent.tail = "\n "
ent.text = vers
ent = ET.SubElement(newrel, "Comment")
ent.tail = "\n "
ent.text = "Package bump"
newrel.attrib['release'] = str(rel)
ent = ET.SubElement(newrel, "Name")
ent.tail = "\n "
ent.text = newname
ent = ET.SubElement(newrel, "Email")
ent.text = newemail
ent.tail = "\n "
s = ET.tostring(root, 'utf-8').replace("\r\n", "\n").replace("\t", " ")
complete = "<?xml version=\"1.0\" ?>\n<!DOCTYPE PISI SYSTEM \"https://solus-project.com/standard/pisi-spec.dtd\">\n" + s
with open ("pspec.xml", "w") as output:
output.writelines(complete)
print "Bumped to %s" % rel

298
common/Scripts/yauto.py Executable file
View file

@ -0,0 +1,298 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# yauto.py
#
# Copyright 2013 Ikey Doherty <ikey@solusos.com>
# Copyright 2015 Ikey Doherty <iikey@solus-project.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
import os
import sys
import os.path
import dloader
import datetime
import shutil
from configobj import ConfigObj
''' Example config file
~/.evolveos/packager
[Packager]
Name=Your Name Goes Here
Email=Your Email Goes Here
'''
# What we term as needed doc files
KnownDocFiles = [ "COPYING", "COPYING.LESSER", "ChangeLog", "COPYING.GPL", "AUTHORS", "BUGS", "CHANGELOG", "LICENSE"]
# Compile type to build 'actions.py'
GNOMEY = 1
AUTOTOOLS = 2
CMAKE = 3
PYTHON_MODULES = 4
PERL_MODULES = 5
class DepObject:
name = None
version = None
class AutoPackage:
package_prefix = ""
buildpl = False
makefile = False
def __init__(self, uri):
self.package_uri = uri
homeDir = os.environ ["HOME"]
config = ".evolveos/packager"
self.config_dir = os.path.join (homeDir, config)
if not os.path.exists (self.config_dir):
print "Config file not found at %s" % self.config_dir
sys.exit (-1)
# See the above commentary for details on the file format
self.config = ConfigObj (self.config_dir)
self.email = self.config["Packager"]["Email"]
self.packager_name = self.config["Packager"]["Name"]
# Templates
us = os.path.dirname(os.path.abspath(__file__))
base_dir = "/".join (us.split ("/")[:-1])
self.template_dir = os.path.join (base_dir, "Templates")
self.build_deps = list()
self.doc_files = list()
def verify (self):
print "Verifying %s" % self.package_uri
self.file_name = self.package_uri.split ("/")[-1]
self.file_name_full = os.path.abspath (self.file_name)
print self.file_name
try:
dloader.download_file (self.package_uri)
self.sha256sum = dloader.get_sha256sum(self.file_name)
except Exception, e:
print e
return False
return True
def examine_source (self):
splits = self.file_name.split (".")
suffix = "".join(splits [-2:]).replace ("bzip2", "bz2")
# Find out pspec file type
if suffix.endswith ("zip"):
suffix = "zip"
self.file_type = suffix
# Work out the version number
path,ext = os.path.splitext (self.file_name)
version = path.split ("-")[-1].split(".")[:-1]
version_string = ".".join(version)
self.version_string = version_string
# Package name, including hyphens
self.package_name = "-".join(path.split("-")[:-1])
self.compile_type = None
print "Package: %s\nVersion: %s" % (self.package_name, self.version_string)
# Set up temporary
self.temp_dir = os.path.abspath ("./TEMP")
os.mkdir (self.temp_dir)
self.current_dir = os.getcwd ()
os.chdir (self.temp_dir)
os.system ("tar xf \"%s\"" % self.file_name_full)
known_types = list()
# Check for certain files..
for root,dirs,files in os.walk (os.getcwd ()):
depth = root[len(path) + len(os.path.sep):].count(os.path.sep)
if depth == 3:
print "bailing"
# We're currently two directories in, so all subdirs have depth 3
dirs[:] = [] # Don't recurse any deeper
for file in files:
if file in KnownDocFiles:
# Append files for pisitools.dodoc ()
if file not in self.doc_files:
self.doc_files.append (file)
print "Added %s" % file
if file == "Makefile":
self.makefile = True
if "configure.ac" in file:
# Examine this fella for build deps
self.build_deps = self.check_build_deps(os.path.join(root, file))
if "configure" in file:
# Check if we need to employ certain hacks needed in gnome packages
fPath = os.path.join (root, file)
print "Checking %s for use of g-ir-scanner" % fPath
if self.check_is_gnomey (fPath):
known_types.append(GNOMEY)
else:
known_types.append(AUTOTOOLS)
if "CMakeLists.txt" in file:
# This will use the actions with cmake
known_types.append(CMAKE)
if "setup.py" in file:
# this is a python module.
known_types.append(PYTHON_MODULES)
if "Makefile.PL" in file or "Build.PL" in file:
# This is a perl module
known_types.append(PERL_MODULES)
if "BUILD.PL" in file:
self.buildpl = True
# We may have hit several systems..
if CMAKE in known_types:
print "cmake"
self.compile_type = CMAKE
elif GNOMEY in known_types:
print "gnomey"
self.compile_type = GNOMEY
elif AUTOTOOLS in known_types:
print "autotools"
self.compile_type = AUTOTOOLS
elif PYTHON_MODULES in known_types:
print "python"
self.compile_type = PYTHON_MODULES
elif PERL_MODULES in known_types:
print "perl"
self.compile_type = PERL_MODULES
else:
print "unknown"
# Clean up on aisle 3
os.chdir (self.current_dir)
shutil.rmtree (self.temp_dir)
# Always delete
if os.path.exists (self.file_name):
os.remove (self.file_name)
def check_build_deps(self, path):
deps = list()
with open(path, "r") as read:
for line in read.readlines():
line = line.replace("\n","").replace("\r","").strip()
# Currently only handles configure.ac
if "PKG_CHECK_MODULES" in line:
splits = line.split(",")
part = splits[1] if len(splits) > 1 else splits[0]
part = part.replace("[","").replace(")","").replace("]","")
splits = part.split(">=")
pkg = splits[0].strip()
dep = DepObject()
dep.name = pkg
if len(splits) > 1:
version = splits[1].strip()
# Can happen, we don't handle variable expansion.
if "$" in version:
continue
dep.version = version
# Check it hasn't been added
objs = [x for x in deps if x.name == dep.name]
if len(objs) == 0:
deps.append(dep)
return deps
def create_yaml(self):
''' Attempt creation of a package.yaml... '''
with open('package.yml', 'w') as yml:
mapping = { "NAME" : self.package_name,
"VERSION" : self.version_string,
"SOURCE": self.package_uri,
"SHA256SUM": self.sha256sum }
tmp = """name : %(NAME)s
version : %(VERSION)s
release : 1
source :
- %(SOURCE)s : %(SHA256SUM)s
license : GPL-2.0 # CHECK ME
summary : PLEASE FILL ME IN
description: |
PLEASE FILL ME IN""" % mapping
totalStr = tmp
setup = None
build = None
install = None
totalStr += "\nbuilddeps :\n"
if self.build_deps is not None and len(self.build_deps) > 0:
for dep in self.build_deps:
if len(dep.name.strip()) == 0:
continue
totalStr += " - pkgconfig(%s)\n" % dep.name
if self.compile_type == GNOMEY:
setup = "%configure --disable-static"
elif self.compile_type == CMAKE:
setup = "%cmake ."
elif self.compile_type == PYTHON_MODULES:
setup = "python setup.py configure"
build = "python setup.py build"
install = "python setup.py install --root=%installroot% --no-compile -O0"
elif self.compile_type == PERL_MODULES:
if self.buildpl:
setup = "perl Build.PL installdirs=vendor destdir=%installroot%"
else:
setup = "perl Makefile.PL PREFIX=/usr INSTALLDIRS=vendor DESTDIR=%installroot%"
if not self.makefile:
build = "perl Build"
install = "perl Build install"
sample_actions = os.path.join (self.template_dir, "actions.perlmodules.sample.py")
if setup is None:
setup = "%configure"
if build is None:
build = "%make"
if install is None:
install = "%make_install"
mapping = { "SETUP": setup, "BUILD" : build, "INSTALL" : install }
tmpl = """setup : |
%(SETUP)s
build : |
%(BUILD)s
install : |
%(INSTALL)s
""" % mapping
totalStr += "\n" + tmpl
yml.writelines(totalStr.replace("\n\n", "\n"))
yml.flush()
def check_is_gnomey (self, path):
with open (path, "r") as makefile:
lines = makefile.read ()
if "g-ir-scanner" in lines or "g_ir_scanner" in lines:
return True
return False
if __name__ == "__main__":
if len (sys.argv) < 2:
print "%s: <URI>" % sys.argv[0]
sys.exit (-1)
p = AutoPackage (sys.argv[1])
if not p.verify ():
print "Unable to locate given URI"
else:
print "Completed verification"
p.examine_source ()
p.create_yaml ()

104
common/Scripts/yconvert.py Executable file
View file

@ -0,0 +1,104 @@
#!/usr/bin/env python
# yconvert.py - convert existing package into YML format
#
# USAGE: yconvert.py pspec.xml
# Copyright 2015 Ikey Doherty <iikey@solus-project.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
import xml.etree.ElementTree as ET
import sys
import os
import xml.dom.minidom as minidom
import commands
if __name__ == "__main__":
if len(sys.argv) != 2:
print "Provide pspec.xml"
sys.exit(1)
if not sys.argv[1].endswith("pspec.xml"):
print "This doesn\'t look like a pspec.xml. Aborting"
sys.exit(1)
if not os.path.exists(sys.argv[1]):
print "pspec.xml doesn\'t exist - aborting"
sys.exit(1)
tree = ET.parse(sys.argv[1])
root = tree.getroot()
archive = root.findall("Source/Archive")[0]
name = root.findall("Source/Name")[0].text
homepage = None
t = root.findall("Source/Homepage")
if t and len(t) > 0:
homepage = t[0].text
lic = root.findall("Source/License")
licenses = [x.text for x in lic]
hist = root.findall("History")
last_update = hist[0].findall("Update")[0]
rel = int(last_update.attrib['release']) + 1
version = str(last_update.findall("Version")[0].text)
description = root.findall("Source/Description")[0].text
summary = root.findall("Source/Summary")[0].text
depsi = root.findall("Source/BuildDependencies/Dependency")
pcdeps = ["pkgconfig(%s)" % (x.text) for x in depsi if "type" in x.attrib and x.attrib['type'] == "pkgconfig"]
deps = [x.text for x in depsi if "pkgconfig(%s)" % x.text not in pcdeps]
url = archive.text
file = url.split("/")[-1]
r = 0
try:
r = os.system("wget \"%s\"" % url)
except:
print "Failed to download file"
sys.exit(1)
if r != 0:
print "Failed to download file"
sys.exit(1)
sha256 = commands.getoutput("sha256sum %s" % file).split()[0].strip()
os.unlink(file)
d = """
name : %(name)s
version : %(version)s
release : %(release)s
source :
- %(tarball)s : %(sha256)s
""" % { "name": name, "version": version, "release": rel, "tarball": url, "sha256": sha256}
if homepage:
d += "homepage : %s\n" % homepage
d += "license :\n"
for lic in licenses:
d += " - %s\n" % lic
d += "summary : %s\n" % summary
if len(pcdeps) > 0 or len(deps) > 0:
d += "builddeps :\n"
for dep in pcdeps:
d += " - %s\n" % dep
for dep in deps:
d += " - %s\n" % dep
d += "description : |\n"
for line in description.split("\n"):
line = line.strip()
d += " %s\n" % line
d += """setup : |
%configure
build : |
%make
install : |
%make_install
"""
with open ("package.yml", "w") as output:
output.writelines(d.strip() + "\n")

View file

@ -0,0 +1,17 @@
#!/usr/bin/python
from pisi.actionsapi import cmaketools, pisitools
def setup():
cmaketools.configure()
def build():
cmaketools.make()
def install():
cmaketools.install()
#EXTRADOCS#

View file

@ -0,0 +1,19 @@
#!/usr/bin/python
from pisi.actionsapi import shelltools, get, autotools, pisitools
shelltools.export("HOME", get.workDIR())
def setup():
autotools.configure("--disable-static")
def build():
autotools.make()
def install():
autotools.rawInstall("DESTDIR=%s" % get.installDIR())
#EXTRADOCS#

View file

@ -0,0 +1,17 @@
#!/usr/bin/python
from pisi.actionsapi import perlmodules, pisitools
def setup():
perlmodules.configure()
def build():
perlmodules.make()
def install():
perlmodules.install()
#EXTRADOCS#

View file

@ -0,0 +1,17 @@
#!/usr/bin/python
from pisi.actionsapi import pythonmodules, pisitools
def build():
pythonmodules.compile()
def check():
pythonmodules.compile("test")
def install():
pythonmodules.install()
#EXTRADOCS#

View file

@ -0,0 +1,17 @@
#!/usr/bin/python
from pisi.actionsapi import get, autotools, pisitools
def setup():
autotools.configure()
def build():
autotools.make()
def install():
autotools.rawInstall("DESTDIR=%s" % get.installDIR())
#EXTRADOCS#

View file

@ -0,0 +1,37 @@
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "https://evolve-os.com/standard/pisi-spec.dtd">
<PISI>
<Source>
<Name>%(PackageName)s</Name>
<Homepage></Homepage>
<Packager>
<Name>%(PackagerName)s</Name>
<Email>%(PackagerEmail)s</Email>
</Packager>
<Summary>%(Summary)s</Summary>
<Description>%(Description)s</Description>
<License>%(License)s</License>
<Archive sha1sum="%(HashSum)s" type="%(ArchiveType)s">%(ArchiveURI)s</Archive>
<BuildDependencies>
%(BuildDeps)s
</BuildDependencies>
</Source>
<Package>
<Name>%(PackageName)s</Name>
<Files>
<Path fileType="*">/</Path>
</Files>
</Package>
<History>
<Update release="1">
<Date>%(Date)s</Date>
<Version>%(Version)s</Version>
<Comment>Add %(PackageName)s to repositories</Comment>
<Name>%(PackagerName)s</Name>
<Email>%(PackagerEmail)s</Email>
</Update>
</History>
</PISI>