Merge pull request #34 from gissehel/rename

Renaming file and folders
This commit is contained in:
Richard O'Dwyer 2013-05-04 17:38:33 -07:00
commit f7a43edb16
2 changed files with 25 additions and 0 deletions

View file

@ -7,6 +7,7 @@ Python library for the Mega.co.nz API, currently supporting:
- deleting - deleting
- searching - searching
- sharing - sharing
- renaming
This is a work in progress, further functionality coming shortly. This is a work in progress, further functionality coming shortly.
@ -68,6 +69,11 @@ m.download(file, '/home/john-smith/Desktop')
```python ```python
m.create_folder('new_folder') m.create_folder('new_folder')
``` ```
### Rename a file or a folder
```python
file = m.find('myfile.doc')
m.rename(file, 'my_file.doc')
```
### Search account for a file, and get its public link ### Search account for a file, and get its public link
```python ```python
file = m.find('myfile.doc') file = m.find('myfile.doc')

View file

@ -584,3 +584,22 @@ class Mega(object):
'i': self.request_id}) 'i': self.request_id})
#return API msg #return API msg
return data return data
def rename(self, file, new_name):
file = file[1]
#create new attribs
attribs = {'n': new_name}
#encrypt attribs
encrypt_attribs = base64_url_encode(encrypt_attr(attribs, file['k']))
encrypted_key = a32_to_base64(encrypt_key(file['key'], self.master_key))
#update attributes
data = self.api_request([{
'a': 'a',
'attr': encrypt_attribs,
'key': encrypted_key,
'n': file['h'],
'i': self.request_id}])
#return API msg
return data