-
Notifications
You must be signed in to change notification settings - Fork 7
/
create-perl-package-from-cpan
executable file
·171 lines (137 loc) · 5.33 KB
/
create-perl-package-from-cpan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/python
# -*- coding: utf-8 -*-
# A semi-automatic Perl pisi package generator from CPAN.
# Usage: create-perl-package http://search.cpan.org/CPAN/authors/id/O/OP/OPI/Class-Member-1.6.tar.gz
import os
import re
import sys
import pisi
import time
ACTIONS_PY = """\
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 2.
# See the file http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
from pisi.actionsapi import perlmodules
from pisi.actionsapi import pisitools
def setup():
perlmodules.configure()
def build():
perlmodules.make()
def check():
perlmodules.make("test")
def install():
perlmodules.install()
pisitools.dodoc("README", "Changes")
"""
TRANSLATIONS_XML = """\
<?xml version="1.0" ?>
<PISI>
<Source>
<Name>%(package_name)s</Name>
<Summary xml:lang="tr">FIXME için Perl modülü</Summary>
<Description xml:lang="tr">%(package_name)s FIXME için Perl modülüdür.</Description>
</Source>
</PISI>
"""
PSPEC_XML = """\
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pardus.org.tr/projeler/pisi/pisi-spec.dtd">
<PISI>
<Source>
<Name>%(package_name)s</Name>
<Homepage>%(package_homepage)s</Homepage>
<Packager>
<Name>%(packager_name)s</Name>
<Email>%(packager_email)s</Email>
</Packager>
<!-- FIXME: Check licenses before merging to review -->
<License>Artistic-2</License>
<License>GPLv1</License>
<IsA>library</IsA>
<Summary>Perl module to FIXME</Summary>
<Description>%(package_name)s is a Perl module which FIXME.</Description>
<Archive sha1sum="%(archive_sum)s" type="%(archive_type)s">%(archive_url)s</Archive>
<BuildDependencies>
<Dependency version="%(perl_ver)s">perl</Dependency>
</BuildDependencies>
</Source>
<Package>
<Name>%(package_name)s</Name>
<RuntimeDependencies>
<Dependency version="%(perl_ver)s">perl</Dependency>
</RuntimeDependencies>
<Files>
<Path fileType="library">/usr/lib</Path>
<Path fileType="doc">/usr/share/doc</Path>
<Path fileType="man">/usr/share/man</Path>
</Files>
</Package>
<History>
<Update release="1">
<Date>%(today)s</Date>
<Version>%(package_version)s</Version>
<Comment>Initial release.</Comment>
<Name>%(packager_name)s</Name>
<Email>%(packager_email)s</Email>
</Update>
</History>
</PISI>
"""
def get_and_save_user_info():
name = "PACKAGER_NAME"
email = "PACKAGER_EMAIL"
conf_file = os.path.expanduser("~/.packagerinfo")
if os.path.exists(conf_file):
# Read from it
name, email = open(conf_file, "r").read().strip().split(",")
else:
print "Please enter your full name as seen in pspec files"
name = raw_input("> ")
print "Please enter your e-mail as seen in pspec files"
email = raw_input("> ")
print "Saving packager info into %s" % conf_file
open(conf_file, "w").write("%s,%s" % (name, email))
return name, email
def usage():
print "Usage: %s <archive-url>" % (sys.argv[0])
return 1
if __name__ == "__main__":
if len(sys.argv) < 2:
sys.exit(usage())
# Dictionaries for pspec.xml and translations.xml templates
pdict = {}
tdict = {}
# Ex: http://search.cpan.org/CPAN/authors/id/O/OP/OPI/Class-Member-1.6.tar.gz
pdict["archive_url"] = sys.argv[1]
# Extract package name, package version, archive extension
# Ex: perl-Class-Member, 1.16, tar.gz
(module_name, pdict["package_version"], archive_extension) = \
re.search("(.*?)-([0-9\._]*)\.(.*)", os.path.basename(pdict["archive_url"])).groups()
tdict["package_name"] = pdict["package_name"] = "perl-%s" % module_name
pdict["archive_type"] = archive_extension.replace(".", "")
# Generate homepage
pdict["package_homepage"] = "http://search.cpan.org/dist/%s" % module_name
# Get packager info
pdict["packager_name"], pdict["packager_email"] = get_and_save_user_info()
# Today's date
pdict["today"] = time.strftime("%Y-%m-%d")
# Get Perl version
pdict["perl_ver"] = pisi.db.installdb.InstallDB().get_version("perl")[0]
print "Fetching %s..." % pdict["archive_url"]
os.system("aria2c %s -q -d /var/cache/pisi/archives" % pdict["archive_url"])
pdict["archive_sum"] = os.popen("sha1sum /var/cache/pisi/archives/%s" % os.path.basename(pdict["archive_url"])).read().strip().split()[0]
# Replace with mirrors://cpan/ if starts with http://search.cpan.org
pdict["archive_url"] = "mirrors://cpan/%s" % \
pdict["archive_url"].replace("http://search.cpan.org/CPAN/", "") if \
pdict["archive_url"].startswith("http://search.cpan.org") else pdict["archive_url"]
try:
os.makedirs(pdict["package_name"])
except OSError:
print "Directory %s already exists." % pdict["package_name"]
# Write files
open(os.path.join(pdict["package_name"], "actions.py"), "w").write(ACTIONS_PY)
open(os.path.join(pdict["package_name"], "pspec.xml"), "w").write(PSPEC_XML % pdict)
open(os.path.join(pdict["package_name"], "translations.xml"), "w").write(TRANSLATIONS_XML % tdict)
os.system("svn add %s" % pdict["package_name"])