added setup.py, restructured files to be a python package. fixed issue #4. updated readme
This commit is contained in:
parent
8d2dbb597b
commit
17b4d0363a
9 changed files with 75 additions and 13 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -4,4 +4,7 @@
|
|||
|
||||
# Hidden files #
|
||||
###################
|
||||
.*
|
||||
.*
|
||||
# Build files #
|
||||
###################
|
||||
build/
|
|
@ -1,4 +1,4 @@
|
|||
cyberjujum
|
||||
richardasaurus
|
||||
jlejeune
|
||||
issues: zbahoui,alyssarowan
|
||||
issues: zbahoui,alyssarowan,kionez
|
||||
|
|
13
README.md
13
README.md
|
@ -12,6 +12,17 @@ This is a work in progress, further functionality coming shortly.
|
|||
|
||||
## How To Use
|
||||
|
||||
### Install mega.py package
|
||||
|
||||
- Download the source code
|
||||
- Open the terminal in the source folder
|
||||
- Run the following command
|
||||
sudo python setup.py install
|
||||
|
||||
### Import mega.py
|
||||
|
||||
from mega import Mega
|
||||
|
||||
### Create an instance of Mega.py
|
||||
|
||||
mega = Mega()
|
||||
|
@ -60,7 +71,7 @@ This is a work in progress, further functionality coming shortly.
|
|||
|
||||
## Tests
|
||||
|
||||
Test .py files can be found in /tests, run these to ensure Mega.py is working 100%.
|
||||
Test .py files can be found in tests.py, run these to ensure Mega.py is working 100%.
|
||||
|
||||
## Contribute
|
||||
|
||||
|
|
1
mega/__init__.py
Normal file
1
mega/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from .mega import Mega
|
|
@ -7,8 +7,8 @@ import os
|
|||
import random
|
||||
import binascii
|
||||
import requests
|
||||
import errors
|
||||
from crypto import *
|
||||
from .errors import ValidationError,RequestError
|
||||
from .crypto import *
|
||||
|
||||
|
||||
class Mega(object):
|
||||
|
@ -32,7 +32,7 @@ class Mega(object):
|
|||
resp = self.api_request({'a': 'us', 'user': email, 'uh': uh})
|
||||
#if numeric error code response
|
||||
if isinstance(resp, int):
|
||||
raise errors.RequestError(resp)
|
||||
raise RequestError(resp)
|
||||
self._login_process(resp, password_aes)
|
||||
|
||||
def _login_process(self, resp, password):
|
||||
|
@ -82,7 +82,7 @@ class Mega(object):
|
|||
|
||||
#if numeric error code response
|
||||
if isinstance(json_resp, int):
|
||||
raise errors.RequestError(json_resp)
|
||||
raise RequestError(json_resp)
|
||||
return json_resp[0]
|
||||
|
||||
def get_files(self):
|
||||
|
@ -129,7 +129,7 @@ class Mega(object):
|
|||
public_handle,
|
||||
decrypted_key)
|
||||
else:
|
||||
raise errors.ValidationError('File id and key must be present')
|
||||
raise ValidationError('File id and key must be present')
|
||||
|
||||
def download_url(self, url, dest_path=None):
|
||||
'''
|
||||
|
@ -154,7 +154,7 @@ class Mega(object):
|
|||
path = match[0]
|
||||
return path
|
||||
else:
|
||||
raise errors.RequestError('Url key missing')
|
||||
raise RequestError('Url key missing')
|
||||
|
||||
def get_user(self):
|
||||
user_data = self.api_request({'a': 'ug'})
|
||||
|
@ -359,6 +359,13 @@ class Mega(object):
|
|||
"""
|
||||
if file['t'] == 0 or file['t'] == 1:
|
||||
key = file['k'][file['k'].index(':') + 1:]
|
||||
#fix for shared folder key format {k: foo1:bar1/foo2:bar2 }
|
||||
uid = file['u']
|
||||
keys = file['k'].split('/')
|
||||
regex = re.compile('^%s:.*$' % uid)
|
||||
for keytmp in keys:
|
||||
if regex.match(keytmp):
|
||||
key = keytmp[keytmp.index(':') + 1:]
|
||||
key = decrypt_key(base64_to_a32(key), self.master_key)
|
||||
if file['t'] == 0:
|
||||
k = (key[0] ^ key[4], key[1] ^ key[5], key[2] ^ key[6],
|
41
setup.py
Normal file
41
setup.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*
|
||||
|
||||
from distutils.core import setup
|
||||
import os
|
||||
|
||||
|
||||
def get_packages(package):
|
||||
"""
|
||||
Return root package & all sub-packages.
|
||||
"""
|
||||
return [dirpath
|
||||
for dirpath, dirnames, filenames in os.walk(package)
|
||||
if os.path.exists(os.path.join(dirpath, '__init__.py'))]
|
||||
|
||||
def get_package_data(package):
|
||||
"""
|
||||
Return all files under the root package, that are not in a
|
||||
package themselves.
|
||||
"""
|
||||
walk = [(dirpath.replace(package + os.sep, '', 1), filenames)
|
||||
for dirpath, dirnames, filenames in os.walk(package)
|
||||
if not os.path.exists(os.path.join(dirpath, '__init__.py'))]
|
||||
|
||||
filepaths = []
|
||||
for base, filenames in walk:
|
||||
filepaths.extend([os.path.join(base, filename)
|
||||
for filename in filenames])
|
||||
return {package: filepaths}
|
||||
|
||||
setup(
|
||||
name='mega.py',
|
||||
version='0.8',
|
||||
packages=get_packages('mega'),
|
||||
package_data=get_package_data('mega'),
|
||||
description='Python lib for the Mega.co.nz API',
|
||||
author='Richard O\'Dwyer',
|
||||
author_email='richard@richard.do',
|
||||
license='Creative Commons Attribution-Noncommercial-Share Alike license',
|
||||
long_description=open('README.md').read(),
|
||||
)
|
|
@ -1,6 +1,5 @@
|
|||
from mega import Mega
|
||||
|
||||
|
||||
def test():
|
||||
#user details
|
||||
email = 'your@email.com'
|
||||
|
@ -23,11 +22,11 @@ def test():
|
|||
print files[file]
|
||||
|
||||
##upload file
|
||||
print(m.upload('test.py'))
|
||||
print(m.upload('tests.py'))
|
||||
|
||||
##get file's public link
|
||||
#NOTE: if passing upload() function response use get_upload_link()
|
||||
file = m.find('test.py')
|
||||
file = m.find('tests.py')
|
||||
#print(m.get_upload_link(file))
|
||||
print(m.get_link(file))
|
||||
|
||||
|
@ -42,7 +41,7 @@ def test():
|
|||
print(m.delete(file[1]['k']))
|
||||
|
||||
##download file
|
||||
#file = m.find('test.py')
|
||||
#file = m.find('tests.py')
|
||||
#m.download(file)
|
||||
##specify destination folder
|
||||
#m.download(file, '/home/user_name/Desktop')
|
Loading…
Reference in a new issue