def flush(self): with tempfile.NamedTemporaryFile() as tf: data_to_png(self._stringio_get_data()).save(tf, 'png') if self.imageid: flickr.replace(filename=tf.name, photo_id=self.imageid, title=self.name, description=str(len(data)), format='bs4') else: self.imageid = flickr.upload(filename=tf.name, title=self.name, description=str(len(data)), format='bs4').photoid.text
else: raise fs.errors.ResourceNotFoundError(path) ########NEW FILE######## __FILENAME__ = runflickrfs from fs.expose import fuse from flickrfs import FlickrFS, data_to_png, png_to_data import requests import sys if __name__ == '__main__': if sys.argv[1] == 'encode': filefrom, fileto = sys.argv[2], sys.argv[3] with open(filefrom) as ff, open(fileto, 'w') as ft: img = data_to_png(ff.read()) img.save(ft, 'png') elif sys.argv[1] == 'decode': filefrom, fileto = sys.argv[2], sys.argv[3] with open(filefrom) as ff, open(fileto, 'w') as ft: data = png_to_data(ff.read()) ft.write(data) elif sys.argv[1] == 'upload': filefrom = sys.argv[2] with open(filefrom) as ff, tempfile.NamedTemporaryFile() as tf: img = data_to_png(ff.read()) img.save(tf, 'png') print flickr.upload(filename=tf.name, format='bs4').photoid.text elif sys.argv[1] == 'download': imageid, fileto = sys.argv[2], sys.argv[3] with open(fileto, 'w') as ft:
from fs.expose import fuse from flickrfs import FlickrFS, data_to_png, png_to_data import requests import sys if __name__ == "__main__": if sys.argv[1] == "encode": filefrom, fileto = sys.argv[2], sys.argv[3] with open(filefrom) as ff, open(fileto, "w") as ft: img = data_to_png(ff.read()) img.save(ft, "png") elif sys.argv[1] == "decode": filefrom, fileto = sys.argv[2], sys.argv[3] with open(filefrom) as ff, open(fileto, "w") as ft: data = png_to_data(ff.read()) ft.write(data) elif sys.argv[1] == "upload": filefrom = sys.argv[2] with open(filefrom) as ff, tempfile.NamedTemporaryFile() as tf: img = data_to_png(ff.read()) img.save(tf, "png") print flickr.upload(filename=tf.name, format="bs4").photoid.text elif sys.argv[1] == "download": imageid, fileto = sys.argv[2], sys.argv[3] with open(fileto, "w") as ft: url = flickr.get_sizes(photo_id=imageid, format="bs4").sizes.find("size", label="Original")["source"] ft.write(png_to_data(requests.get(url).content)) elif len(sys.argv) == 2: mp = fuse.mount(FlickrFS(), sys.argv[1]) print "mounted your filckr account on", mp.path, "pid", mp.pid, "."