Exemple #1
0
def main (argv=None):
    print 'Command line: ', sys.argv
    print confn_src

    if os.path.exists(user_dir):
        logging.debug('Clearing user directory: %s', user_dir)
        shutil.rmtree(user_dir)
    else:
        logging.debug('Creating user directory: %s', user_dir)

    os.makedirs(user_dir)

    shutil.copyfile(state_src, state_dest)
    shutil.copyfile(confn_src, confn_dest)

    global config
    config = Config(asynk_base_dir=asynk_base_dir, user_dir=user_dir)

    data = None
    with open(sys.argv[1], "r") as f:
        data = f.read()
        
    print
    print data
    vco = vobject.readOne(data)
    print vco
    print vco.prettyPrint()
    con = CDContact(None, vco=vobject.readOne(data), debug_vcf=True)
    print unicode(con)

    print "Display Name: ", con.get_disp_name()
    print "VCO: ", con.init_vco_from_props().serialize()
Exemple #2
0
def main(argv=None):
    print 'Command line: ', sys.argv
    print confn_src

    if os.path.exists(user_dir):
        logging.debug('Clearing user directory: %s', user_dir)
        shutil.rmtree(user_dir)
    else:
        logging.debug('Creating user directory: %s', user_dir)

    os.makedirs(user_dir)

    shutil.copyfile(state_src, state_dest)
    shutil.copyfile(confn_src, confn_dest)

    global config
    config = Config(asynk_base_dir=asynk_base_dir, user_dir=user_dir)

    data = None
    with open(sys.argv[1], "r") as f:
        data = f.read()

    print
    print data
    vco = vobject.readOne(data)
    print vco
    print vco.prettyPrint()
    con = CDContact(None, vco=vobject.readOne(data), debug_vcf=True)
    print unicode(con)

    print "Display Name: ", con.get_disp_name()
    print "VCO: ", con.init_vco_from_props().serialize()
Exemple #3
0
    def find_item(self, itemid):
        """See the documentation in folder.Folder"""

        sess = self.get_db().session()
        result = sess.readData(URL(path=self.item_path(itemid)))
        if not result:
            return None

        data, _ignore_etag = result

        try:
            itemid = CDContact.normalize_cdid(itemid)
            return CDContact(self, vco=vobject.readOne(data), itemid=itemid)
        except Exception, e:
            logging.error('Error (%s) parsing vCard object for %s', e, itemid)
            raise
Exemple #4
0
    def batch_create(self, src_sl, src_dbid, items):
        """See the documentation in folder.Folder"""

        my_dbid = self.get_dbid()
        c = self.get_config()
        pname = src_sl.get_pname()

        src_sync_tag = c.make_sync_label(src_sl.get_pname(), src_dbid)
        dst_sync_tag = c.make_sync_label(src_sl.get_pname(), my_dbid)

        success = True
        for item in items:

            ## CardDAV does not support a multiput operation. So we will have
            ## to PUT the damn items one at a time. What kind of a standard is
            ## this, anyway?

            con_itemid = item.get_itemid_from_synctags(pname, 'cd')
            cd = CDContact(self, con=item, con_itemid=con_itemid)
            cd.update_sync_tags(src_sync_tag, item.get_itemid(), save=True)
            self.add_contact(cd)

            item.update_sync_tags(dst_sync_tag, cd.get_itemid())

            logging.info('Successfully created CardDAV entry for %30s (%s)',
                         cd.get_disp_name(), cd.get_itemid())

        return True
Exemple #5
0
    def find_items (self, itemids):
        """See the documentation in folder.Folder"""

        sess = self.get_db().session()
        results = sess.multiGet(URL(path=self.get_itemid()), itemids,
                                (davxml.getetag, carddavxml.address_data))

        ret = []
        for key, item in results.iteritems():
            etag = item.getNodeProperties()[davxml.getetag]
            vcf  = item.getNodeProperties()[carddavxml.address_data]

            vco = vobject.readOne(vcf.text)
            cd = CDContact(self, vco=vco, itemid=key)
            cd.set_etag(etag.text)
            ret.append(cd)

        return ret
Exemple #6
0
    def find_items(self, itemids):
        """See the documentation in folder.Folder"""

        sess = self.get_db().session()
        results = sess.multiGet(URL(path=self.get_itemid()), itemids,
                                (davxml.getetag, carddavxml.address_data))

        ret = []
        for key, item in results.iteritems():
            etag = item.getNodeProperties()[davxml.getetag]
            vcf = item.getNodeProperties()[carddavxml.address_data]

            vco = vobject.readOne(vcf.text)
            cd = CDContact(self, vco=vco, itemid=key)
            cd.set_etag(etag.text)
            ret.append(cd)

        return ret
Exemple #7
0
    def find_items(self, itemids):
        """See the documentation in folder.Folder"""

        sess = self.get_db().session()
        results = sess.multiGet(URL(path=self.get_itemid()), itemids,
                                (davxml.getetag, carddavxml.address_data))

        ret = []
        for key, item in results.iteritems():
            etag = item.getNodeProperties()[davxml.getetag]
            vcf = item.getNodeProperties()[carddavxml.address_data]

            try:
                cd = CDContact(self, vco=vobject.readOne(vcf.text), itemid=key)
            except Exception, e:
                logging.error('Error (%s) parsing vCard object for %s', e, key)
                raise

            cd.set_etag(etag.text)
            ret.append(cd)
Exemple #8
0
    def find_items (self, itemids):
        """See the documentation in folder.Folder"""

        sess = self.get_db().session()
        results = sess.multiGet(URL(path=self.get_itemid()), itemids,
                                (davxml.getetag, carddavxml.address_data))

        ret = []
        for key, item in results.iteritems():
            etag = item.getNodeProperties()[davxml.getetag]
            vcf  = item.getNodeProperties()[carddavxml.address_data]

            try:
                cd = CDContact(self, vco=vobject.readOne(vcf.text), itemid=key)
            except Exception, e:
                logging.error('Error (%s) parsing vCard object for %s',
                              e, key)
                raise

            cd.set_etag(etag.text)
            ret.append(cd)
Exemple #9
0
    def find_item(self, itemid):
        """See the documentation in folder.Folder"""

        sess = self.get_db().session()
        result = sess.readData(URL(path=itemid))
        if not result:
            return None

        data, _ignore_etag = result
        cd = CDContact(self, vco=vobject.readOne(data), itemid=itemid)

        return cd
Exemple #10
0
    def batch_create (self, src_sl, src_dbid, items):
        """See the documentation in folder.Folder"""

        my_dbid = self.get_dbid()
        c       = self.get_config()
        src_sync_tag = c.make_sync_label(src_sl.get_pname(), src_dbid)
        dst_sync_tag = c.make_sync_label(src_sl.get_pname(), my_dbid)

        success = True
        for item in items:

            ## CardDAV does not support a multiput operation. So we will have
            ## to PUT the damn items one at a time. What kind of a standard is
            ## this, anyway?

            cd = CDContact(self, con=item)
            cd.update_sync_tags(src_sync_tag, item.get_itemid(), save=True)
            self.add_contact(cd)            

            item.update_sync_tags(dst_sync_tag, cd.get_itemid())

            logging.info('Successfully created CardDAV entry for %30s (%s)',
                         cd.get_disp_name(), cd.get_itemid())

        return True
Exemple #11
0
    def batch_update (self, src_sl, src_dbid, items):
        """See the documentation in folder.Folder"""

        my_dbid = self.get_dbid()
        c       = self.get_config()
        pname   = src_sl.get_pname()

        src_sync_tag = c.make_sync_label(pname, src_dbid)
        dst_sync_tag = c.make_sync_label(pname, my_dbid)

        cons = self.get_contacts()

        ## FIXME: We will try to overwrite using the etags we had fetched just
        ## a fe moments back. It could still fail; and the error handling
        ## needs to be robust ... but it is not

        success = True

        for item in items:
            tag, href = item.get_sync_tags(dst_sync_tag)[0]
            ## FIXME: Some times we might find it expedient to force a
            ## "update" without the contact being present int he remote. If
            ## that happens the next line will throw an KeyError. You are
            ## warned. 
            con_old = cons[href]
            con_itemid = item.get_itemid_from_synctags(pname, 'cd')
            con_new = CDContact(self, con=item, con_itemid=con_itemid)

            con_new.set_uid(con_old.get_uid())
            con_new.update_sync_tags(src_sync_tag, item.get_itemid())

            try:
                con_new.save(etag=con_old.get_etag())
                logging.info('Successfully updated CardDAV entry for %30s (%s)',
                             con_new.get_disp_name(), con_new.get_itemid())
            except HTTPError, e:
                logging.error('Error (%s). Could not update CardDAV entry %s',
                              e, con_new.get_disp_name())
                success = False
Exemple #12
0
    def find_item (self, itemid):
        """See the documentation in folder.Folder"""

        sess = self.get_db().session()
        result = sess.readData(URL(path=self.item_path(itemid)))
        if not result:
            return None

        data, _ignore_etag = result

        try:
            itemid = CDContact.normalize_cdid(itemid)
            return CDContact(self, vco=vobject.readOne(data), itemid=itemid)
        except Exception, e:
            logging.error('Error (%s) parsing vCard object for %s',
                          e, itemid)
            raise
Exemple #13
0
def create_contact (cd):
    c = CDContact(cd.get_def_folder())
    c.set_firstname('Chalini')
    c.set_lastname('Tarantula')
    c.set_prefix('Dr.')
    c.set_suffix('Jr.')
    c.set_gender('Female')
    c.add_email_home('*****@*****.**')

    c.save()
    print c
Exemple #14
0
    def batch_update(self, src_sl, src_dbid, items):
        """See the documentation in folder.Folder"""

        my_dbid = self.get_dbid()
        c = self.get_config()
        pname = src_sl.get_pname()

        src_sync_tag = c.make_sync_label(pname, src_dbid)
        dst_sync_tag = c.make_sync_label(pname, my_dbid)

        cons = self.get_contacts()

        ## FIXME: We will try to overwrite using the etags we had fetched just
        ## a fe moments back. It could still fail; and the error handling
        ## needs to be robust ... but it is not

        success = True

        for item in items:
            tag, href = item.get_sync_tags(dst_sync_tag)[0]
            ## FIXME: Some times we might find it expedient to force a
            ## "update" without the contact being present int he remote. If
            ## that happens the next line will throw an KeyError. You are
            ## warned.
            con_old = cons[href]
            con_itemid = item.get_itemid_from_synctags(pname, 'cd')
            con_new = CDContact(self, con=item, con_itemid=con_itemid)

            con_new.set_uid(con_old.get_uid())
            con_new.update_sync_tags(src_sync_tag, item.get_itemid())

            try:
                con_new.save(etag=con_old.get_etag())
                logging.info(
                    'Successfully updated CardDAV entry for %30s (%s)',
                    con_new.get_disp_name(), con_new.get_itemid())
            except HTTPError, e:
                logging.error('Error (%s). Could not update CardDAV entry %s',
                              e, con_new.get_disp_name())
                success = False
Exemple #15
0
def create_contact (cd):
    c = CDContact(cd.get_def_folder())
    c.set_firstname('Nalini')
    c.set_lastname('Bharatula')
    c.set_prefix('Dr.')
    c.set_suffix('Jr.')
    c.set_gender('Female')
    c.add_email_home('*****@*****.**')

    c.save()
    print c
Exemple #16
0
def create_contact(cd):
    c = CDContact(cd.get_def_folder())
    c.set_firstname('Chalini')
    c.set_lastname('Tarantula')
    c.set_prefix('Dr.')
    c.set_suffix('Jr.')
    c.set_gender('Female')
    c.add_email_home('*****@*****.**')

    c.save()
    print c