Ejemplo n.º 1
0
    def __init__(self,
                 server,
                 path,
                 user,
                 pswd,
                 logging,
                 noHostRedirect=False,
                 afunix=None):

        super(Shell, self).__init__("caldav_client")
        self.prefix = self.wd = "/"
        self.server = server
        self.user = user
        self.pswd = pswd

        self.registerCommands()

        # Create the account
        ssl = server.startswith("https://")
        server = server[8:] if ssl else server[7:]
        self.account = CalDAVAccount(server,
                                     ssl=ssl,
                                     afunix=afunix,
                                     user=self.user,
                                     pswd=self.pswd,
                                     root=path,
                                     principal=None,
                                     logging=logging,
                                     noHostRedirect=noHostRedirect)

        atexit.register(self.saveHistory)
Ejemplo n.º 2
0
class Shell(BaseShell):
    def __init__(self,
                 server,
                 path,
                 user,
                 pswd,
                 logging,
                 noHostRedirect=False,
                 afunix=None):

        super(Shell, self).__init__("caldav_client")
        self.prefix = self.wd = "/"
        self.server = server
        self.user = user
        self.pswd = pswd

        self.registerCommands()

        # Create the account
        ssl = server.startswith("https://")
        server = server[8:] if ssl else server[7:]
        self.account = CalDAVAccount(server,
                                     ssl=ssl,
                                     afunix=afunix,
                                     user=self.user,
                                     pswd=self.pswd,
                                     root=path,
                                     principal=None,
                                     logging=logging,
                                     noHostRedirect=noHostRedirect)

        atexit.register(self.saveHistory)

    def registerCommands(self):
        module = caldavclientlibrary.browser.commands
        for item in module.__all__:
            mod = __import__("caldavclientlibrary.browser.commands." + item,
                             globals(), locals(), [
                                 "Cmd",
                             ])
            cmd_class = mod.Cmd
            if type(cmd_class) is type and issubclass(cmd_class, Command):
                self.registerCommand(cmd_class())

    def setWD(self, newwd):

        # Check that the new one exists
        resource = (newwd if newwd.endswith("/") else newwd + "/")
        if not self.account.session.testResource(URL(url=resource)):
            return False
        self.prefix = self.wd = newwd
        return True

    def setUserPswd(self, user, pswd):

        self.user = user
        self.pswd = pswd
        self.account.setUserPswd(user, pswd)
Ejemplo n.º 3
0
 def cd_init (self):
     sf  = self.get_server()
     ssl = sf.startswith('https://')
     server = sf[8:] if ssl else sf[7:]
     account  = CalDAVAccount(server, ssl=ssl, user=self.get_user(),
                              pswd=self.get_pw(), root=self.get_path(),
                              principal=None, logging=False)
     self.set_account(account)
Ejemplo n.º 4
0
    def __init__(self, server, path, user, pswd, logging):

        self.server = server
        self.path = path
        self.user = user
        self.pswd = pswd

        # Create the account
        ssl = server.startswith("https://")
        server = server[8:] if ssl else server[7:]
        paths = "/principals/users/%s/" % (self.user,)
        self.account = CalDAVAccount(server, ssl=ssl, user=self.user, pswd=self.pswd, root=paths, principal=paths, logging=logging)
Ejemplo n.º 5
0
 def cd_init (self):
     sf  = self.get_server()
     ssl = sf.startswith('https://')
     server = sf[8:] if ssl else sf[7:]
     try:
         account  = CalDAVAccount(server, ssl=ssl, user=self.get_user(),
                                  pswd=self.get_pw(), root=self.get_path(),
                                  principal=None,
                                  logging=self.get_client_logging())
     except HTTPError, e:
         server = "Carddav Server (%s)" % sf
         logging.fatal('Could not open connection to %s. Error: %s',
                       server, e)
         raise
         sys.exit(-1)
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##

from caldavclientlibrary.client.account import CalDAVAccount

if __name__ == '__main__':
    account = CalDAVAccount("",
                            ssl=True,
                            user="",
                            pswd="",
                            root="",
                            principal="")

    print account.getPrincipal()

    #    memberships = [CalDAVPrincipal(account.session, path) for path in account.getPrincipal().memberships]
    #    for member in memberships:
    #        member.loadDetails()
    #    memberships = [member.displayname for member in memberships]
    #    print "Memberships: %s" % (memberships,)

    #    calendars = account.getPrincipal().listCalendars()
    #    for calendar in calendars:
    #        print "%s:" % (calendar,)
    #        txt = calendar.getDisplayName()
Ejemplo n.º 7
0
def main():
    # create the args parser
    parser = argparse.ArgumentParser(
        description="Davcontroller creates, lists and removes caldav "
        "calendars and carddav address books from server")
    parser.add_argument("-v",
                        "--version",
                        action="store_true",
                        help="Get current program version")
    parser.add_argument("-H", "--hostname", default="")
    parser.add_argument("-p", "--port", default="")
    parser.add_argument("-u", "--username", default="")
    parser.add_argument("-P", "--password", default="")
    parser.add_argument("action",
                        nargs="?",
                        default="",
                        help="Actions: new-addressbook, new-calendar, list, "
                        "and remove")
    args = parser.parse_args()

    # version
    if args.version is True:
        print("davcontroller version 0.1")
        sys.exit(0)

    # check the server's parameter
    if args.hostname == "":
        print("Missing host name")
        sys.exit(1)
    if args.port == "":
        print("Missing host port")
        sys.exit(1)
    if args.username == "":
        print("Missing user name")
        sys.exit(1)
    if args.password == "":
        print("Missing password")
        sys.exit(1)

    if args.action == "":
        print("Please specify an action. Possible values are: "
              "new-addressbook, new-calendar, list and remove")
        sys.exit(1)
    elif args.action not in [
            "new-addressbook", "new-calendar", "list", "remove"
    ]:
        print("The specified action \"%s\" is not supported. Possible values "
              "are: new-addressbook, new-calendar, list and remove" %
              args.action)
        sys.exit(1)

    # try to connect to the caldav server
    account = CalDAVAccount(args.hostname,
                            args.port,
                            ssl=True,
                            user=args.username,
                            pswd=args.password,
                            root="/",
                            principal="")
    if account.getPrincipal() is None:
        print("Error: Connection refused")
        sys.exit(2)

    if args.action in ["list", "remove"]:
        # address books
        print("Available address books")
        addressbook_list = account.getPrincipal().listAddressBooks()
        if addressbook_list.__len__() == 0:
            print("No address books found")
        else:
            for index, addressbook in enumerate(addressbook_list):
                print("%d. %s" % (index + 1, addressbook.getDisplayName()))
        print()
        # calendars
        print("Available calendars")
        calendar_list = account.getPrincipal().listCalendars()
        if calendar_list.__len__() == 0:
            print("No calendars found")
        else:
            for index, calendar in enumerate(calendar_list):
                print("%d. %s" % (addressbook_list.__len__() + index + 1,
                                  calendar.getDisplayName()))
        item_list = addressbook_list + calendar_list
        if item_list.__len__() == 0:
            sys.exit(2)

        if args.action == "remove":
            print()
            while True:
                input_string = input("Enter Id: ")
                if input_string == "":
                    sys.exit(0)
                try:
                    id = int(input_string)
                    if id > 0 and id <= item_list.__len__():
                        break
                except ValueError:
                    pass
                print(
                    "Please enter an Id between 1 and %d or nothing to exit." %
                    item_list.__len__())
            item = item_list[id - 1]
            while True:
                input_string = input("Deleting %s. Are you sure? (y/n): " %
                                     item.getDisplayName())
                if input_string.lower() in ["", "n", "q"]:
                    print("Canceled")
                    sys.exit(0)
                if input_string.lower() == "y":
                    break
            account.session.deleteResource(URL(url=item.path))

    if args.action.startswith("new-"):
        # get full host url
        host_url = "https://%s:%s" % (account.session.server,
                                      account.session.port)
        # enter new name
        if args.action == "new-addressbook":
            input_string = input("Enter new address book name or nothing to "
                                 "cancel: ")
        else:
            input_string = input("Enter new calendar name or nothing to "
                                 "cancel: ")
        if input_string == "":
            sys.exit(0)
        res_name = input_string
        res_path = input_string.replace(" ", "_").lower()
        # create new resource
        if args.action == "new-addressbook":
            u = URL(url=host_url + account.principal.adbkhomeset[0].path +
                    res_path + "/")
            account.session.makeAddressBook(u, res_name)
        else:
            u = URL(url=host_url + account.principal.homeset[0].path +
                    res_path + "/")
            account.session.makeCalendar(u, res_name)
        print("Creation successful")
Ejemplo n.º 8
0
def main():
    # create the args parser
    parser = argparse.ArgumentParser(description="Davcontroller creates, lists and removes \
            caldav calendars and carddav address books from server")
    parser.add_argument("-v", "--version", action="store_true", help="Get current program version")
    parser.add_argument("-H", "--hostname", default="")
    parser.add_argument("-p", "--port", default="")
    parser.add_argument("-u", "--username", default="")
    parser.add_argument("-P", "--password", default="")
    parser.add_argument("action", nargs="?", default="", help="Actions: new-addressbook, new-calendar, list, and remove")
    args = parser.parse_args()

    # version
    if args.version == True:
        print "davcontroller version 0.1"
        sys.exit(0)

    # check the server's parameter
    if args.hostname == "":
        print "Missing host name"
        sys.exit(1)
    if args.port == "":
        print "Missing host port"
        sys.exit(1)
    if args.username == "":
        print "Missing user name"
        sys.exit(1)
    if args.password == "":
        print "Missing password"
        sys.exit(1)

    if args.action == "":
        print "Please specify an action. Possible values are: new-addressbook, new-calendar, list and remove"
        sys.exit(1)
    elif args.action not in ["new-addressbook", "new-calendar", "list", "remove"]:
        print "The specified action \"%s\" is not supported. Possible values are: \
                new-addressbook, new-calendar, list and remove" % args.action
        sys.exit(1)

    # try to connect to the caldav server
    account = CalDAVAccount(args.hostname, args.port, ssl=True, user=args.username,
            pswd=args.password, root="/", principal="")
    if account.getPrincipal() == None:
        print "Error: Connection refused"
        sys.exit(2)

    if args.action in ["list", "remove"]:
        # address books
        print "Available address books"
        addressbook_list = account.getPrincipal().listAddressBooks()
        if addressbook_list.__len__() == 0:
            print "No address books found"
        else:
            for index, addressbook in enumerate(addressbook_list):
                print "%d. %s" % (index+1, addressbook.getDisplayName())
        print
        # calendars
        print "Available calendars"
        calendar_list = account.getPrincipal().listCalendars()
        if calendar_list.__len__() == 0:
            print "No calendars found"
        else:
            for index, calendar in enumerate(calendar_list):
                print "%d. %s" % (addressbook_list.__len__()+index+1, calendar.getDisplayName())
        item_list = addressbook_list + calendar_list
        if item_list.__len__() == 0:
            sys.exit(2)

        if args.action == "remove":
            print
            while True:
                input_string = raw_input("Enter Id: ")
                if input_string == "":
                    sys.exit(0)
                try:
                    id = int(input_string)
                    if id > 0 and id <= item_list.__len__():
                        break
                except ValueError as e:
                    pass
                print "Please enter an Id between 1 and %d or nothing to exit." % item_list.__len__()
            item = item_list[id-1]
            while True:
                input_string = raw_input("Deleting %s. Are you sure? (y/n): " \
                        % item.getDisplayName())
                if input_string.lower() in ["", "n", "q"]:
                    print "Canceled"
                    sys.exit(0)
                if input_string.lower() == "y":
                    break
            account.session.deleteResource(URL(url=item.path))

    if args.action.startswith("new-"):
        # get full host url
        host_url = "https://%s:%s" % (account.session.server, account.session.port)
        # enter new name
        if args.action == "new-addressbook":
            input_string = raw_input("Enter new address book name or nothing to cancel: ")
        else:
            input_string = raw_input("Enter new calendar name or nothing to cancel: ")
        if input_string == "":
            sys.exit(0)
        res_name = input_string
        res_path = input_string.replace(" ","_").lower()
        # create new resource
        if args.action == "new-addressbook":
            u = URL(url=host_url + account.principal.adbkhomeset[0].path + res_path + "/")
            account.session.makeAddressBook(u, res_name)
        else:
            u = URL(url=host_url + account.principal.homeset[0].path + res_path + "/")
            account.session.makeCalendar(u, res_name)
        print "Creation successful"
Ejemplo n.º 9
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##

from caldavclientlibrary.client.account import CalDAVAccount

if __name__ == '__main__':
    account = CalDAVAccount("", ssl=True, user="", pswd="", root="", principal="")

    print account.getPrincipal()

#    memberships = [CalDAVPrincipal(account.session, path) for path in account.getPrincipal().memberships]
#    for member in memberships:
#        member.loadDetails()
#    memberships = [member.displayname for member in memberships]
#    print "Memberships: %s" % (memberships,)

#    calendars = account.getPrincipal().listCalendars()
#    for calendar in calendars:
#        print "%s:" % (calendar,)
#        txt = calendar.getDisplayName()
#        if txt:
#            print "  Display Name: %s" % (txt,)