Wiki Ubuntu-it

Indice
Partecipa
FAQ
Wiki Blog
------------------
Ubuntu-it.org
Forum
Chiedi
Chat
Cerca
Planet
  • Pagina non alterabile
  • Informazioni
  • Allegati
  • attachment:debomatic-webui-wiki.py di LeoIannacone/Debomatic-webui

Allegato "debomatic-webui-wiki.py"

Scarica

   1 #!/usr/bin/python
   2 
   3 from urllib2 import urlopen
   4 from argparse import ArgumentParser
   5 import re
   6 import os
   7 
   8 class Task():
   9 
  10     def __init__(self, task, args):
  11 
  12         self.style = None
  13         self.bug = None
  14         self.message = None
  15 
  16         if args.not_needed:
  17             self.style = 'background:#f5f5f5;color:#333333'
  18         elif args.in_progress:
  19             self.style = 'background:#D9EDF7;color:#31708F'
  20         elif args.warning:
  21             self.style = 'background:#FCF8E3;color:#8A6D3B'
  22         elif args.done:
  23             self.style = 'background:#DFF0D8;color:#3C763D'
  24         elif args.error:
  25             self.style = 'background:#F2DEDE;color:#A94442'
  26         elif re.match(r'<style="(.*)">', task):
  27             self.style = re.findall(r'<style="(.*)">', task)[0]
  28 
  29         if args.bug:
  30             self.bug = args.bug
  31         elif re.search(r'<<Bug\(debian (.*)\)>>', task):
  32             self.bug = re.findall(r'<<Bug\(debian (.*)\)>>', task)[0]
  33 
  34         if args.message:
  35             self.message = args.message
  36         elif len(task.split('>>')) > 1:
  37             self.message = task.split('>>')[1].strip()
  38         elif len(task.split('>')) > 1:
  39             self.message = task.split('>')[1].strip()
  40         else:
  41             self.message = task
  42 
  43     def __str__(self):
  44         result = ""
  45         if self.style:
  46             result += '<style="%s">' % self.style
  47         if self.bug:
  48             result += " <<Bug(debian %s)>>" % self.bug
  49         if self.message:
  50             result += " %s" % self.message
  51         return result
  52 
  53 
  54 def _edit_line(line, args):
  55     info = line.split('||')
  56 
  57     info[-2] = "%s" % Task(info[-2], args)
  58 
  59     return '||'.join(info)
  60 
  61 
  62 def main():
  63 
  64     if not os.path.exists('/usr/bin/xclip'):
  65         print("Install xclip:\n\n\tsudo apt-get install xclip\n")
  66         exit(1)
  67 
  68     usage = "%(prog)s [options] package_name"
  69     parser = ArgumentParser(prog='debomatic-webui-wiki', usage=usage)
  70     group = parser.add_mutually_exclusive_group()
  71 
  72     group.add_argument('-d', '--done', action="store_true", \
  73         default=False, help='job complete')
  74     group.add_argument('-e', '--error', action="store_true", \
  75         default=False, help='there is some strong issue')
  76     group.add_argument('-i', '--in-progress', action="store_true", \
  77         default=False, help='work in progress')
  78     group.add_argument('-n', '--not-needed', action="store_true", \
  79         default=False, help='no work needed')
  80     group.add_argument('-w', '--warning', action="store_true", \
  81         default=False, help='someone else has been warned about')
  82 
  83 
  84     parser.add_argument('-b', '--bug', help="add a debian bug")
  85     parser.add_argument('-m', '--message', help="leave a message")
  86 
  87     parser.add_argument('package_name', help='the package name')
  88 
  89     args = parser.parse_args()
  90 
  91     url_base = "http://wiki.ubuntu-it.org/LeoIannacone/Debomatic-webui"
  92 
  93     page = urlopen('%s?action=raw' % url_base).read().split('\n')
  94 
  95     found = False
  96     for i in range(0, len(page)):
  97         if page[i].find("%s (" % args.package_name) > 0:
  98             found = True
  99             page[i] = _edit_line(page[i], args)
 100             break
 101     if not found:
 102         print("%s not found." % args.package_name)
 103         exit(1)
 104 
 105     with os.popen('xclip -selection c', 'w') as xclip:
 106         xclip.write('\n'.join(page))
 107 
 108     print("Result is in your clipboard. Just paste in the browser.")
 109     os.system("xdg-open %s?action=edit&editor=text" % url_base)
 110 
 111 
 112 if __name__ == '__main__':
 113     main()

Allegati

Per riferirsi agli allegati di una pagina, usare attachment:NOME_FILE, come mostrato qui sotto nell'elenco degli allegati. NON usare l'URL che si trova in corrispondenza del collegamento [scarica], potrebbe cambiare in futuro.
  • [scarica | mostra] (28/03/2014 17.26.00, 3.4 KB) [[attachment:debomatic-webui-wiki.py]]
 All files | Selected Files: delete move to page copy to page

Non รจ consentito inserire allegati su questa pagina.