Beispiel #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)
Beispiel #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
Beispiel #3
0
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"]),
}

for f in sys.argv[1:]:
    response = your_cloud.upload_file(f)
    print("Uploaded %s to %s" %(f, response['url']))
    whats[SETTINGS.get("mode", "source")](urls, response)

try:
    cmd = 'echo %s | tr -d "\\n" | pbcopy' % ','.join(urls) # this doesn't work under terminal multiplexers like tmux... pbcopy's fault
    ret = call(cmd, shell=True)
    if ret < 0:
        fallback(urls)
except OSError, e:
    fallback(urls)
Beispiel #4
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")
Beispiel #5
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.')
Beispiel #6
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.")