Пример #1
0
def _showCalendar(userCalendar, j, jcount):
    current_count = display.current_count(j, jcount)
    summary = userCalendar.get('summaryOverride', userCalendar['summary'])
    print(f'  Calendar: {userCalendar["id"]}{current_count}')
    print(f'    Summary: {summary}')
    print(f'    Description: {userCalendar.get("description", "")}')
    print(f'    Access Level: {userCalendar["accessRole"]}')
    print(f'    Timezone: {userCalendar["timeZone"]}')
    print(f'    Location: {userCalendar.get("location", "")}')
    print(f'    Hidden: {userCalendar.get("hidden", "False")}')
    print(f'    Selected: {userCalendar.get("selected", "False")}')
    print(f'    Color ID: {userCalendar["colorId"]}, ' \
          f'Background Color: {userCalendar["backgroundColor"]}, ' \
          f'Foreground Color: {userCalendar["foregroundColor"]}')
    print(f'    Default Reminders:')
    for reminder in userCalendar.get('defaultReminders', []):
        print(f'      Method: {reminder["method"]}, ' \
              f'Minutes: {reminder["minutes"]}')
    print('    Notifications:')
    if 'notificationSettings' in userCalendar:
        notifications = userCalendar['notificationSettings'].get(
            'notifications', [])
        for notification in notifications:
            print(f'      Method: {notification["method"]}, ' \
                  f'Type: {notification["type"]}')
Пример #2
0
def addCalendar(users):
    calendarId = normalizeCalendarId(sys.argv[5])
    body = {'id': calendarId, 'selected': True, 'hidden': False}
    colorRgbFormat = getCalendarAttributes(6, body, 'add')
    i = 0
    count = len(users)
    for user in users:
        i += 1
        user, cal = buildCalendarGAPIObject(user)
        if not cal:
            continue
        current_count = display.current_count(i, count)
        print(f'Subscribing {user} to calendar {calendarId}{current_count}')
        gapi.call(cal.calendarList(),
                  'insert',
                  soft_errors=True,
                  body=body,
                  colorRgbFormat=colorRgbFormat)
Пример #3
0
def showCalSettings(users):
    i = 0
    count = len(users)
    for user in users:
        i += 1
        user, cal = buildCalendarGAPIObject(user)
        if not cal:
            continue
        feed = gapi.get_all_pages(cal.settings(),
                                  'list',
                                  'items',
                                  soft_errors=True)
        if feed:
            current_count = display.current_count(i, count)
            print(f'User: {user}, Calendar Settings:{current_count}')
            settings = {}
            for setting in feed:
                settings[setting['id']] = setting['value']
            for attr, value in sorted(settings.items()):
                print(f'  {attr}: {value}')
Пример #4
0
def printShowACLs(csvFormat):
    calendarId, cal = buildCalendarDataGAPIObject(sys.argv[2])
    if not cal:
        return
    toDrive = False
    i = 4
    while i < len(sys.argv):
        myarg = sys.argv[i].lower().replace('_', '')
        if csvFormat and myarg == 'todrive':
            toDrive = True
            i += 1
        else:
            action = ['showacl', 'printacl'][csvFormat]
            message = f'gam calendar <email> {action}'
            controlflow.invalid_argument_exit(sys.argv[i], message)
    acls = gapi.get_all_pages(cal.acl(),
                              'list',
                              'items',
                              calendarId=calendarId)
    i = 0
    if csvFormat:
        titles = []
        rows = []
    else:
        count = len(acls)
    for rule in acls:
        i += 1
        if csvFormat:
            row = utils.flatten_json(rule, None)
            for key in row:
                if key not in titles:
                    titles.append(key)
            rows.append(row)
        else:
            formatted_acl = formatACLRule(rule)
            current_count = display.current_count(i, count)
            print(
                f'Calendar: {calendarId}, ACL: {formatted_acl}{current_count}')
    if csvFormat:
        display.write_csv_file(rows, titles, f'{calendarId} Calendar ACLs',
                               toDrive)
Пример #5
0
def updateCalendar(users):
    calendarId = normalizeCalendarId(sys.argv[5], checkPrimary=True)
    body = {}
    colorRgbFormat = getCalendarAttributes(6, body, 'update')
    i = 0
    count = len(users)
    for user in users:
        i += 1
        user, cal = buildCalendarGAPIObject(user)
        if not cal:
            continue
        current_count = display.current_count(i, count)
        print(f"Updating {user}'s subscription to calendar ' \
              f'{calendarId}{current_count}")
        calId = calendarId if calendarId != 'primary' else user
        gapi.call(cal.calendarList(),
                  'patch',
                  soft_errors=True,
                  calendarId=calId,
                  body=body,
                  colorRgbFormat=colorRgbFormat)