Esempio n. 1
0
def do_post(path, ulabel):
  mycloud = Cloud()
  mycloud.auth('*****@*****.**', '')
  img = mycloud.upload_file(path.get_text() )
  share_url = img["url"]
  print "Successfully upload photo - "
  print share_url
  ulabel.set_text("Image uploaded by url: " + share_url)
  pyperclip.copy(share_url)
Esempio n. 2
0
def main():
    c = Cloud()
    c.auth(os.environ['CLOUDAPP_USERNAME'], os.environ['CLOUDAPP_PASSWORD'])
    drop = c.upload_file(sys.argv[1])
    subprocess.Popen('echo %s | pbcopy' % drop['url'], shell=True)
    print
    print drop['url']
    print drop['content_url']
    print
Esempio n. 3
0
    def logincloudapp(self, email, password):
        if hasattr(self, 'mycloud'):
            if self.mycloud.auth_success == 1:
                return True

        self.mycloud = Cloud()
        return self.mycloud.auth(email, password)
Esempio n. 4
0
else:
    with open("%s/.cloud" % HOME, "w") as f:
        with open("%s/cloud-settings.json" % SCRIPT_FOLDER, "r") as s:
            f.write(s.read())
    abort("You need to type your email and password into ~/.cloud file")

try:
    from cloudapp.cloud import Cloud
except Exception, e:
    abort("You need to install CloudApp API wrapper from https://github.com/originell/pycloudapp")

if not sys.argv[1:]:
    abort("You need to specify a file or two to upload. Or three... or... you got this.")

urls = []
your_cloud = Cloud()

try:
    your_cloud.auth(SETTINGS["email"], SETTINGS["password"])
except KeyError, e:
    abort("You missed either `email` or `password` key in ~/.cloud file. Please check your settings.")
except Exception, e:
    abort("CloudApp authentication failed. Check your email/password in ~/.cloud file.")

if not your_cloud.auth_success:
    abort("CloudApp authentication failed. Check your email/password in ~/.cloud file.")

whats = {
    'source': lambda x,v:x.append(v["content_url"]),
    'view': lambda x,v:x.append(v["url"]),
}
Esempio n. 5
0
""" % (url, title)

def upload_files_from_directory(mycloud, directory):
	file_index = ''
	for f in os.listdir(directory):
		if os.path.splitext(f)[1][1:] in EXTS:
			path = os.path.join(directory, f)
			uploaded = mycloud.upload_file(path)
			file_index += make_dir_entry(f, uploaded['url'])
	return file_index

def upload_string_as_file(mycloud, string, suffix):
	index = tempfile.NamedTemporaryFile(suffix=suffix, dir='.')
	index.write(string)
	index.flush()
	uploaded = mycloud.upload_file(index.name)
	index.close()
	return uploaded['remote_url']

if __name__ == '__main__':
	mycloud = Cloud()
	mycloud.auth(CLOUD_USER, CLOUD_PASS)

	file_index = upload_files_from_directory(mycloud, DIR)
	if file_index == '':
		print 'Nothing to upload.'
		sys.exit(1)

	template = fill_template(TITLE, file_index)
	print upload_string_as_file(mycloud, template, '.html')
Esempio n. 6
0
class mysqlcloudback:

    def backtik(self, cmd):
        p = subprocess.Popen(['/bin/sh', '-c', cmd], stdout=subprocess.PIPE)
        p.wait()
        return p.stdout.read()

    def generatefilename(self, nprefix, format, nsuffix):
        return nprefix + datetime.now().strftime(format) + nsuffix

    def compressbackup(self, filepath, cformat):
        if cformat not in ['bzip2', 'gzip']:
            raise Exception("Unsupported compression format")
        output = self.backtik("%s %s" % (cformat, filepath))
        if output != "":
            raise Exception("%s said %s" % (cformat, output))
        if cformat == "bzip2":
            compressedfile = filepath + ".bz2"
        elif cformat == "gzip":
            compressedfile = filepath + ".gz"
        if not os.path.exists(compressedfile):
            raise Exception("Compressed file not created or someone ate it up")
        return compressedfile

    def runmysqldump(self, filepath, mhost, mdb, muser, mpass):
        self.backtik("mysqldump -h %s -u '%s' -p'%s' %s > %s" % (mhost,
                     muser, mpass, mdb, filepath))

    def splitfile(self, filepath, sizemb, suffix, deleteorig):
        self.backtik("split -b %i %s %s" % (int(sizemb * 1024 * 1024),
                     filepath, filepath + suffix))
        if deleteorig:
            self.backtik("rm -f %s" % filepath)
        return glob("%s%s*" % (filepath, suffix))

    def logincloudapp(self, email, password):
        if hasattr(self, 'mycloud'):
            if self.mycloud.auth_success == 1:
                return True

        self.mycloud = Cloud()
        return self.mycloud.auth(email, password)

    def encryptfile(self, filename, passphrase, deleteorig, cypher='aes-128-cbc'):
        self.backtik("openssl %s -pass pass:%s -in %s -out %s" % (cypher,
                     passphrase, filename, filename + ".aes"))
        if os.path.exists(filename + ".aes"):
            if deleteorig:
                self.backtik("rm -f %s" % filename)
            return filename + ".aes"
        else:
            raise Exception("Encryption Failed")

    def decryptfile(self, filename, passphrase, deleteorig, cypher='aes-128-cbc'):
        self.backtik("openssl %s -d -pass pass:%s -in %s -out %s" % (cypher,
                     passphrase, filename + ".aes", filename))
        if os.path.exists(filename):
            if deleteorig:
                self.backtik("rm -f %s" % filename + ".aes")
            return filename
        else:
            raise Exception("Decryption Failed")

    def uploadcloudapp(self, filelist):
        uploadlist = []
        for files in filelist:
            res = self.mycloud.upload_file(files, True)
            if 'download_url' in res:
                uploadlist.append(res['download_url'])
            else:
                raise Exception("Upload Failed")
        return uploadlist

    def downloadfile(self):
        raise Exception("TODO: Not implemented yet")

    def joinfiles(self, filename, suffix):
        raise Exception("TODO: Not implemented yet")
Esempio n. 7
0
#!/usr/bin/python2

from cloudapp.cloud import Cloud
from ConfigParser import SafeConfigParser
import argparse
import os
import xerox

argparser = argparse.ArgumentParser(description='Cloudapp Uploader')
argparser.add_argument('-u', '--upload', help='Filename to upload', required=True)
args = argparser.parse_args()
confparser = SafeConfigParser()
confparser.read(os.path.abspath(os.path.join(os.path.dirname(__file__), './smallcloud.conf')))

mycloud = Cloud()
mycloud.auth(confparser.get('auth', 'username'), confparser.get('auth', 'password'))

print('Uploading ' + args.upload + '...')
mycloud.upload_file(args.upload)
xerox.copy(mycloud.list_items(page=1, per_page=1)[0]['url'])
print('Upload Successful. Copied link to clipboard.')
Esempio n. 8
0
# 2. Config
usr = get("database", "username")
pwd = get("database", "password")
db = get("database", "database")
dump = os.path.join(get("dump", "dirname"), "%s-%s.sql" % (db, strftime("%Y%m%d-%H%M%S", gmtime())))
if db == "--all-databases":
    dump = os.path.join(get("dump", "dirname"), "%s-%s.sql" % ("all_db", strftime("%Y%m%d-%H%M%S", gmtime())))

# 3. Process
timestamp = "%Y-%m-%d %H:%M:%S"
logger.info(strftime(timestamp, gmtime()) + ": Mysqldump started")
print strftime(timestamp, gmtime()) + ": Mysqldump started"
subprocess.call(
    "mysqldump --user %s --password=%s --force --flush-privileges --compress --comments %s > %s" % (usr, pwd, db, dump),
    shell=True,
)
subprocess.call("tar -czf %s.tgz %s" % (dump, dump), shell=True)
logger.info(strftime(timestamp, gmtime()) + ": Mysqldump finished")
print strftime(timestamp, gmtime()) + ": Mysqldump finished"

# sending to cloud
if tocloud:
    cloud = Cloud()
    try:
        cloud.auth(base64.decodestring(get("cloudapp", "username")), base64.decodestring(get("cloudapp", "password")))
        cloud.upload_file(dump)
        logger.info("Upload sucefully uploaded")
    except HTTPError:
        print "Wrong username or password."
        logger.error("Wrong username or password.")
Esempio n. 9
0
#!/usr/bin/env python
print "CloudApp all item snapshot"
login=raw_input("Login to CloudApp: ")
import getpass
passw=getpass.getpass("Password for CloudApp: ")
from cloudapp.cloud import Cloud
mycloud=Cloud()
mycloud.auth(login,passw)
print "Getting items..."
finished = False
items=[]
cpg=1
while not finished:
	current = mycloud.list_items(page=cpg, per_page=2000)
	if len(current) == 0:
		finished = True;
	for itemDict in current:
		if 'download_url' in itemDict:
			items.append(itemDict['download_url'])
	cpg = cpg + 1
print "Got "+str(len(items))+" items"
import urllib
for url in items:
	webFile = urllib.urlopen(url)
	name = urllib.unquote(urllib.unquote(url.split('/')[-1]))
	print "Downloading \""+name+"\"..."
	localFile = open(name, 'w')
	localFile.write(webFile.read())
	localFile.close()
print "Completed."
print "by vladkorotnev, 2013"