From db74c11d2b8ceea7ba04ef9cc3086d0209de10d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Tue, 26 Mar 2013 18:13:52 +0100 Subject: [PATCH 1/2] Add an Atom feed generator in devscripts --- devscripts/gh-pages/update-feed.py | 83 ++++++++++++++++++++++++++++++ devscripts/release.sh | 1 + 2 files changed, 84 insertions(+) create mode 100755 devscripts/gh-pages/update-feed.py diff --git a/devscripts/gh-pages/update-feed.py b/devscripts/gh-pages/update-feed.py new file mode 100755 index 000000000..7158d7a0b --- /dev/null +++ b/devscripts/gh-pages/update-feed.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 + +import sys + +import xml.etree.ElementTree as ET +import xml.dom.minidom as minidom + +import datetime + +if len(sys.argv) <= 1: + print('Specify the version number as parameter') + sys.exit() +version = sys.argv[1] + +out_file = "atom.atom" +in_file = out_file + +now = datetime.datetime.now() +now_iso = now.isoformat() + +atom_url = "http://www.w3.org/2005/Atom" + +#Some utilities functions +def atom_tag(tag): + #Return a tag in the atom namespace + return "{{{}}}{}".format(atom_url,tag) + +def atom_SubElement(parent,tag): + return ET.SubElement(parent,atom_tag(tag)) + +class YDLUpdateAtomEntry(object): + def __init__(self,parent,title,id ,link, downloads_link): + self.entry = entry = atom_SubElement(parent, "entry") + #We set the values: + atom_id = atom_SubElement(entry, "id") + atom_id.text = id + atom_title = atom_SubElement(entry, "title") + atom_title.text = title + atom_link = atom_SubElement(entry, "link") + atom_link.set("href", link) + atom_content = atom_SubElement(entry, "content") + atom_content.set("type", "xhtml") + #Here we go: + div = ET.SubElement(atom_content,"div") + div.set("xmlns", "http://www.w3.org/1999/xhtml") + div.text = "Downloads available at " + a = ET.SubElement(div, "a") + a.set("href", downloads_link) + a.text = downloads_link + + #Author info + atom_author = atom_SubElement(entry, "author") + author_name = atom_SubElement(atom_author, "name") + author_name.text = "The youtube-dl maintainers" + #If someone wants to put an email adress: + #author_email = atom_SubElement(atom_author, "email") + #author_email.text = the_email + + atom_updated = atom_SubElement(entry,"updated") + up = parent.find(atom_tag("updated")) + atom_updated.text = up.text = now_iso + + @classmethod + def entry(cls,parent, version): + update_id = "youtube-dl-{}".format(version) + update_title = "New version {}".format(version) + downloads_link = "http://youtube-dl.org/downloads/{}/".format(version) + #There's probably no better link + link = "http://rg3.github.com/youtube-dl" + return cls(parent, update_title, update_id, link, downloads_link) + + +atom = ET.parse(in_file) + +root = atom.getroot() + +#Otherwise when saving all tags will be prefixed with a 'ns0:' +ET.register_namespace("atom",atom_url) + +update_entry = YDLUpdateAtomEntry.entry(root, version) + +#Find some way of pretty printing +atom.write(out_file,encoding="utf-8",xml_declaration=True) diff --git a/devscripts/release.sh b/devscripts/release.sh index ee650f221..6e89d55b3 100755 --- a/devscripts/release.sh +++ b/devscripts/release.sh @@ -69,6 +69,7 @@ ROOT=$(pwd) ORIGIN_URL=$(git config --get remote.origin.url) cd build/gh-pages "$ROOT/devscripts/gh-pages/add-version.py" $version + "$ROOT/devscripts/gh-pages/update-feed.py" $version "$ROOT/devscripts/gh-pages/sign-versions.py" < "$ROOT/updates_key.pem" "$ROOT/devscripts/gh-pages/generate-download.py" "$ROOT/devscripts/gh-pages/update-copyright.py" From 6060788083df366dae1cd75d4c1eac8e46918765 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Fri, 29 Mar 2013 19:42:33 +0100 Subject: [PATCH 2/2] Write a new feed each time, reading from versions.json --- devscripts/gh-pages/update-feed.py | 110 +++++++++++------------------ devscripts/release.sh | 2 +- 2 files changed, 43 insertions(+), 69 deletions(-) diff --git a/devscripts/gh-pages/update-feed.py b/devscripts/gh-pages/update-feed.py index 7158d7a0b..f8b9fb594 100755 --- a/devscripts/gh-pages/update-feed.py +++ b/devscripts/gh-pages/update-feed.py @@ -1,83 +1,57 @@ #!/usr/bin/env python3 -import sys - -import xml.etree.ElementTree as ET -import xml.dom.minidom as minidom - import datetime -if len(sys.argv) <= 1: - print('Specify the version number as parameter') - sys.exit() -version = sys.argv[1] +import textwrap -out_file = "atom.atom" -in_file = out_file +import json + +atom_template=textwrap.dedent("""\ + + + Updates feed. + youtube-dl-updates-feed + @TIMESTAMP@ + @ENTRIES@ + """) + +entry_template=textwrap.dedent(""" + + youtube-dl-@VERSION@ + New version @VERSION@ + + +
+ Downloads available at http://youtube-dl.org/downloads/@VERSION@/ +
+
+ + The youtube-dl maintainers + + @TIMESTAMP@ +
+ """) now = datetime.datetime.now() now_iso = now.isoformat() -atom_url = "http://www.w3.org/2005/Atom" +atom_template = atom_template.replace('@TIMESTAMP@',now_iso) -#Some utilities functions -def atom_tag(tag): - #Return a tag in the atom namespace - return "{{{}}}{}".format(atom_url,tag) - -def atom_SubElement(parent,tag): - return ET.SubElement(parent,atom_tag(tag)) - -class YDLUpdateAtomEntry(object): - def __init__(self,parent,title,id ,link, downloads_link): - self.entry = entry = atom_SubElement(parent, "entry") - #We set the values: - atom_id = atom_SubElement(entry, "id") - atom_id.text = id - atom_title = atom_SubElement(entry, "title") - atom_title.text = title - atom_link = atom_SubElement(entry, "link") - atom_link.set("href", link) - atom_content = atom_SubElement(entry, "content") - atom_content.set("type", "xhtml") - #Here we go: - div = ET.SubElement(atom_content,"div") - div.set("xmlns", "http://www.w3.org/1999/xhtml") - div.text = "Downloads available at " - a = ET.SubElement(div, "a") - a.set("href", downloads_link) - a.text = downloads_link - - #Author info - atom_author = atom_SubElement(entry, "author") - author_name = atom_SubElement(atom_author, "name") - author_name.text = "The youtube-dl maintainers" - #If someone wants to put an email adress: - #author_email = atom_SubElement(atom_author, "email") - #author_email.text = the_email - - atom_updated = atom_SubElement(entry,"updated") - up = parent.find(atom_tag("updated")) - atom_updated.text = up.text = now_iso - - @classmethod - def entry(cls,parent, version): - update_id = "youtube-dl-{}".format(version) - update_title = "New version {}".format(version) - downloads_link = "http://youtube-dl.org/downloads/{}/".format(version) - #There's probably no better link - link = "http://rg3.github.com/youtube-dl" - return cls(parent, update_title, update_id, link, downloads_link) - +entries=[] -atom = ET.parse(in_file) +versions_info = json.load(open('update/versions.json')) +versions = list(versions_info['versions'].keys()) +versions.sort() -root = atom.getroot() +for v in versions: + entry = entry_template.replace('@TIMESTAMP@',v.replace('.','-')) + entry = entry.replace('@VERSION@',v) + entries.append(entry) -#Otherwise when saving all tags will be prefixed with a 'ns0:' -ET.register_namespace("atom",atom_url) +entries_str = textwrap.indent(''.join(entries), '\t') +atom_template = atom_template.replace('@ENTRIES@', entries_str) + +with open('update/atom.atom','w',encoding='utf-8') as atom_file: + atom_file.write(atom_template) -update_entry = YDLUpdateAtomEntry.entry(root, version) -#Find some way of pretty printing -atom.write(out_file,encoding="utf-8",xml_declaration=True) diff --git a/devscripts/release.sh b/devscripts/release.sh index 6e89d55b3..b2a91f817 100755 --- a/devscripts/release.sh +++ b/devscripts/release.sh @@ -69,7 +69,7 @@ ROOT=$(pwd) ORIGIN_URL=$(git config --get remote.origin.url) cd build/gh-pages "$ROOT/devscripts/gh-pages/add-version.py" $version - "$ROOT/devscripts/gh-pages/update-feed.py" $version + "$ROOT/devscripts/gh-pages/update-feed.py" "$ROOT/devscripts/gh-pages/sign-versions.py" < "$ROOT/updates_key.pem" "$ROOT/devscripts/gh-pages/generate-download.py" "$ROOT/devscripts/gh-pages/update-copyright.py"