def get_file(fname): import webnotes in_fname = fname # from the "File" table if webnotes.conn.exists('File',fname): fname = webnotes.conn.sql("select file_list from tabFile where name=%s", fname) fname = fname and fname[0][0] fname = fname.split('\n')[0].split(',')[1] if get_file_system_name(fname): f = get_file_system_name(fname)[0] else: f = None # read the file import os file_id = f[0].replace('/','-') file = open(os.path.join(webnotes.get_files_path(), file_id), 'r') content = file.read() file.close() return [f[1], content]
def delete_file(fid, verbose=0): """delete file from file system""" import os webnotes.conn.sql("delete from `tabFile Data` where name=%s", fid) path = os.path.join(webnotes.get_files_path(), fid.replace('/','-')) if os.path.exists(path): os.remove(path)
def write_file(fid, content): import os, webnotes.defs # test size max_file_size = 1000000 if hasattr(webnotes.defs, 'max_file_size'): max_file_size = webnotes.defs.max_file_size if len(content) > max_file_size: raise Exception, 'Maximum File Limit (%s MB) Crossed' % (int( max_file_size / 1000000)) # no slashes fid = fid.replace('/', '-') # save to a folder (not accessible to public) folder = webnotes.get_files_path() # create account folder (if not exists) webnotes.create_folder(folder) # write the file file = open(os.path.join(folder, fid), 'w+') file.write(content) file.close()
def delete_file(fname, verbose=0): import webnotes, os for f in get_file_system_name(fname): webnotes.conn.sql("delete from `tabFile Data` where name=%s", f[0]) # delete file file_id = f[0].replace('/','-') try: os.remove(os.path.join(webnotes.get_files_path(), file_id)) except OSError, e: if e.args[0]!=2: raise e if verbose: webnotes.msgprint('File Deleted')
def get_file(fname): f = get_file_system_name(fname) if f: file_id = f[0][0].replace('/','-') file_name = f[0][1] else: file_id = fname file_name = fname # read the file import os with open(os.path.join(webnotes.get_files_path(), file_id), 'r') as f: content = f.read() return [file_name, content]
def delete_file(fname, verbose=0): import os for f in get_file_system_name(fname): webnotes.conn.sql("delete from `tabFile Data` where name=%s", f[0]) # delete file file_id = f[0].replace('/', '-') try: os.remove(os.path.join(webnotes.get_files_path(), file_id)) except OSError, e: if e.args[0] != 2: raise e if verbose: webnotes.msgprint('File Deleted')
def get_file(fname): """deprecated""" f = get_file_system_name(fname) if f: file_id = f[0][0].replace("/", "-") file_name = f[0][1] else: file_id = fname file_name = fname # read the file import os with open(os.path.join(webnotes.get_files_path(), file_id), "r") as f: content = f.read() return [file_name, content]
def get_file(fname): in_fname = fname # from the "File" table if webnotes.conn.exists('File', fname): fname = webnotes.conn.sql( "select file_list from tabFile where name=%s", fname) fname = fname and fname[0][0] fname = fname.split('\n')[0].split(',')[1] if get_file_system_name(fname): f = get_file_system_name(fname)[0] else: f = None # read the file import os file_id = f[0].replace('/', '-') file = open(os.path.join(webnotes.get_files_path(), file_id), 'r') content = file.read() file.close() return [f[1], content]
def write_file(fid, content): import os, webnotes.defs # test size max_file_size = 1000000 if hasattr(webnotes.defs, "max_file_size"): max_file_size = webnotes.defs.max_file_size if len(content) > max_file_size: raise Exception, "Maximum File Limit (%s MB) Crossed" % (int(max_file_size / 1000000)) # no slashes fid = fid.replace("/", "-") # save to a folder (not accessible to public) folder = webnotes.get_files_path() # create account folder (if not exists) webnotes.create_folder(folder) # write the file file = open(os.path.join(folder, fid), "w+") file.write(content) file.close()
def write_file(fid, content): import os, conf # test size max_file_size = 1000000 if hasattr(conf, 'max_file_size'): max_file_size = conf.max_file_size if len(content) > max_file_size: raise Exception, 'Maximum File Limit (%s MB) Crossed' % (int(max_file_size / 1000000)) # no slashes fid = fid.replace('/','-') # save to a folder (not accessible to public) folder = webnotes.get_files_path() # create account folder (if not exists) webnotes.create_folder(folder) # write the file file = open(os.path.join(folder, fid),'w+') file.write(content) file.close()