#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# just put a .pisipackager file in your home and fill it like
#
# name = Onur Küçük
# email = onur@pardus.org.tr
#
import os
import sys
import time
import string
packagerfile = ".pisipackager"
data = {"date": time.strftime("%Y-%m-%d"),
"year": time.strftime("%Y")}
temp_pspec = '''
%(package)s
%(packager_name)s
%(packager_email)s
GPLv2
%(package)s
app:gui
%(package)s
sleep
/
%(date)s
First release
%(packager_name)s
%(packager_email)s
'''
temp_actions = '''#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright %(year)s TUBITAK/UEKAE
# Licensed under the GNU General Public License, version 2.
# See the file http://www.gnu.org/copyleft/gpl.txt.
from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools
from pisi.actionsapi import shelltools
from pisi.actionsapi import get
# WorkDir = ""
# NoStrip = "/"
def setup():
autotools.configure()
def build():
autotools.make()
def install():
autotools.rawInstall("DESTDIR=%%s" %% get.installDIR())
pisitools.dodoc("AUTHORS", "ChangeLog", "README*", "NEWS")
'''
temp_desktop = '''[Desktop Entry]
Type=Application
Version=1.0
Encoding=UTF-8
Name=%(package_cap)s
Name[tr]=%(package_cap)s
GenericName=%(package_cap)s
GenericName[tr]=%(package_cap)s
Icon=%(package)s
Exec=%(package)s
Terminal=false
StartupNotify=false
Categories=Application;Game;ArcadeGame;
'''
temp_service = '''
from comar.service import *
serviceType = "local"
serviceConf = "%(package)s"
serviceDefault = "conditional"
serviceDesc = _({"en": "%(package_cap)s",
"tr": "%(package_cap)s"})
@synchronized
def start():
startService(command="/usr/sbin/%(package)s",
args = config.get("args", "destroy"),
donotify=True)
@synchronized
def stop():
stopService(command="/usr/sbin/%(package)s",
donotify=True)
def ready():
import os
status = is_on()
if status == "on" or (status == "conditional" and os.path.exists("/sys/coffee/ready")):
start()
def status():
return checkDaemon("/var/run/%(package)s.pid")
'''
temp_postscript = '''#/usr/bin/python
# -*- coding: utf-8 -*-
import os
def postInstall():
print "FIXME"
'''
temp_translation = '''
%(package)s
'''
def write(filename, data):
try:
f = open("%s/%s" % (target, filename), "w")
f.write(data)
f.close()
except:
print("Could not write file %s/%s" % (target, filename))
def create_dirs():
try:
os.makedirs("%s/files" % target)
os.makedirs("%s/comar" % target)
except:
print("Could not make directory %s" % target)
sys.exit(1)
def readConfig():
home = os.getenv("HOME", "")
cfg = "%s/%s" % (home, packagerfile)
d = {"name": "", "email": ""}
if home != "" and os.path.exists(cfg):
for line in open(cfg):
if line != "" and not line.startswith("#") and "=" in line:
l, m = line.split("=", 1)
k = l.strip()
v = m.strip()
if k in ["name", "email"]:
if v.startswith('"') or v.startswith("'"):
v = v[1:-1]
d[k.strip()] = v.strip()
return d["name"], d["email"]
# some checks
if len(sys.argv) < 2:
print("Usage : %s NewPackageDir" % sys.argv[0])
sys.exit(0)
else:
target = sys.argv[1]
data["packagedir"], data["package"] = os.path.split(target)
data["package_cap"] = string.capitalize(data["package"])
if os.path.exists(target):
print("%s already exists, please remove it first" % target)
sys.exit(1)
elif " " in data["package"]:
print("You should not use empty space in package name")
sys.exit(1)
# here we go
data["packager_name"], data["packager_email"] = readConfig()
create_dirs()
write("pspec.xml", temp_pspec % data)
write("actions.py", temp_actions % data)
write("translations.xml", temp_translation % data)
write("files/%s.desktop" % data["package"], temp_desktop % data)
write("comar/service.py", temp_service % data)
write("comar/package.py", temp_postscript)