Migration de dotProject à OwnCloud : Différence entre versions

De April MediaWiki
(Ajout des liens)
(Installation d'OwnCloud)
Ligne 2 : Ligne 2 :
[http://owncloud.org Owncloud]
[http://owncloud.org Owncloud]
Installé depuis le paquet Debian : [http://packages.debian.org/wheezy/owncloud paquet], [http://tracker.debian.org/owncloud tracker debian]
Installé depuis le paquet Debian : [http://packages.debian.org/wheezy-backports/owncloud paquet], [http://tracker.debian.org/owncloud tracker debian]
== Migration des contact de dotProjet vers vCard pour import dans OwnCloud ==
== Migration des contact de dotProjet vers vCard pour import dans OwnCloud ==

Version actuelle en date du 17 juillet 2014 à 11:32

Installation d'OwnCloud[modifier]


Installé depuis le paquet Debian : paquet, tracker debian

Migration des contact de dotProjet vers vCard pour import dans OwnCloud[modifier]

Nous avons utilisé un script python :

import csv
import vobject
import re

def are_null (row, args):
  for arg in args:
    if arg not in row:
      return True
    if row[arg] != "":
      return False
  return True

def add_name (v, row):
  v.add ('n')
  v.n.value = vobject.vcard.Name(
      family      = row["First Name"],
      given       = row["Last Name"],
      additional  = row["Middle Name"],
      prefix      = row["Title"],
      suffix      = row["Suffix"],

def add_notes (v, row):
  if are_null (row, ["Notes"]):
  v.add ('note')
  v.note.value = row["Notes"]

def add_anniversary (v, row):
  if are_null (row, ["Birthday"]):
  v.add ('bday')
  v.bday.value = row["Birthday"]

def add_title (v, row):
  v.add ('fn')
  v.fn.value = "%s %s" % (row["First Name"], row["Last Name"])

def add_organization (v, row):
  if are_null (row, ["Company", "Department", "Job Title"]):
  v.add ('org')
  v.org.value = [row["Company"], row["Department"], row ["Job Title"]]

def add_address (v, row, pre, typ):
  if are_null (row, [pre+" Street", pre+" City"]):
  v.add ('adr')
  v.adr.type_param = typ
  v.adr.value = vobject.vcard.Address(
      street =  row[pre+" Street"]   + "\n " +
                row[pre+" Street 2"] + "\n " +
                row[pre+" Street 3"],
      city =    row[pre+" City"],
      region =  row[pre+" State"],
      code =    row[pre+" Postal Code"],
      country = row[pre+" Country"],

def add_telephone (v, row, pre, typ):
  if are_null (row, [pre+" Phone"]):
  v.tel.type_param = typ
  v.tel.value = row[pre+" Phone"]

def add_fax (v, row, pre, typ):
  if are_null (row, [pre+" Fax"]):
  v.fax.type_param = typ
  v.fax.value = row[pre+" Fax"]

def unfuck_emails (s):
  t= re.split ("[<>]", s)
  for field in t:
    if field.find ('@') > -1:
      return field.strip()
  # should raise ValueError("Badly splitted: " + s)
  return s

def add_email (v, row, suf):
    dn=  "E-mail" + suf + " Display Name"
    ema= "E-mail" + suf + " Address"
    emt= "E-mail" + suf + " Type"
    if row[ema] != "":
      v.email.value = "%s <%s>" % (row[dn], unfuck_emails (row[ema]))
      if row[emt] != "SMTP":
        v.email.type_param = row[emt]

with open('APRILContacts-unix-utf8.csv', 'rb') as csvfile:
  reader = csv.DictReader(csvfile, delimiter=',', quotechar='"')
  for row in reader:
    for key in row:
      if type (row[key]) is str:
        row[key]= row[key].decode('utf8')

    v= vobject.vCard()
    add_title (v, row)
    add_name  (v, row)
    add_notes (v, row)
    add_anniversary  (v, row)
    add_organization (v, row)

    for (i,o) in [("Business", "WORK"), ("Home", "HOME"), ("Other", "OTHER")]:
      add_address (v, row, i, o)
      add_telephone (v, row, i, o)
      add_telephone (v, row, i+" 2", o+" 2")
      add_fax (v, row, i, o)

    for (i,o) in [("Mobile", "CELL")]:
      add_telephone (v, row, i, o)

    for suf in ["", " 2", " 3"]:
      add_email (v, row, suf)

    print v.serialize()

Pour l'utiliser:

  • exporter les contacts depuis dotProjet en CSV dans un fichier APRILContacts.csv ;
  • l'ouvrir avec Gedit (ou $editor) et le sauvegarder dans APRILContacts-unix-utf8.csv, en prenant soin de le coder en unicode, au format unix.
  • lancer le script : python dotp2vcard.py > contacts.vcard

Migration des événements[modifier]

J'ai mis en ligne les travail de migration des événements : De la conversion d'une liste d'événement de dotprojet

Exporter en CSV :

select event_title, event_start_date, event_end_date, event_description from events
  into outfile event.csv
  fields terminated by ','
  enclosed by '"'
  escaped by '\\'
  lines terminated by '\n' ;

Le code Python :

import csv
from icalendar import Calendar, Event, LocalTimezone
from datetime import datetime, timedelta
from random import randint
import sys
#from __future__ import print_function
reader_builder = list(csv.DictReader(open('events_utf8.csv', 'Ub'), skipinitialspace = True))
headers = reader_builder[0].keys()
# Start calendar file
cal = Calendar()
cal.add('prodid', 'dotproject.april.org')
cal.add('version', '2.0')
reader = reader_builder
rownum = 0
    for row in reader:
        event = Event()
        event.add('summary', row['event_title'])
        event.add('dtstart', datetime.strptime(row['event_start_date'],'%Y-%m-%d %H:%M:%S'))
        event.add('dtend', datetime.strptime(row['event_end_date'],'%Y-%m-%d %H:%M:%S'))
        event['uid'] = str(randint(1,10**30)) + datetime.now().strftime('%Y%m%dT%H%M%S') + '___dotproject.april.org'
        rownum += 1
except Exception, e:
    if rownum > 0:
        print('I had a problem with an event. I think I might have gotten through about {0} events and had trouble with an event with subject: {1} . Sorry!'.format(rownum, row['event_title']))
        print("N'arrivera pas")
f = open('./dotp_events.ics','wb')

Il faut arrondir les angles à différents moments :

sed -i.bak 's/\\"/«/g' events.csv
iconv -f latin1 -t utf-8 events.csv > events_utf8.csv
python script.py
sed -i.bak s/;VALUE=DATE-TIME// dotp_events.ics