This repository was archived by the owner on Mar 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmega-upload.py
More file actions
executable file
·61 lines (51 loc) · 1.32 KB
/
mega-upload.py
File metadata and controls
executable file
·61 lines (51 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
#
# Mega Python CommandLine Tools
# Copyright stefano.cudini@gmail.com 2013
# https://opengeo.tech
#
# Source:
# https://github.com/stefanocudini/Mega-Python-CommandLine-Tools
#
# Require:
# https://github.com/richardasaurus/mega.py
#
# Config file, ~/.megarc:
# [default]
# email = my@email.com
# pass = mypass
#
import os
import sys
import ConfigParser
from mega import Mega
configfile = os.path.expanduser("~") + os.sep + '.megarc'
if not os.path.exists(configfile):
sys.exit('File ~/.megarc Not Found!')
config = ConfigParser.RawConfigParser()
config.read(configfile)
email = config.get('default', 'email')
passw = config.get('default', 'pass')
mega = Mega({'verbose': True})
m = mega.login(email, passw)
curDir = os.getcwd() + os.path.sep
dstDirId = None
if len(sys.argv)>1 and sys.argv[1]:
srcs = sys.argv[1:]
else:
srcs = None
print srcs
if srcs:
if len(srcs) > 1 and not os.path.isfile( srcs[-1] ):#if last param isn't a local file then it is dest remote folder
dstName = srcs.pop()
dstId = m.find( dstName )
if dstId:
dstDirId = dstId[0]
print 'Destination Folder: '+ dstName
for src in srcs:
srcFile = curDir + src
if os.path.isfile( srcFile ):
print srcFile
print dstDirId
uppedFile = m.upload(srcFile, dstDirId)
print 'Upped File Link: ' + m.get_upload_link( uppedFile )