all repos — tint2 @ 3a7fb0971b3a529999560afe3dd8b777d77599eb

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

packaging/version_status.py (raw)

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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import sys
reload(sys)
sys.setdefaultencoding('utf8')
import datetime
import xml.etree.ElementTree as ET
import ftplib
import gzip
import json
import re
from StringIO import StringIO
import urllib2


# Returns true if `value` is an integer represented as a string.
def is_int(value):
  # type: (str) -> bool
  try:
    value = int(value)
  except ValueError:
    return False
  return True


# Returns a new string with all instances of multiple whitespace
# replaced with a single space.
def collapse_multiple_spaces(line):
  # type: (str) -> str
  return " ".join(line.split())


# Extracts the file name from a line of an FTP listing.
# The input must be a valid directory entry (starting with "-" or "d").
def ftp_file_name_from_listing(line):
  # type: (str) -> str
  line = collapse_multiple_spaces(line)
  return line.split(" ", 8)[-1]


# Extracts a list of the directories and a list of the files
# from an FTP listing.
def ftp_list_dir_process_listing(lines):
  # type: (List[str]) -> List[str], List[str]
  dirs = []
  files = []
  for line in lines:
    if line.startswith("d"):
      dirs.append(ftp_file_name_from_listing(line))
    elif line.startswith("-"):
      files.append(ftp_file_name_from_listing(line))
  return dirs, files


# Lists the remote FTP directory located at `path`.
# Returns a list of the directories and a list of the files.
def ftp_list_dir(ftp, path):
  # type: (ftplib.FTP, str) -> List[str], List[str]
  ftp.cwd(path)
  lines = []
  ftp.retrlines("LIST", lines.append)
  return ftp_list_dir_process_listing(lines)


# Downloads a binary file to a string.
# Returns the string.
def ftp_download(ftp, path):
  # type: (ftplib.FTP, str) -> str
  blocks = []
  ftp.retrbinary("RETR {0}".format(path), blocks.append)
  return "".join(blocks)


# Extracts the list of links from an HTML string.
def http_links_from_listing(html):
  # type: (str) -> List[str]
  pattern = re.compile(r"""href=['"]+([^'"]+)['"]+""")
  return re.findall(pattern, html)


# Extracts the list of paths (relative links, except to ../*) from an HTML string.
def http_paths_from_listing(html):
  # type: (str) -> List[str]
  paths = []
  for link in http_links_from_listing(html):
    if link.startswith(".."):
      continue
    if link == "./" or link == "/":
      continue
    if "://" in link:
      continue
    paths.append(link)
  return paths


# Downloads a file as string from an URL. Decodes correctly.
def http_download_txt(url):
  # type: (str) -> str
  try:
    r = urllib2.urlopen(url)
    encoding = r.headers.getparam("charset")
    if not encoding:
      encoding = "utf-8"
    return r.read().decode(encoding)
  except:
    raise


# Extracts the list of paths (relative links, except to ../*) from the HTML code
# located at `url`.
def http_list_dir(url):
  # type: (str) -> List[str]
  try:
    html = http_download_txt(url)
  except:
    return []
  return http_paths_from_listing(html)


# Extracts the version and maintainer info for a package, from a Debian repository Packages file.
def deb_packages_extract_version(packages, name):
  # type: (str, str) -> str, str
  inside = False
  version = None
  maintainer = None
  for line in packages.split("\n"):
    if line == "Package: " + name:
      inside = True
    elif not line:
      if inside:
        break
    else:
      if inside:
        if line.startswith("Version:"):
          version = line.split(":", 1)[-1].strip()
        elif line.startswith("Maintainer:"):
          maintainer = line.split(":", 1)[-1].strip()
  return version, maintainer

# Extracts the version and maintainer info for a package, from an Arch PKGBUILD file.
def arch_pkgbuild_extract_version(pkgbuild):
  # type: (str) -> str, str
  version = None
  maintainer = None
  for line in pkgbuild.split("\n"):
    if line.startswith("# Maintainer:"):
      maintainer = line.split(":", 1)[-1].strip()
    elif line.startswith("pkgver="):
      version = line.split("=", 1)[-1].strip()
  return version, maintainer


# Debian

def get_debian_release_version(release):
  data = http_download_txt("http://metadata.ftp-master.debian.org/changelogs/main/t/tint2/{0}_changelog".format(release))
  version = data.split("\n", 1)[0].split("(", 1)[-1].split(")", 1)[0].strip()
  maintainer = [line.split("--", 1)[-1] for line in data.split("\n") if line.startswith(" --")][0].split("  ")[0].strip()
  return release, version, maintainer


def get_debian_versions():
  return "Debian", "debian", [get_debian_release_version(release) for release in ["stable", "testing", "unstable", "experimental"]]


# Ubuntu

def get_ubuntu_versions():
  data = http_download_txt("https://api.launchpad.net/1.0/ubuntu/+archive/primary?ws.op=getPublishedSources&source_name=tint2&exact_match=true")
  data = json.loads(data)["entries"]
  data.reverse()
  versions = []
  for package in data:
    if package["status"] == "Published":
      version = package["source_package_version"]
      release = package["distro_series_link"].split("/")[-1]
      maintainer = package["package_maintainer_link"]
      versions.append((release, version, maintainer))
  return "Ubuntu", "ubuntu", versions


# BunsenLabs

def get_bunsenlabs_versions():
  dirs = http_list_dir("https://eu.pkg.bunsenlabs.org/debian/dists/")
  versions = []
  for d in dirs:
    if d.endswith("/") and "/" not in d[:-1]:
      release = d.replace("/", "")
      packages = http_download_txt("https://eu.pkg.bunsenlabs.org/debian/dists/{0}/main/binary-amd64/Packages".format(release))
      version, maintainer = deb_packages_extract_version(packages, "tint2")
      if version:
        versions.append((release, version, maintainer))
  return "BunsenLabs", "bunsenlabs", versions


# Arch

def get_arch_versions():
  pkgbuild = http_download_txt("https://git.archlinux.org/svntogit/community.git/plain/trunk/PKGBUILD?h=packages/tint2")
  version, maintainer = arch_pkgbuild_extract_version(pkgbuild)
  return "Arch Linux", "archlinux", [("Community", version, maintainer)]


# Fedora

def get_fedora_versions():
  dirs = http_list_dir("http://mirror.switch.ch/ftp/mirror/fedora/linux/development/")
  versions = []
  for d in dirs:
    if d.endswith("/") and "/" not in d[:-1]:
      release = d.replace("/", "")
      packages = http_list_dir("http://mirror.switch.ch/ftp/mirror/fedora/linux/development/{0}/Everything/source/tree/Packages/t/".format(release))
      for p in packages:
        if p.startswith("tint2-"):
          version = p.split("-", 1)[-1].split(".fc")[0]
          v = (release, version, "")
          if v not in versions:
            versions.append(v)
  return "Fedora", "fedora", versions


# Red Hat (EPEL)

def get_redhat_epel_versions():
  dirs = http_list_dir("http://mirror.switch.ch/ftp/mirror/epel/")
  versions = []
  for d in dirs:
    if d.endswith("/") and "/" not in d[:-1] and is_int(d[:-1]):
      release = d.replace("/", "")
      packages = http_list_dir("http://mirror.switch.ch/ftp/mirror/epel/{0}/SRPMS/t/".format(release))
      for p in packages:
        if p.startswith("tint2-"):
          version = p.split("-", 1)[-1].split(".el")[0]
          v = (release, version, "")
          if v not in versions:
            versions.append(v)
  return "RedHat (EPEL)", "rhel", versions


# SUSE

def get_suse_versions():
  ftp = ftplib.FTP("mirror.switch.ch")
  ftp.login()
  releases, _ = ftp_list_dir(ftp, "/mirror/opensuse/opensuse/distribution/leap/")
  versions = []
  for release in releases:
    root = "/mirror/opensuse/opensuse/distribution/leap/{0}/repo/oss/suse/repodata/".format(release)
    _, files = ftp_list_dir(ftp, root)
    for fname in files:
      if fname.endswith("-primary.xml.gz"):
        data = ftp_download(ftp, "{0}/{1}".format(root, fname))
        xml = gzip.GzipFile(fileobj=StringIO(data)).read()
        root = ET.fromstring(xml)
        for package in root.findall("{http://linux.duke.edu/metadata/common}package"):
          name = package.find("{http://linux.duke.edu/metadata/common}name").text
          if name == "tint2":
            version = package.find("{http://linux.duke.edu/metadata/common}version").get("ver")
            versions.append((release, version, ""))
  ftp.quit()
  return "OpenSUSE", "opensuse", versions


# Gentoo

def get_gentoo_versions():
  files = http_list_dir("https://gitweb.gentoo.org/repo/gentoo.git/tree/x11-misc/tint2")
  versions = []
  for f in files:
    if "tint2" in f and f.endswith(".ebuild"):
      version = f.split("tint2-")[-1].split(".ebuild")[0]
      v = ("", version, "")
      if v not in versions:
        versions.append(v)
  return "Gentoo", "gentoo", versions


# Void

def get_void_versions():
  template = http_download_txt("https://raw.githubusercontent.com/voidlinux/void-packages/master/srcpkgs/tint2/template")
  versions = []
  version = None
  maintainer = None
  for line in template.split("\n"):
    if line.startswith("version="):
      version = line.split("=", 1)[-1].replace('"', "").strip()
    elif line.startswith("maintainer="):
      maintainer = line.split("=", 1)[-1].replace('"', "").strip()
  if version:
    versions.append(("", version, maintainer))
  return "Void Linux", "void", versions


# Alpine

def get_alpine_versions():
  apkbuild = http_download_txt("https://git.alpinelinux.org/cgit/aports/plain/community/tint2/APKBUILD")
  versions = []
  version = None
  maintainer = None
  for line in apkbuild.split("\n"):
    if line.startswith("pkgver="):
      version = line.split("=", 1)[-1].replace('"', "").strip()
    elif line.startswith("# Maintainer:"):
      maintainer = line.split(":", 1)[-1].replace('"', "").strip()
  if version:
    versions.append(("", version, maintainer))
  return "Alpine Linux", "alpine", versions


# Slackware

def get_slack_versions():
  dirs = http_list_dir("https://slackbuilds.org/slackbuilds/")
  versions = []
  for d in dirs:
    if d.endswith("/") and "/" not in d[:-1]:
      release = d.replace("/", "")
      try:
        info = http_download_txt("https://slackbuilds.org/slackbuilds/{0}/desktop/tint2/tint2.info".format(release))
      except:
        continue
      version = None
      maintainer = None
      for line in info.split("\n"):
        if line.startswith("VERSION="):
          version = line.split("=", 1)[-1].replace('"', "").strip()
        elif line.startswith("MAINTAINER="):
          maintainer = line.split("=", 1)[-1].replace('"', "").strip()
      if version:
        versions.append((release, version, maintainer))
  return "Slackware", "slackware", versions

# FreeBSD

def get_freebsd_versions():
  makefile = http_download_txt("https://svnweb.freebsd.org/ports/head/x11/tint/Makefile?view=co")
  versions = []
  version = None
  maintainer = None
  for line in makefile.split("\n"):
    if line.startswith("PORTVERSION="):
      version = line.split("=", 1)[-1].strip()
    elif line.startswith("MAINTAINER="):
      maintainer = line.split("=", 1)[-1].strip()
  if version:
    versions.append(("", version, maintainer))
  return "FreeBSD", "freebsd", versions


# OpenBSD

def get_openbsd_versions():
  makefile = http_download_txt("http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/ports/x11/tint2/Makefile?rev=1.5&content-type=text/plain")
  versions = []
  version = None
  for line in makefile.split("\n"):
    if line.startswith("V="):
      version = line.split("=", 1)[-1].strip()
  if version:
    versions.append(("", version, ""))
  return "OpenBSD", "openbsd", versions


# Upstream

def get_tint2_version():
  readme = http_download_txt("https://gitlab.com/o9000/tint2/raw/master/README.md")
  version = readme.split("\n", 1)[0].split(":", 1)[-1].strip()
  return version


def main():
  latest = get_tint2_version()
  distros = []
  distros.append(get_debian_versions())
  distros.append(get_bunsenlabs_versions())
  distros.append(get_ubuntu_versions())
  distros.append(get_fedora_versions())
  distros.append(get_redhat_epel_versions())
  distros.append(get_suse_versions())
  distros.append(get_alpine_versions())
  distros.append(get_slack_versions())
  distros.append(get_arch_versions())
  distros.append(get_void_versions())
  distros.append(get_gentoo_versions())
  distros.append(get_freebsd_versions())
  distros.append(get_openbsd_versions())
  print "| Distribution | Release | Version | Status |"
  print "| ------------ | ------- | ------- | ------ |"
  for dist, dcode, releases in distros:
    icon = "![](numix-icons/distributor-logo-{0}.svg.png)".format(dcode)
    for r in releases:
      if r[1].split("-", 1)[0] == latest:
        status = ":white_check_mark: Latest"
      else:
        status = ":warning: Out of date"
      print "| {0} {1} | {2} | {3} | {4} |".format(icon, dist, r[0], r[1], status)
  utc_datetime = datetime.datetime.utcnow()
  print ""
  print "Last updated:", utc_datetime.strftime("%Y-%m-%d %H:%M UTC")


if __name__ == "__main__":
  main()