@ -1,86 +0,0 @@ |
|||
import time |
|||
base="http://packages.debian.org" |
|||
distro="stable" |
|||
usage ="""sde pkg new --deb [options] arg |
|||
example: sde pkg new -deb -o network/apache2 apache2 |
|||
Run --help (-h) for more info""" |
|||
force=True |
|||
guess=True |
|||
def copynote(package): |
|||
return """[COPY] --- SDE-COPYRIGHT-NOTE-BEGIN --- |
|||
[COPY] This copyright note is auto-generated by ./scripts/Create-CopyPatch. |
|||
[COPY] |
|||
[COPY] Filename: package/.../%(p)s/%(p)s.desc |
|||
[COPY] Copyright (C) %(t)s The OpenSDE Project |
|||
[COPY] |
|||
[COPY] More information can be found in the files COPYING and README. |
|||
[COPY] |
|||
[COPY] This program is free software; you can redistribute it and/or modify |
|||
[COPY] it under the terms of the GNU General Public License as published by |
|||
[COPY] the Free Software Foundation; version 2 of the License. A copy of the |
|||
[COPY] GNU General Public License can be found in the file COPYING. |
|||
[COPY] --- SDE-COPYRIGHT-NOTE-END ---""" %{ "p": package, |
|||
't': time.strftime('%Y')} |
|||
desci="[I] TODO: Short Information" |
|||
desct="""TODO: Long Explanation |
|||
TODO: Long Explanation |
|||
TODO: Long Explanation |
|||
TODO: Long Explanation |
|||
TODO: Long Explanation""" |
|||
descu="[U] TODO: URL" |
|||
desca="[A] TODO: Author" |
|||
descm="[M] The OpenSDE Community <list@opensde.org>" |
|||
descc="[C] TODO: Category" |
|||
descl="[L] TODO: License" |
|||
descs="[S] TODO: Status" |
|||
descv="[V] TODO: Version" |
|||
descp="[P] X -----5---9 800.000" |
|||
descd="[D] 0" |
|||
status={"oldstable":"stable", |
|||
"stable":"Stable", |
|||
"testing":"Gamma", |
|||
"unstable":"Beta", |
|||
"experimental":"Alpha"} |
|||
|
|||
licenses={"contrib":"OpenSource", |
|||
"Non-Free":"Free-to-use", |
|||
"Non-US/Main":"Free-to-use", |
|||
"Non-US/Non-Free":"OpenSource"} |
|||
categories={"admin":"extra/tool", |
|||
"comm":"extra/network", |
|||
"debian-installer":"extra/base", |
|||
"doc":"extra/documentation", |
|||
"editors":"extra/editor", |
|||
"electronics":"extra/tool", |
|||
"embedded":"extra/embedded", |
|||
"games":"extra/game", |
|||
"gnome":"extra/desktop/gnome", |
|||
"graphics":"extra/graphic", |
|||
"hamradio":"extra/tool", |
|||
"interpreters":"extra/shell", |
|||
"kde":"extra/desktop/kde", |
|||
"libdevel":"extra/development", |
|||
"libs":"extra/library", |
|||
"mail":"extra/office", |
|||
"math":"extra/scientific", |
|||
"misc":"extra/miscellaneous", |
|||
"net":"extra/network", |
|||
"news":"extra/office", |
|||
"oldlibs":"extra/library", |
|||
"otherosfs":"extra/tools", |
|||
"perl":"extra/development", |
|||
"python":"extra/development", |
|||
"science":"extra/scientific", |
|||
"shells":"extra/shell", |
|||
"tex":"extra/text", |
|||
"text":"extra/text", |
|||
"utils":"extra/tool", |
|||
"web":"extra/network", |
|||
"x11":"extra/x11" |
|||
} |
|||
# category exlucsion:reason |
|||
debianpolicy="http://www.debian.org/doc/debian-policy/ch-binary" |
|||
excludecat={"virtual":""" |
|||
This is a debian only package. |
|||
See %s#s-virtual_pkg for reason"""% debianpolicy |
|||
} |
@ -1,205 +0,0 @@ |
|||
import urllib2, re, os,sys,optparse |
|||
from BeautifulSoup import BeautifulSoup |
|||
from HTMLParser import HTMLParser |
|||
from info import * |
|||
class cParseHTML(HTMLParser): |
|||
val=None |
|||
def handle_starttag(self, tag, attrs): |
|||
self.val=re.sub(self.get_starttag_text()+"|\n|\r", |
|||
" ",self.val) |
|||
def parse(self,string): |
|||
self.val=string |
|||
self.feed(self.val) |
|||
return self.val |
|||
cParse=cParseHTML() |
|||
parse=cParse.parse |
|||
repo=None |
|||
pkg=None |
|||
bdescd=False |
|||
parser = optparse.OptionParser(usage) |
|||
parser.add_option("-b", "--base", dest="base", |
|||
help="""Change base i.e from |
|||
http://packages.debian.org to http://packages.ubuntu.com""") |
|||
parser.add_option("-d", "--distro",dest="distro", |
|||
help="""chose distro i.e stable (default) testing,unstable |
|||
oldstable experimental etc. """) |
|||
parser.add_option("-f", "--force", |
|||
action="store_true", dest="force", |
|||
help="""Toggle force values on/off. Default can be set in |
|||
lib/sde-download/info.py.""") |
|||
parser.add_option("-g", "--guess", |
|||
action="store_true", dest="guess", |
|||
help="""Toggle guess values on/off. Default can be set in |
|||
lib/sde-download/info.py.""") |
|||
parser.add_option("-o", "--outpkg",dest="outpkg", |
|||
help="""Write desc to package.""") |
|||
(options, args) = parser.parse_args() |
|||
argn=0 |
|||
if len(args) != 1: |
|||
parser.error("incorrect number of arguments") |
|||
if options.base: |
|||
base=options.base |
|||
if options.distro: |
|||
distro=options.distro |
|||
if options.force: |
|||
if force: |
|||
force=False |
|||
else: force=True |
|||
if options.guess: |
|||
if guess: |
|||
guess=False |
|||
else: force=True |
|||
nargs=len(sys.argv)-1 |
|||
if sys.argv[nargs].startswith("-") or sys.argv[nargs].startswith("--"): |
|||
parse.error("Invalid options") |
|||
opts=sys.argv[nargs].split("/") |
|||
if len(opts) == 1: |
|||
pkg=sys.argv[nargs] |
|||
for cat in categories: |
|||
url=base + "/" + distro + "/" + cat + "/" + pkg |
|||
try: |
|||
urllib2.urlopen(url) |
|||
repo=cat |
|||
except:pass |
|||
elif len(opts)==2: |
|||
repo=opts[0] |
|||
pkg=opts[1] |
|||
else: |
|||
parse.error("Invalid options.") |
|||
if not repo:parser.error("Package doesn't exist.") |
|||
if not pkg:parse.error("Invalid options.") |
|||
url=base + "/" + distro + "/" + repo + "/" + pkg |
|||
try: |
|||
page=urllib2.urlopen(url).read() |
|||
except: |
|||
print "Error: package '%s' does not exist." % sys.argv[nargs] |
|||
sys.exit() |
|||
soup = BeautifulSoup(page) |
|||
copy=copynote(pkg) |
|||
for link in soup("a"): |
|||
link=str(link) |
|||
if re.search("tar\.gz",link): |
|||
buf=re.sub("^.|.$","", |
|||
re.search('("|\').*("|\')',link).group()) |
|||
descd+=" " + buf.split("/").pop() |
|||
descd+=" " + re.sub(buf.split("/").pop()+"$","",buf) |
|||
bdescd=True |
|||
try: |
|||
descv="[V] " + re.sub("^.|.$","",re.search("\(.*\)", |
|||
str(soup("h1"))).group()) |
|||
except: pass |
|||
try: |
|||
desci="[I] " + parse("".join(soup("h2")[0])).capitalize()+"." |
|||
except: pass |
|||
try: |
|||
desct=parse(str(soup("p")[1])) |
|||
except: pass |
|||
lcat=soup("span") |
|||
if len(lcat) > 0: |
|||
lcat=re.sub("^.|.$","",str(lcat)) |
|||
if force: |
|||
descu="[U] " + url |
|||
desca="[A] Unknown" |
|||
descl="[L] Unknown" |
|||
descs="[S] Stable" |
|||
if guess: |
|||
try: |
|||
stat=status[distro] |
|||
descs="[S] " + stat |
|||
except: pass |
|||
try: |
|||
cat=categories[repo] |
|||
descc="[C] " + cat |
|||
except: pass |
|||
try: |
|||
license=licenses[lcat] |
|||
descl="[L] " + license |
|||
except:pass |
|||
sdesct="" |
|||
cnt=0 |
|||
cnt2=0 |
|||
desct=re.sub("^\s*","",desct) |
|||
for word in desct.split(" "): |
|||
cnt+=len(word)+1 |
|||
if cnt < 76: |
|||
if cnt2 == 0: |
|||
sdesct+="[T] %s" % word |
|||
cnt2=1 |
|||
else:sdesct+=" %s" % word |
|||
else: |
|||
sdesct+="\n[T] %s" % word |
|||
cnt=1 |
|||
formatteddesc="""%(copy)s |
|||
|
|||
%(i)s |
|||
|
|||
%(t)s |
|||
|
|||
%(u)s |
|||
|
|||
%(a)s |
|||
%(m)s |
|||
|
|||
%(c)s |
|||
|
|||
%(l)s |
|||
%(s)s |
|||
%(v)s |
|||
%(p)s |
|||
|
|||
%(d)s |
|||
"""%{ "copy": copy,"i": desci,"t":sdesct,"u":descu,"a":desca, |
|||
"m":descm,"c":descc,"l":descl,"s":descs,"v":descv,"p":descp, |
|||
"d":descd} |
|||
|
|||
if options.outpkg: |
|||
output=options.outpkg.split("/") |
|||
optcnt=len(output) - output.count("") |
|||
out="" |
|||
if optcnt == 1: |
|||
os.system("echo -e \"\033[33;1m=>\033[0m assuming reqested repository as 'wip.'\"") |
|||
out="package/wip/" +output[0]+"/"+output[0]+".desc" |
|||
dir="package/wip/" +output[0] |
|||
if os.path.isdir(dir): |
|||
if os.path.isfile(out): |
|||
print """failed |
|||
package %s belongs to wip!""" % output[0] |
|||
sys.exit(1) |
|||
else: |
|||
os.mkdir(dir) |
|||
elif optcnt==2: |
|||
repository="package/" + output[0] |
|||
if not os.path.isdir(repository): |
|||
print "Error:invalid repository '%s'!" % dir |
|||
sys.exit(1) |
|||
dir=repository + "/" + output[1] |
|||
if os.path.isdir(dir): |
|||
out=dir+"/"+output[1]+".desc" |
|||
if os.path.isfile(out): |
|||
print "failed\n package %(p)s belongs to %(c)s!" %{"p":output[1], |
|||
"c":output[0]} |
|||
sys.exit(1) |
|||
else: |
|||
os.mkdir(dir) |
|||
else:parser.error("Inavlid Option for --outpkg (-o)") |
|||
try: |
|||
os.system("echo -n 'Writing desc to file...'") |
|||
outf=open(out,"w") |
|||
outf.write(formatteddesc) |
|||
outf.close() |
|||
os.system("echo 'ok'") |
|||
except: |
|||
print"Error writing to file " + out |
|||
if bdescd: |
|||
os.system("echo -n 'Patching cksum...'") |
|||
if os.popen("sde pkg up " + output[len(output)-1]+"&>/dev/null"): |
|||
os.system("echo 'ok'") |
|||
else:os.system("echo 'failed'") |
|||
todo="" |
|||
for line in formatteddesc.split("\n"): |
|||
if re.search("^\[.\] TODO:",line):todo+="\n" + line |
|||
if not todo == "": |
|||
print "The following needs completing:" |
|||
print todo |
|||
else: |
|||
print formatteddesc |