コード例 #1
0
    def create_calendar(self, displayname, cal_id):
        """
        Create a new calendar on this server.
        name: Displayname of calendar
        cal_id: unique ID
        """
        if displayname in self.calendars:
            raise Exception("CalDAVserver.create_calendar: Calendar name {} already exists in url {}.".format(name, self.url))

        # check if cal_id exists
        cal_id = sanity_check.trailing_slash(cal_id)
        calendars = self.principal.calendars()        
        props = [c.get_properties([caldav.elements.dav.Href()]) for c in calendars]
        cal_ids = [p['{DAV:}href'] for p in props]
        if any([i.endswith(cal_id) for i in cal_ids]):
            raise Exception("CalDAVserver.create_calendar: ID {} already exists in url {}.".format(cal_id, self.url))
        
        try:
            new_calendar = self.principal.make_calendar(name=displayname, cal_id=cal_id)
            logging.info("Created new calendar {}, {}".format(displayname, cal_id))
            self.calendars[displayname] = new_calendar
            logging.debug('CalDAVserver.create_calendar: current calendars: {}'.format(self.calendars))
            logging.info("Added new calendar {} with ID {} to url {}.".format(displayname, cal_id, self.url))
        except Exception as e:
            logging.debug(e)
コード例 #2
0
ファイル: caldavserver.py プロジェクト: dino-r/shirleytoolate
 def delete_calendar(self, cal_id):
     """
     Delete calendar with ID cal_id.
     """
     cal_id = sanity_check.trailing_slash(cal_id)
     try:
         for c in self.calendars:
             if c.get_properties([caldav.elements.dav.Href()])['{DAV:}href'].endswith(cal_id):
                 c.delete()
                 logging.info("Deleted calendar with ID {} from url {}".format(cal_id, self.url))
                 return
         raise Exception("CalDAVserver.delete_calendar: Calendar with ID {} does not exist in url.".format(cal_id, self.url))
     except Exception as e:
         logging.debug(e)
コード例 #3
0
ファイル: main.py プロジェクト: trobanga/shirleytoolate
def get_urls(url_conf="url.conf"):
    """
    Return dictionary with url_nick & url listed in url_conf
    """
    u = {}
    with open(url_conf, "r") as f:
        lines = f.readlines()
        for i, l in enumerate(lines):
            if l.strip()[0] != "#":
                l = l.split(" ")
                if len(l) != 2:
                    continue
                l[1] = sanity_check.trailing_slash(l[1].rstrip())
                u[l[0]] = l[1]
    return u
コード例 #4
0
def get_urls(url_conf="url.conf"):
    """
    Return dictionary with url_nick & url listed in url_conf
    """
    u = {}
    with open(url_conf, 'r') as f:
        lines = f.readlines()
        for i, l in enumerate(lines):
            if l.strip()[0] != '#':
                l = l.split(' ')
                if len(l) != 2:
                    continue
                l[1] = sanity_check.trailing_slash(l[1].rstrip())
                u[l[0]] = l[1]
    return u
コード例 #5
0
ファイル: caldavserver.py プロジェクト: dino-r/shirleytoolate
 def create_calendar(self, name, cal_id):
     """
     Create a new calendar on this server.
     name: Displayname of calendar
     cal_id: unique ID
     """
     cal_id = sanity_check.trailing_slash(cal_id)
     if any([i.endswith(cal_id) for i in self.calendar_IDs]):
         raise Exception("CalDAVserver.create_calendar: ID {} already exists in url {}.".format(cal_id, self.url))
     if name in self.calendar_DisplayNames:
         raise Exception("CalDAVserver.create_calendar: Calendar name {} already exists in url {}.".format(name, self.url))
     try:
         self.principal.make_calendar(name=name, cal_id=cal_id)
         logging.info("Created new calendar {}, {}".format(name, cal_id))
         self.calendars = self.principal.calendars()
         logging.debug('CalDAVserver.create_calendar: calendars: {}'.format(self.calendars))
         self.calendar_IDs.append(cal_id)
         logging.info("Added new calendar with ID {} to url {}.".format(cal_id, self.url))
     except Exception as e:
         logging.debug(e)
コード例 #6
0
ファイル: main.py プロジェクト: dino-r/shirleytoolate
                               metavar=('URL_nick', 'calendar_name', 'cal_id'),
                               help="add a new calendar ")
    parser_add.set_defaults(func=add)

    parser_del = subparser.add_parser("del", help="Delete calendars, etc.")
    parser_del.add_argument("--calendar", nargs=2,
                            metavar=("URL nick, cal_id"),
                            help="Delete calendar from URL.")
    parser_del.set_defaults(func=delete)
    
    args = parser.parse_args()


    if args.debug:
        logging.basicConfig(filename='shirleys.log',level=logging.DEBUG)
    else:
        logging.basicConfig(filename='shirleys.log',level=logging.INFO)


    config.url = {k: sanity_check.trailing_slash(v) for k,v in config.url.items()}

    
    for k, v in config.url.items():
        servers[k] = caldavserver.CalDAVserver(k, v)
        for k,v in servers.items():
            for c in v.calendars:
                calendars.append(c)

    if args:       
        args.func(args)