aboutsummaryrefslogtreecommitdiffstats
path: root/docs/images/images.py
blob: 261ebc5a1f5c5818794c7b761f31df970e671193 (plain)
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re, sys, os, getopt, subprocess, urllib2

def usage():
    print '\nUsage: python %s [OPTION]' %os.path.basename(sys.argv[0])
    print '       Show the list of missing images for given locale and docs name'
    print 'Options: -h, --help                       : usage'
    print '         -l <locale>, --locale=<locale>   : locale to test (default is "uk")'
    print '         -d <docs>, --docs=<docs>         : docs to test (installer (default) or mcc)'
    print '         -s <source>, --source=<source>   : source (webdav (default) or svn)'
    sys.exit(2)
try:
    opts, args = getopt.getopt(sys.argv[1:], "hd:l:s:", ["help", "docs=", "locale=", "source="])
except getopt.GetoptError as err:
    print str(err)
    usage() # print help information and exit
    sys.exit(2)

docs = ''
locale = ''
source = ''

for o,a in opts:
    if o in ("-h", "--help"):
        usage()
    elif o in ("-d", "--docs"):
        docs=a
    elif o in ("-l", "--locale"):
        locale=a
    elif o in ("-s", "--source"):
        source=a

if docs == '':
  docs = 'installer'

if locale == '':
  locale = 'uk'

if source == 'svn':
  command_template = "svn list svn://svn.mageia.org/svn/soft/mageia-doc/trunk/%s/%s/images/ -R"
  download_command = command_template %(docs, locale)
else:
  command_template = "kioclient ls webdav://vargas.calenco.com:8284/workspaces/Documentation/content/%s/"
  download_command = command_template %locale

existing_images = []

proc = subprocess.Popen(download_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
  line = proc.stdout.readline()
  if line != '':
    existing_images.append(line.rstrip())
  else:
    break

if docs == 'installer':
  po_url = "http://gitweb.mageia.org/software/i18n/tools/plain/docs/installer/%s.po" %locale
if docs == 'mcc':
  po_url = "http://gitweb.mageia.org/software/i18n/tools/plain/docs/mcc-help/%s.po" %locale

response = urllib2.urlopen(po_url)
po_text = response.read().replace('\"\n\"','')

dirty_list = []

regexpression='[\w-]{1,}\.png'
such=re.compile(regexpression,re.DOTALL)
for image in such.findall(po_text):
  image_name = image.strip('')
  #add image_name
  if not(image_name in existing_images):
    dirty_list.append(image)
    
list = sorted(set(dirty_list))
print 'Missing images for the %s docs (locale %s):\n-------------------------------' %(docs, locale)
print "\n".join(list)
print '-------------------------------'