Exemple #1
0
    def mkdir(self, name, parent=None, by_name=False, share=0):
        """Create a directory if it does not exists and return its id
        """
        self._check()

        if not parent:
            parent = self.ROOT_ID
        elif by_name:
            parent = self._convert_to_id(parent, False)
        params = urllib.urlencode(
            {
                "action": "create_folder",
                "api_key": self._api_key,
                "auth_token": self._auth_token,
                "parent_id": encode(parent),
                "name": encode(name),
                "share": share,
            }
        )
        logger.debug("mkdir params: {}".format(params))
        response = urllib.urlopen(self.REST_URL, params)

        tree = self._parse_response(response)
        folder = map_element(tree.find("folder"))
        self._log_response(folder)
        return folder
Exemple #2
0
    def get_account_info(self):
        """Get account information"""
        self._check()

        params = urllib.urlencode(
            {"action": "get_account_info", "api_key": self._api_key, "auth_token": self._auth_token}
        )
        logger.debug("get_account_info params: {}".format(params))
        response = urllib.urlopen(self.REST_URL, params)
        tree = self._parse_response(response)
        info = map_element(tree.find("user"))
        self._log_response(info)
        return info
Exemple #3
0
    def get_account_info(self):
        """Get account information"""
        self._check()

        params = urllib.urlencode({
                   'action': "get_account_info",
                   'api_key': self._api_key,
                   'auth_token': self._auth_token})
        logger.debug("get_account_info params: {}".format(params))
        response = urllib.urlopen(self.REST_URL, params)
        tree = self._parse_response(response)
        info = map_element(tree.find('user'))
        self._log_response(info)
        return info
Exemple #4
0
    def get_file_info(self, file_id, by_name=False):
        """Get file detailed information"""
        self._check()

        if by_name:
            file_id = self._convert_to_id(file_id, True)
        params = urllib.urlencode({
                   'action': "get_file_info",
                   'api_key': self._api_key,
                   'auth_token': self._auth_token,
                   'file_id': encode(file_id)})
        logger.debug("get_file_info params: {}".format(params))
        response = urllib.urlopen(self.REST_URL, params)
        tree = self._parse_response(response)
        info = map_element(tree.find('info'))
        self._log_response(info)
        return info
Exemple #5
0
    def get_file_info(self, file_id, by_name=False):
        """Get file detailed information"""
        self._check()

        if by_name:
            file_id = self._convert_to_id(file_id, True)
        params = urllib.urlencode({
                   'action': "get_file_info",
                   'api_key': self._api_key,
                   'auth_token': self._auth_token,
                   'file_id': encode(file_id)})
        logger.debug("get_file_info params: {}".format(params))
        response = urllib.urlopen(self.REST_URL, params)
        tree = self._parse_response(response)
        info = map_element(tree.find('info'))
        self._log_response(info)
        return info
Exemple #6
0
    def mkdir(self, name, parent=None, by_name=False, share=0):
        """Create a directory if it does not exists and return its id
        """
        self._check()

        if not parent:
            parent = self.ROOT_ID
        elif by_name:
            parent = self._convert_to_id(parent, False)
        params = urllib.urlencode({
                   'action': "create_folder",
                   'api_key': self._api_key,
                   'auth_token': self._auth_token,
                   'parent_id': encode(parent),
                   'name': encode(name),
                   'share': share})
        logger.debug("mkdir params: {}".format(params))
        response = urllib.urlopen(self.REST_URL, params)

        tree = self._parse_response(response)
        folder = map_element(tree.find('folder'))
        self._log_response(folder)
        return folder