]> git.parisson.com Git - yomguy-tools.git/commitdiff
Reorganize tools
authoryomguy <yomguy@457c0346-1240-4656-8a5a-9edca8063506>
Wed, 16 Jan 2008 13:01:18 +0000 (13:01 +0000)
committeryomguy <yomguy@457c0346-1240-4656-8a5a-9edca8063506>
Wed, 16 Jan 2008 13:01:18 +0000 (13:01 +0000)
git-svn-id: http://svn.parisson.org/svn/tools/trunk@31 457c0346-1240-4656-8a5a-9edca8063506

12 files changed:
mail_restartd.py [deleted file]
pyfapg.py [deleted file]
python-telesql/teleSQL.py [new file with mode: 0755]
python-zopebackup/zope_backup.py [new file with mode: 0755]
python-zopebackup/zope_instance.py [new file with mode: 0644]
teleSQL.py [deleted file]
various/mail_restartd.py [new file with mode: 0755]
various/pyfapg.py [new file with mode: 0755]
various/webthumb_list.py [new file with mode: 0755]
webthumb_list.py [deleted file]
zope_backup.py [deleted file]
zope_instance.py [deleted file]

diff --git a/mail_restartd.py b/mail_restartd.py
deleted file mode 100755 (executable)
index d75c5e0..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/usr/bin/python
-
-import os
-import time
-
-service = 'apache2'
-mails = ['yomguy@sfr.fr','pellerin@parisson.com']
-server = 'ns37892'
-file = '/tmp/restartd_apache.tmp'
-
-def touch_and_mail(server, service, mails, file):
-    for mail in mails:
-        command = 'echo "'+service+' crashed" | mail -s"'+server+'" '+mail
-        os.system('touch '+file)
-        os.system(command)
-
-
-if not os.path.exists(file):
-    touch_and_mail(server, service, mails, file)
-
-date = os.path.getmtime(file)
-laps = time.time() - date
-print laps
-if laps > 120:
-    touch_and_mail(server, service, mails, file)
-
-
diff --git a/pyfapg.py b/pyfapg.py
deleted file mode 100755 (executable)
index 4ade468..0000000
--- a/pyfapg.py
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/usr/bin/python
-# 1 mp3 to m3u
-# depends: fapg
-
-import os, sys, string
-
-host = 'audio.pre-barreau.com'
-root_dir = '/home/pro-barreau/www/audio'
-web_dir = '/'
-types = ['mp3','ogg','flac']
-
-#s.chdir(root_dir)
-
-for root, dirs, files in os.walk(root_dir+web_dir):
-    #print root
-    for file in files:
-        file_split = file.split('.')
-        filename = file_split[len(file_split)-2]
-        #print filename
-        if not os.path.exists(root+os.sep+filename+'.m3u'):
-            fileext = file_split[len(file_split)-1]
-            if fileext in types :
-                os.chdir(root_dir)
-                prefix = 'http://'+host+'/'
-                dest_dir = string.replace(root,'/home/pro-barreau/www/audio/','')
-                file_new = string.replace(file,' ','_')
-                filename_new = string.replace(filename,' ','_')
-                if file_new != file: 
-                    os.system('mv "'+dest_dir+os.sep+file+'" "'+dest_dir+os.sep+file_new+'"')
-                os.system('fapg -f m3u -p '+prefix+' -o "'+root+os.sep+filename_new+'.m3u" "'+dest_dir+os.sep+file_new+'"')
-
diff --git a/python-telesql/teleSQL.py b/python-telesql/teleSQL.py
new file mode 100755 (executable)
index 0000000..6c4d098
--- /dev/null
@@ -0,0 +1,264 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2007-2007 Guillaume Pellerin <yomguy@parisson.com>
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution. The terms
+# are also available at http://svn.parisson.org/d-fuzz/DFuzzLicense.
+#
+# Author: Guillaume Pellerin <yomguy@parisson.com>
+
+
+import os
+import sys
+import datetime
+import codecs
+import string
+import MySQLdb
+from sqltools import *
+
+
+class TeleSQL:
+
+    def __init__(self, db1, db2):
+        self.db1 = db1['db']
+        self.host1 = db1['host']
+        self.user1 = db1['user']
+        self.passwd1 = db1['passwd']
+        self.port1 = int(db1['port'])
+
+        self.db2 = db2['db']
+        self.host2 = db2['host']
+        self.user2 = db2['user']
+        self.passwd2 = db2['passwd']
+        self.port2 = int(db2['port'])
+        
+        self.sql_db1 = sql_db(self.db1, self.host1, self.user1, self.passwd1, self.port1)
+        self.sql_db2 = sql_db(self.db2, self.host2, self.user2, self.passwd2, self.port2)
+            
+    def upgrade_secondary_table(self, dict):
+        """Update incremental tables in colums of the DB n°2 from some colums in
+        the main DB n°1 respectively to a given filter dictionnary (see example below)"""
+
+        table1 = dict['table1']
+        table2 = dict['table2']
+        col1tocol2 = dict['col1tocol2']
+        filter_dict = filetodict(dict['filter'])
+        default_value = dict['default']
+        
+        col1 = col1tocol2.keys()
+        col1 = col1[0]
+        col2 = col1tocol2[col1]
+        print table1 + ' ('+col1+') => '+table2+' ('+ col2 +')'
+        
+        data1_t = sql_command_fetch(self.sql_db1, "SELECT " + col1 + " from %s.%s " % (self.db1, table1))
+        #print data1_t
+        data1_l = tuple2list2_latin(data1_t)
+        #print data1_l
+
+        data2_t = sql_command_fetch(self.sql_db2, "SELECT " + col2 + " from %s.%s " % (self.db2, table2))
+        data2_l = tuple2list2_latin(data2_t)
+        data2_l_low = tuple2list2_low_latin(data2_t)
+        data2_l_cap = tuple2list2_cap_latin(data2_t)
+
+        count = 0
+        wrong_data = open(self.db2 + '_' + table2 + '_bonus' +'.csv','w')
+        
+        for data in data1_l:
+            data = unicode(data)
+            data_corr = get_data_corr(data, filter_dict)
+            #print data_corr
+                
+            if not data_corr in data2_l and \
+                not data_corr.lower() in data2_l_low and \
+                not data_corr.lower() in data2_l and \
+                not data_corr.capitalize() in data2_l_cap and \
+                not data_corr.capitalize() in data2_l:
+
+                db2c = self.sql_db2.cursor()
+                db2c.execute("INSERT INTO "+table2+" ("+col2+") VALUES (%("+col2+")s)", {col2: data_corr})
+                #print 'INSERTED'
+                data2_t = sql_command_fetch(self.sql_db2, "SELECT " + col2 + " from %s.%s" % (self.db2, table2))
+                data2_l = tuple2list2_latin(data2_t)
+                data2_l_low = tuple2list2_low_latin(data2_t)
+                data2_l_cap = tuple2list2_cap_latin(data2_t)
+                count = count + 1
+                wrong_data.write(data_corr.encode('utf-8')+'\n')
+            else:
+                pass
+                #print 'EXISTS'
+
+        print table2 + ': ' +str(count) +' updated'
+        print '========================================================================'
+        wrong_data.close()
+        self.sql_db2.commit()
+        self.sql_db1.close()
+        self.sql_db2.close()
+
+
+
+    def update_main_table(self, dict):
+        
+        table1 = dict['table1']
+        table2 = dict['table2']
+        col1tocol2 = dict['col1tocol2']
+        date_limit = dict['date_limit']
+        meta_dict = dict['meta_dict']
+        
+        col1_t = sql_command_fetch(self.sql_db1,'SHOW columns from '+ self.db1 + '.' + table1)
+        #print col1_t
+        col1_l = []
+        for col in col1_t:
+            col1_l.append(col[0])
+
+        col2_t = sql_command_fetch(self.sql_db2,'SHOW columns from '+ self.db2 + '.' + table2)
+        #print col2_t
+        col2_l = []
+        for col in col2_t:
+            col2_l.append(col[0])
+        
+        print "-----------------------------------------"
+        print 'Table 1:'
+        print col1_l
+        print 'Table 2:'
+        print col2_l
+
+        # Fetch all data
+        data1_t = sql_command_fetch(self.sql_db1, """SELECT * from %s.%s """ % (self.db1, table1))
+        data2_t = sql_command_fetch(self.sql_db2, """SELECT * from %s.%s """ % (self.db2, table2))
+
+        #sys.exit()
+        
+        dates_ok = 0
+        dates = 0
+
+        for data in data1_t:
+            
+            #print data
+            dict_1 = tuple2dict(col1_l, data)
+            #print dict_1
+            dict_2 = tuple2dict(col2_l)
+            #print dict_3
+            dict_2 = dict1todict2(dict_1, col1tocol2, dict_2)
+            
+            #print meta_dict.keys()
+
+            for item in meta_dict.keys():
+                #print item
+                item_table = meta_dict[item]['table']
+                item_default = meta_dict[item]['default']
+                item_cols = sql_command_fetch(self.sql_db1,'SHOW columns from '+ self.db2 + '.' + item_table)
+                item_cols_l = []
+                for col in item_cols:
+                    item_cols_l.append(col[0])
+                
+                item_data = sql_command_fetch(self.sql_db2, """SELECT * from %s.%s """ % (self.db2, item_table))
+                item_data_d = []
+                for dat in item_data:
+                    item_data_d.append(tuple2dict(item_cols_l, dat))
+                    
+                #item_data_d = tuple2dict(item_data)
+                item_dict = filetodict(meta_dict[item]['filter'])
+                item_value = dict_1[item].decode('latin1')
+                item_id_name = meta_dict[item]['id']
+
+                #print item_dict
+                
+                if item_value in item_dict.keys():
+                    item_value = get_data_corr(item_value, item_dict, item_default)
+                
+                for value in item_data_d:
+                    #print value
+                    value_new = value['nom'].decode('latin1')
+                    if item_value ==  value_new or \
+                        item_value ==  value_new.lower() or \
+                        item_value ==  value_new.capitalize() or \
+                        item_value.lower() ==  value_new.lower() or \
+                        item_value.capitalize() ==  value_new.capitalize():
+
+                        #print item_value +': ' + item_id_name + ' = ' + str(value['id'])
+                        dict_2[item_id_name] = value['id']
+
+            db2c = self.sql_db2.cursor()
+            db2c.execute("""INSERT INTO emissions (titre, date_diffusion, realisateur_id, duree, genre_id, resume, master, position, radio_id) VALUES (%(titre)s, %(date_diffusion)s, %(realisateur_id)s, %(duree)s, %(genre_id)s, %(resume)s, %(master)s, %(position)s, %(radio_id)s)""", dict_2)
+            dates_ok = dates_ok + 1
+            dates = dates + 1
+            #print dates
+
+            #if dates == 10:
+            #    break
+
+        self.sql_db2.commit()
+        self.sql_db1.close()
+        self.sql_db2.close()
+
+        print "--------------------------------------------"
+        print "Number of items inserted :" + str(dates_ok)
+        print "Total number of items :" + str(dates)
+       
+
+# -----------------------------------------------
+
+db1 = {'host':   'localhost',
+          'user':    'epra',
+          'passwd':  'testepra',
+          'db':      'epra_fm',
+          'port':    '3306'}
+
+
+db2 = {'host':   'localhost',
+          'user':    'epra',
+          'passwd':  'testepra',
+          'db':      'epra',
+          'port':    '3306'}
+
+vector1 = {'table1': 'diffusions',
+            'table2': 'radios',
+            'col1tocol2': {'station': 'nom'},
+            'default': 'Radio',
+            'filter': 'FM.Stations_filter_2.csv'}
+
+vector2 = {'table1': 'diffusions',
+            'table2': 'realisateurs',
+            'col1tocol2': {'auteur': 'nom'},
+            'default': '',
+            'filter': 'FM.Realisateurs_filter.csv',
+            'split': '1'}
+
+vector3 = {'table1': 'diffusions',
+            'table2': 'genres',
+            'col1tocol2': {'genre': 'nom'},
+            'default': '',
+            'filter': 'FM.Genres_filter.csv'}
+
+vector4 = {'table1': 'diffusions',
+           'table2': 'emissions',
+           'col1tocol2': {'titre': 'titre',
+                        'date_diffusion': 'datedifsat' ,
+                        'duree': 'dureedif',
+                        'resume': 'resume',
+                        'master': 'nummaster',
+                        'position': 'positionsat'},
+           'date_limit': '20021201',
+           'meta_dict': {'station': {'table': 'radios', 'id': 'radio_id', 'default':'Radio', 'filter': 'FM.Stations_filter_2.csv'},
+                           'genre': {'table': 'genres', 'id': 'genre_id', 'default': '', 'filter': 'FM.Genres_filter.csv'},
+                           'auteur': {'table': 'realisateurs', 'id': 'realisateur_id', 'default': '', 'filter': 'FM.Realisateurs_filter.csv'}
+                           }}
+
+secondary_vectors = (vector1, vector2, vector3)
+main_vector = vector4
+
+
+def main():    
+    for vector in secondary_vectors:
+        sql_db = TeleSQL(db1, db2)
+        sql_db.upgrade_secondary_table(vector)
+    sql_db = TeleSQL(db1, db2)
+    sql_db.update_main_table(main_vector)
+    print 'Done !'
+    
+if __name__ == '__main__':
+    main()
+            
diff --git a/python-zopebackup/zope_backup.py b/python-zopebackup/zope_backup.py
new file mode 100755 (executable)
index 0000000..e4240f7
--- /dev/null
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+# Backups all zope instances (any versions)
+#
+# Depends : zope_instance.py
+# Copyright (C) 2007-2008 Guillaume Pellerin
+
+import os
+import sys
+from zope_instance import *
+
+version = '0.2'
+info = 'zope_backup v'+version+'\n'+ \
+       """Copyright (C) 2007-2008 Guillaume Pellerin
+       Usage: zope_backup DIRECTORY
+       where DIRECTORY is the directory where you want to backup 
+       the instances of the different versions of zope."""
+
+if len(sys.argv) < 2:
+    sys.exit(info)
+else :
+    backup_dir = sys.argv[1]
+
+z = ZopeInstall()
+instances = z.get_instances()
+instance_main_dir = z.instance_main_dir
+
+def backup_all():
+    for version in instances:
+       for instance in instances[version]:
+            z = ZopeInstance(version, instance)
+           print z.get_instance_dir()
+            z.backup(backup_dir)
+           print version + ': ' + instance + ' backuped !'
+
+if __name__ == '__main__':
+    backup_all()
+    print "Backup_all Zopes done !"
+
+    
+        
diff --git a/python-zopebackup/zope_instance.py b/python-zopebackup/zope_instance.py
new file mode 100644 (file)
index 0000000..f45a3e1
--- /dev/null
@@ -0,0 +1,138 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2007 Guillaume Pellerin <yomguy@parisson.com>
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Guillaume Pellerin <yomguy@parisson.com>
+
+
+import os
+import sys
+from optparse import OptionParser
+
+
+class ZopeInstall:
+    """This give the main parameters of the Zope installations respectively to the
+       distribution used"""
+
+    def __init__(self):
+        self.versions = ['2.7', '2.9', '2.8', '2.10']
+       self.instance_main_dir = '/var/lib'
+       self.zope_main_dir = '/usr/lib'
+
+
+    def get_instances(self):
+        """Return all instances in all zope versions installed"""
+        dict = {}
+        for version in self.versions:
+            #print version
+            path = self.instance_main_dir + os.sep + 'zope' + version + os.sep + 'instance'
+            if os.path.exists(path):
+                dict[version] = os.listdir(path)
+                #print dict
+        return dict
+
+
+class ZopeInstance(ZopeInstall):
+    """Expose Zope instances to several python methods that simplifies admins' life
+    (backup, recover, import, etc...)"""
+    
+    def __init__(self, version, instance):
+        ZopeInstall.__init__(self)
+       self.version = version
+        self.instance = instance
+        self.instance_dir = self.instance_main_dir + os.sep + 'zope' + version + os.sep + \
+                        'instance' + os.sep + self.instance
+        self.instance_data = self.instance_dir + os.sep + 'var' + os.sep + 'Data.fs'
+        self.instance_products = self.instance_dir + os.sep + 'Products' + os.sep
+        self.instance_var = self.instance_dir + os.sep + 'var' + os.sep
+        self.instance_etc = self.instance_dir + os.sep + 'etc' + os.sep
+       self.repozo = self.zope_main_dir + os.sep + 'zope' + self.version + os.sep + 'bin' + os.sep + 'repozo.py'
+
+    def get_instance_dir(self):
+        return self.instance_dir
+    
+    def backup(self, backup_dir):
+       """Backup the instance"""
+        self.backup_dir = backup_dir
+       self.instance_backup_dir = self.backup_dir + os.sep + self.version + os.sep + self.instance
+
+        path = self.instance_backup_dir+ os.sep + 'Data'
+        if not os.path.exists(path):
+            os.makedirs(path)
+        if os.path.exists(self.instance_data):
+            command = self.repozo +' -Bvz -r ' + path + ' -f ' + self.instance_data
+            os.system(command)
+            command = 'chmod 700 ' + path + os.sep + '*'
+            os.system(command)
+        else:
+            print self.instance_data + ' does not exists !'
+        if not os.path.exists(self.instance_backup_dir):
+            os.makedirs(self.instance_backup_dir)
+        if os.path.exists(self.instance_products):
+            command = 'tar czf ' + self.instance_backup_dir + os.sep + \
+                      'Products.tar.gz ' + self.instance_products
+            os.system(command)
+        if os.path.exists(self.instance_var):
+            command = 'tar czf ' + self.instance_backup_dir + os.sep + \
+                      'var.tar.gz ' + self.instance_var + ' --exclude=Data.fs'
+            os.system(command)
+        if os.path.exists(self.instance_etc):
+            command = 'tar czf ' + self.instance_backup_dir + os.sep + \
+                      'etc.tar.gz ' + self.instance_etc
+            os.system(command)
+        print self.instance + ' backuped !'
+
+    def recover(self):
+        """Recover the instance from a backup"""
+        os.chdir(self.instance_backup_dir)
+        command = 'tar xzf '+self.instance_backup_dir+os.sep+'Products.tar.gz && ' + \
+                  'rsync -a --delete ' + self.instance_backup_dir+os.sep+self.instance_products + \
+                               ' ' + self.instance_products + os.sep + ' && ' + \
+                  'chown -R zope:zope ' + self.instance_products + ' && ' + \
+                  'rm -rf ' + self.instance_backup_dir+os.sep+'var'
+        os.system(command)
+        command = 'tar xzf '+self.instance_backup_dir+os.sep+'var.tar.gz && ' + \
+                  'rsync -a --delete ' + self.instance_backup_dir + os.sep  + self.instance_var + \
+                                ' ' + self.instance_var + os.sep + ' && ' + \
+                  'chown -R zope:zope ' + self.instance_var + ' && ' + \
+                  'rm -rf ' + self.instance_backup_dir+os.sep+'var'
+        os.system(command)
+        command = self.instance_dir+os.sep+'bin'+os.sep+'zopectl restart'            
+        os.system(command)
+        command = self.repozo + ' -Rvz -r ' + self.instance_backup_dir + os.sep + \
+                    'Data -o ' + self.instance_data
+        if os.path.exists(self.instance_data):
+            os.system(command)
+        else:
+            print self.instance_data + ' does not exists !'
+        print self.instance + ' recovered !'
+        
+    def import_from(self, user, server):
+        command = 'rsync -a --rsh="ssh -l '+user+'" ' + \
+                  user+'@'+server+':'+self.instance_backup_dir+os.sep + ' ' + self.instance_backup_dir+os.sep
+        os.system(command)
+
+    def export_to(self, user, server):
+        command = 'rsync -a --rsh="ssh -l '+user+'" ' + \
+                  self.instance_backup_dir+os.sep  + ' ' + user+'@'+server+':'+self.instance_backup_dir+os.sep
+        os.system(command)
+
+
diff --git a/teleSQL.py b/teleSQL.py
deleted file mode 100755 (executable)
index 6c4d098..0000000
+++ /dev/null
@@ -1,264 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-#
-# Copyright (c) 2007-2007 Guillaume Pellerin <yomguy@parisson.com>
-# All rights reserved.
-#
-# This software is licensed as described in the file COPYING, which
-# you should have received as part of this distribution. The terms
-# are also available at http://svn.parisson.org/d-fuzz/DFuzzLicense.
-#
-# Author: Guillaume Pellerin <yomguy@parisson.com>
-
-
-import os
-import sys
-import datetime
-import codecs
-import string
-import MySQLdb
-from sqltools import *
-
-
-class TeleSQL:
-
-    def __init__(self, db1, db2):
-        self.db1 = db1['db']
-        self.host1 = db1['host']
-        self.user1 = db1['user']
-        self.passwd1 = db1['passwd']
-        self.port1 = int(db1['port'])
-
-        self.db2 = db2['db']
-        self.host2 = db2['host']
-        self.user2 = db2['user']
-        self.passwd2 = db2['passwd']
-        self.port2 = int(db2['port'])
-        
-        self.sql_db1 = sql_db(self.db1, self.host1, self.user1, self.passwd1, self.port1)
-        self.sql_db2 = sql_db(self.db2, self.host2, self.user2, self.passwd2, self.port2)
-            
-    def upgrade_secondary_table(self, dict):
-        """Update incremental tables in colums of the DB n°2 from some colums in
-        the main DB n°1 respectively to a given filter dictionnary (see example below)"""
-
-        table1 = dict['table1']
-        table2 = dict['table2']
-        col1tocol2 = dict['col1tocol2']
-        filter_dict = filetodict(dict['filter'])
-        default_value = dict['default']
-        
-        col1 = col1tocol2.keys()
-        col1 = col1[0]
-        col2 = col1tocol2[col1]
-        print table1 + ' ('+col1+') => '+table2+' ('+ col2 +')'
-        
-        data1_t = sql_command_fetch(self.sql_db1, "SELECT " + col1 + " from %s.%s " % (self.db1, table1))
-        #print data1_t
-        data1_l = tuple2list2_latin(data1_t)
-        #print data1_l
-
-        data2_t = sql_command_fetch(self.sql_db2, "SELECT " + col2 + " from %s.%s " % (self.db2, table2))
-        data2_l = tuple2list2_latin(data2_t)
-        data2_l_low = tuple2list2_low_latin(data2_t)
-        data2_l_cap = tuple2list2_cap_latin(data2_t)
-
-        count = 0
-        wrong_data = open(self.db2 + '_' + table2 + '_bonus' +'.csv','w')
-        
-        for data in data1_l:
-            data = unicode(data)
-            data_corr = get_data_corr(data, filter_dict)
-            #print data_corr
-                
-            if not data_corr in data2_l and \
-                not data_corr.lower() in data2_l_low and \
-                not data_corr.lower() in data2_l and \
-                not data_corr.capitalize() in data2_l_cap and \
-                not data_corr.capitalize() in data2_l:
-
-                db2c = self.sql_db2.cursor()
-                db2c.execute("INSERT INTO "+table2+" ("+col2+") VALUES (%("+col2+")s)", {col2: data_corr})
-                #print 'INSERTED'
-                data2_t = sql_command_fetch(self.sql_db2, "SELECT " + col2 + " from %s.%s" % (self.db2, table2))
-                data2_l = tuple2list2_latin(data2_t)
-                data2_l_low = tuple2list2_low_latin(data2_t)
-                data2_l_cap = tuple2list2_cap_latin(data2_t)
-                count = count + 1
-                wrong_data.write(data_corr.encode('utf-8')+'\n')
-            else:
-                pass
-                #print 'EXISTS'
-
-        print table2 + ': ' +str(count) +' updated'
-        print '========================================================================'
-        wrong_data.close()
-        self.sql_db2.commit()
-        self.sql_db1.close()
-        self.sql_db2.close()
-
-
-
-    def update_main_table(self, dict):
-        
-        table1 = dict['table1']
-        table2 = dict['table2']
-        col1tocol2 = dict['col1tocol2']
-        date_limit = dict['date_limit']
-        meta_dict = dict['meta_dict']
-        
-        col1_t = sql_command_fetch(self.sql_db1,'SHOW columns from '+ self.db1 + '.' + table1)
-        #print col1_t
-        col1_l = []
-        for col in col1_t:
-            col1_l.append(col[0])
-
-        col2_t = sql_command_fetch(self.sql_db2,'SHOW columns from '+ self.db2 + '.' + table2)
-        #print col2_t
-        col2_l = []
-        for col in col2_t:
-            col2_l.append(col[0])
-        
-        print "-----------------------------------------"
-        print 'Table 1:'
-        print col1_l
-        print 'Table 2:'
-        print col2_l
-
-        # Fetch all data
-        data1_t = sql_command_fetch(self.sql_db1, """SELECT * from %s.%s """ % (self.db1, table1))
-        data2_t = sql_command_fetch(self.sql_db2, """SELECT * from %s.%s """ % (self.db2, table2))
-
-        #sys.exit()
-        
-        dates_ok = 0
-        dates = 0
-
-        for data in data1_t:
-            
-            #print data
-            dict_1 = tuple2dict(col1_l, data)
-            #print dict_1
-            dict_2 = tuple2dict(col2_l)
-            #print dict_3
-            dict_2 = dict1todict2(dict_1, col1tocol2, dict_2)
-            
-            #print meta_dict.keys()
-
-            for item in meta_dict.keys():
-                #print item
-                item_table = meta_dict[item]['table']
-                item_default = meta_dict[item]['default']
-                item_cols = sql_command_fetch(self.sql_db1,'SHOW columns from '+ self.db2 + '.' + item_table)
-                item_cols_l = []
-                for col in item_cols:
-                    item_cols_l.append(col[0])
-                
-                item_data = sql_command_fetch(self.sql_db2, """SELECT * from %s.%s """ % (self.db2, item_table))
-                item_data_d = []
-                for dat in item_data:
-                    item_data_d.append(tuple2dict(item_cols_l, dat))
-                    
-                #item_data_d = tuple2dict(item_data)
-                item_dict = filetodict(meta_dict[item]['filter'])
-                item_value = dict_1[item].decode('latin1')
-                item_id_name = meta_dict[item]['id']
-
-                #print item_dict
-                
-                if item_value in item_dict.keys():
-                    item_value = get_data_corr(item_value, item_dict, item_default)
-                
-                for value in item_data_d:
-                    #print value
-                    value_new = value['nom'].decode('latin1')
-                    if item_value ==  value_new or \
-                        item_value ==  value_new.lower() or \
-                        item_value ==  value_new.capitalize() or \
-                        item_value.lower() ==  value_new.lower() or \
-                        item_value.capitalize() ==  value_new.capitalize():
-
-                        #print item_value +': ' + item_id_name + ' = ' + str(value['id'])
-                        dict_2[item_id_name] = value['id']
-
-            db2c = self.sql_db2.cursor()
-            db2c.execute("""INSERT INTO emissions (titre, date_diffusion, realisateur_id, duree, genre_id, resume, master, position, radio_id) VALUES (%(titre)s, %(date_diffusion)s, %(realisateur_id)s, %(duree)s, %(genre_id)s, %(resume)s, %(master)s, %(position)s, %(radio_id)s)""", dict_2)
-            dates_ok = dates_ok + 1
-            dates = dates + 1
-            #print dates
-
-            #if dates == 10:
-            #    break
-
-        self.sql_db2.commit()
-        self.sql_db1.close()
-        self.sql_db2.close()
-
-        print "--------------------------------------------"
-        print "Number of items inserted :" + str(dates_ok)
-        print "Total number of items :" + str(dates)
-       
-
-# -----------------------------------------------
-
-db1 = {'host':   'localhost',
-          'user':    'epra',
-          'passwd':  'testepra',
-          'db':      'epra_fm',
-          'port':    '3306'}
-
-
-db2 = {'host':   'localhost',
-          'user':    'epra',
-          'passwd':  'testepra',
-          'db':      'epra',
-          'port':    '3306'}
-
-vector1 = {'table1': 'diffusions',
-            'table2': 'radios',
-            'col1tocol2': {'station': 'nom'},
-            'default': 'Radio',
-            'filter': 'FM.Stations_filter_2.csv'}
-
-vector2 = {'table1': 'diffusions',
-            'table2': 'realisateurs',
-            'col1tocol2': {'auteur': 'nom'},
-            'default': '',
-            'filter': 'FM.Realisateurs_filter.csv',
-            'split': '1'}
-
-vector3 = {'table1': 'diffusions',
-            'table2': 'genres',
-            'col1tocol2': {'genre': 'nom'},
-            'default': '',
-            'filter': 'FM.Genres_filter.csv'}
-
-vector4 = {'table1': 'diffusions',
-           'table2': 'emissions',
-           'col1tocol2': {'titre': 'titre',
-                        'date_diffusion': 'datedifsat' ,
-                        'duree': 'dureedif',
-                        'resume': 'resume',
-                        'master': 'nummaster',
-                        'position': 'positionsat'},
-           'date_limit': '20021201',
-           'meta_dict': {'station': {'table': 'radios', 'id': 'radio_id', 'default':'Radio', 'filter': 'FM.Stations_filter_2.csv'},
-                           'genre': {'table': 'genres', 'id': 'genre_id', 'default': '', 'filter': 'FM.Genres_filter.csv'},
-                           'auteur': {'table': 'realisateurs', 'id': 'realisateur_id', 'default': '', 'filter': 'FM.Realisateurs_filter.csv'}
-                           }}
-
-secondary_vectors = (vector1, vector2, vector3)
-main_vector = vector4
-
-
-def main():    
-    for vector in secondary_vectors:
-        sql_db = TeleSQL(db1, db2)
-        sql_db.upgrade_secondary_table(vector)
-    sql_db = TeleSQL(db1, db2)
-    sql_db.update_main_table(main_vector)
-    print 'Done !'
-    
-if __name__ == '__main__':
-    main()
-            
diff --git a/various/mail_restartd.py b/various/mail_restartd.py
new file mode 100755 (executable)
index 0000000..d75c5e0
--- /dev/null
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+
+import os
+import time
+
+service = 'apache2'
+mails = ['yomguy@sfr.fr','pellerin@parisson.com']
+server = 'ns37892'
+file = '/tmp/restartd_apache.tmp'
+
+def touch_and_mail(server, service, mails, file):
+    for mail in mails:
+        command = 'echo "'+service+' crashed" | mail -s"'+server+'" '+mail
+        os.system('touch '+file)
+        os.system(command)
+
+
+if not os.path.exists(file):
+    touch_and_mail(server, service, mails, file)
+
+date = os.path.getmtime(file)
+laps = time.time() - date
+print laps
+if laps > 120:
+    touch_and_mail(server, service, mails, file)
+
+
diff --git a/various/pyfapg.py b/various/pyfapg.py
new file mode 100755 (executable)
index 0000000..4ade468
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+# 1 mp3 to m3u
+# depends: fapg
+
+import os, sys, string
+
+host = 'audio.pre-barreau.com'
+root_dir = '/home/pro-barreau/www/audio'
+web_dir = '/'
+types = ['mp3','ogg','flac']
+
+#s.chdir(root_dir)
+
+for root, dirs, files in os.walk(root_dir+web_dir):
+    #print root
+    for file in files:
+        file_split = file.split('.')
+        filename = file_split[len(file_split)-2]
+        #print filename
+        if not os.path.exists(root+os.sep+filename+'.m3u'):
+            fileext = file_split[len(file_split)-1]
+            if fileext in types :
+                os.chdir(root_dir)
+                prefix = 'http://'+host+'/'
+                dest_dir = string.replace(root,'/home/pro-barreau/www/audio/','')
+                file_new = string.replace(file,' ','_')
+                filename_new = string.replace(filename,' ','_')
+                if file_new != file: 
+                    os.system('mv "'+dest_dir+os.sep+file+'" "'+dest_dir+os.sep+file_new+'"')
+                os.system('fapg -f m3u -p '+prefix+' -o "'+root+os.sep+filename_new+'.m3u" "'+dest_dir+os.sep+file_new+'"')
+
diff --git a/various/webthumb_list.py b/various/webthumb_list.py
new file mode 100755 (executable)
index 0000000..3cc63dc
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+# Create thumbs of webpages from a list of URLs
+
+# depends : webthumb, imagemagick
+
+import os
+import sys
+
+img_dir = '/var/www/img/thumbs'
+site_list_file = '/var/www/img/thumbs/url_list.txt'
+
+def main(site_list_file, img_dir):
+    site_list = open(img_dir + os.sep + site_list_file,'r')
+    for site in site_list.readlines():
+        site = site[0:len(site)-1]
+        command = 'webthumb http://'+ site +' | pnmscale -xysize 650 400 | ' + \
+                  'pnmtopng | convert -crop 510x275+5+60 - ' + site +'.png'
+        print command
+        os.system(command)
+    site_list.close()
+    print 'Webthumbs created !'
+
+if __name__ == '__main__':
+    main(site_list_file, img_dir)
\ No newline at end of file
diff --git a/webthumb_list.py b/webthumb_list.py
deleted file mode 100755 (executable)
index 3cc63dc..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/python
-# Create thumbs of webpages from a list of URLs
-
-# depends : webthumb, imagemagick
-
-import os
-import sys
-
-img_dir = '/var/www/img/thumbs'
-site_list_file = '/var/www/img/thumbs/url_list.txt'
-
-def main(site_list_file, img_dir):
-    site_list = open(img_dir + os.sep + site_list_file,'r')
-    for site in site_list.readlines():
-        site = site[0:len(site)-1]
-        command = 'webthumb http://'+ site +' | pnmscale -xysize 650 400 | ' + \
-                  'pnmtopng | convert -crop 510x275+5+60 - ' + site +'.png'
-        print command
-        os.system(command)
-    site_list.close()
-    print 'Webthumbs created !'
-
-if __name__ == '__main__':
-    main(site_list_file, img_dir)
\ No newline at end of file
diff --git a/zope_backup.py b/zope_backup.py
deleted file mode 100755 (executable)
index e4240f7..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/python
-# Backups all zope instances (any versions)
-#
-# Depends : zope_instance.py
-# Copyright (C) 2007-2008 Guillaume Pellerin
-
-import os
-import sys
-from zope_instance import *
-
-version = '0.2'
-info = 'zope_backup v'+version+'\n'+ \
-       """Copyright (C) 2007-2008 Guillaume Pellerin
-       Usage: zope_backup DIRECTORY
-       where DIRECTORY is the directory where you want to backup 
-       the instances of the different versions of zope."""
-
-if len(sys.argv) < 2:
-    sys.exit(info)
-else :
-    backup_dir = sys.argv[1]
-
-z = ZopeInstall()
-instances = z.get_instances()
-instance_main_dir = z.instance_main_dir
-
-def backup_all():
-    for version in instances:
-       for instance in instances[version]:
-            z = ZopeInstance(version, instance)
-           print z.get_instance_dir()
-            z.backup(backup_dir)
-           print version + ': ' + instance + ' backuped !'
-
-if __name__ == '__main__':
-    backup_all()
-    print "Backup_all Zopes done !"
-
-    
-        
diff --git a/zope_instance.py b/zope_instance.py
deleted file mode 100644 (file)
index f45a3e1..0000000
+++ /dev/null
@@ -1,138 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-#
-# Copyright (c) 2007 Guillaume Pellerin <yomguy@parisson.com>
-# All rights reserved.
-#
-# This software is licensed as described in the file COPYING, which
-# you should have received as part of this distribution.
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-# Author: Guillaume Pellerin <yomguy@parisson.com>
-
-
-import os
-import sys
-from optparse import OptionParser
-
-
-class ZopeInstall:
-    """This give the main parameters of the Zope installations respectively to the
-       distribution used"""
-
-    def __init__(self):
-        self.versions = ['2.7', '2.9', '2.8', '2.10']
-       self.instance_main_dir = '/var/lib'
-       self.zope_main_dir = '/usr/lib'
-
-
-    def get_instances(self):
-        """Return all instances in all zope versions installed"""
-        dict = {}
-        for version in self.versions:
-            #print version
-            path = self.instance_main_dir + os.sep + 'zope' + version + os.sep + 'instance'
-            if os.path.exists(path):
-                dict[version] = os.listdir(path)
-                #print dict
-        return dict
-
-
-class ZopeInstance(ZopeInstall):
-    """Expose Zope instances to several python methods that simplifies admins' life
-    (backup, recover, import, etc...)"""
-    
-    def __init__(self, version, instance):
-        ZopeInstall.__init__(self)
-       self.version = version
-        self.instance = instance
-        self.instance_dir = self.instance_main_dir + os.sep + 'zope' + version + os.sep + \
-                        'instance' + os.sep + self.instance
-        self.instance_data = self.instance_dir + os.sep + 'var' + os.sep + 'Data.fs'
-        self.instance_products = self.instance_dir + os.sep + 'Products' + os.sep
-        self.instance_var = self.instance_dir + os.sep + 'var' + os.sep
-        self.instance_etc = self.instance_dir + os.sep + 'etc' + os.sep
-       self.repozo = self.zope_main_dir + os.sep + 'zope' + self.version + os.sep + 'bin' + os.sep + 'repozo.py'
-
-    def get_instance_dir(self):
-        return self.instance_dir
-    
-    def backup(self, backup_dir):
-       """Backup the instance"""
-        self.backup_dir = backup_dir
-       self.instance_backup_dir = self.backup_dir + os.sep + self.version + os.sep + self.instance
-
-        path = self.instance_backup_dir+ os.sep + 'Data'
-        if not os.path.exists(path):
-            os.makedirs(path)
-        if os.path.exists(self.instance_data):
-            command = self.repozo +' -Bvz -r ' + path + ' -f ' + self.instance_data
-            os.system(command)
-            command = 'chmod 700 ' + path + os.sep + '*'
-            os.system(command)
-        else:
-            print self.instance_data + ' does not exists !'
-        if not os.path.exists(self.instance_backup_dir):
-            os.makedirs(self.instance_backup_dir)
-        if os.path.exists(self.instance_products):
-            command = 'tar czf ' + self.instance_backup_dir + os.sep + \
-                      'Products.tar.gz ' + self.instance_products
-            os.system(command)
-        if os.path.exists(self.instance_var):
-            command = 'tar czf ' + self.instance_backup_dir + os.sep + \
-                      'var.tar.gz ' + self.instance_var + ' --exclude=Data.fs'
-            os.system(command)
-        if os.path.exists(self.instance_etc):
-            command = 'tar czf ' + self.instance_backup_dir + os.sep + \
-                      'etc.tar.gz ' + self.instance_etc
-            os.system(command)
-        print self.instance + ' backuped !'
-
-    def recover(self):
-        """Recover the instance from a backup"""
-        os.chdir(self.instance_backup_dir)
-        command = 'tar xzf '+self.instance_backup_dir+os.sep+'Products.tar.gz && ' + \
-                  'rsync -a --delete ' + self.instance_backup_dir+os.sep+self.instance_products + \
-                               ' ' + self.instance_products + os.sep + ' && ' + \
-                  'chown -R zope:zope ' + self.instance_products + ' && ' + \
-                  'rm -rf ' + self.instance_backup_dir+os.sep+'var'
-        os.system(command)
-        command = 'tar xzf '+self.instance_backup_dir+os.sep+'var.tar.gz && ' + \
-                  'rsync -a --delete ' + self.instance_backup_dir + os.sep  + self.instance_var + \
-                                ' ' + self.instance_var + os.sep + ' && ' + \
-                  'chown -R zope:zope ' + self.instance_var + ' && ' + \
-                  'rm -rf ' + self.instance_backup_dir+os.sep+'var'
-        os.system(command)
-        command = self.instance_dir+os.sep+'bin'+os.sep+'zopectl restart'            
-        os.system(command)
-        command = self.repozo + ' -Rvz -r ' + self.instance_backup_dir + os.sep + \
-                    'Data -o ' + self.instance_data
-        if os.path.exists(self.instance_data):
-            os.system(command)
-        else:
-            print self.instance_data + ' does not exists !'
-        print self.instance + ' recovered !'
-        
-    def import_from(self, user, server):
-        command = 'rsync -a --rsh="ssh -l '+user+'" ' + \
-                  user+'@'+server+':'+self.instance_backup_dir+os.sep + ' ' + self.instance_backup_dir+os.sep
-        os.system(command)
-
-    def export_to(self, user, server):
-        command = 'rsync -a --rsh="ssh -l '+user+'" ' + \
-                  self.instance_backup_dir+os.sep  + ' ' + user+'@'+server+':'+self.instance_backup_dir+os.sep
-        os.system(command)
-
-