def get_yahoo_icon(): try: http = urllib3.PoolManager() fetch_data = http.request('GET', 'http://opi.yahoo.com/online?u=%s&m=t&t=1' % request.args[0]) if fetch_data.status == 200: from fs.osfs import OSFS file_server = OSFS('/home/www-data/web2py/applications/cbw/static/images') if len(request.args) != 1: raise HTTP(400) if fetch_data.data == "01": path = "icon-YMonline.png" else: path = "icon-YMoffline.png" if file_server.exists(path): response.headers['Content-Length'] = file_server.getinfo(path)['size'] response.headers['Content-Type'] = 'image/png' response.headers['Content-Disposition'] = "attachment; filename=yahoo.png" return response.stream(file_server.open(path=path, mode='rb')) else: raise HTTP(404) else: raise Exception(fetch_data.status) except: return None
def demo(): try: from fs.osfs import OSFS file_server = OSFS('/home/demo/') if len(request.args) != 1: raise HTTP(400) path = request.args[0] if file_server.exists(path): response.headers['Content-Length'] = file_server.getinfo( path)['size'] response.headers['Content-Type'] = 'application/octet-stream' response.headers[ 'Content-Disposition'] = "attachment; filename=%s" % path return response.stream(file_server.open(path=path, mode='rb')) else: raise HTTP(404) except: raise HTTP(200, "ERROR")
def publish(self): super(PyFS, self).publish() deploy_fs = OSFS(self.site.config.deploy_root_path.path) for (dirnm, local_filenms) in deploy_fs.walk(): logger.info("Making directory: %s", dirnm) self.fs.makedir(dirnm, allow_recreate=True) remote_fileinfos = self.fs.listdirinfo(dirnm, files_only=True) # Process each local file, to see if it needs updating. for filenm in local_filenms: filepath = pathjoin(dirnm, filenm) # Try to find an existing remote file, to compare metadata. for (nm, info) in remote_fileinfos: if nm == filenm: break else: info = {} # Skip it if the etags match if self.check_etag and "etag" in info: with deploy_fs.open(filepath, "rb") as f: local_etag = self._calculate_etag(f) if info["etag"] == local_etag: logger.info("Skipping file [etag]: %s", filepath) continue # Skip it if the mtime is more recent remotely. if self.check_mtime and "modified_time" in info: local_mtime = deploy_fs.getinfo(filepath)["modified_time"] if info["modified_time"] > local_mtime: logger.info("Skipping file [mtime]: %s", filepath) continue # Upload it to the remote filesystem. logger.info("Uploading file: %s", filepath) with deploy_fs.open(filepath, "rb") as f: self.fs.setcontents(filepath, f) # Process each remote file, to see if it needs deleting. for (filenm, info) in remote_fileinfos: filepath = pathjoin(dirnm, filenm) if filenm not in local_filenms: logger.info("Removing file: %s", filepath) self.fs.remove(filepath)