def legal_filename(filename): try: filename = filename.strip() filename = re.sub(r'(?!%s)[^\w\-_\.]', '.', filename) filename = re.sub('\.+', '.', filename) filename = re.sub(re.compile('(CON|PRN|AUX|NUL|COM\d|LPT\d)\.', re.I), '\\1_', filename) control.legalFilename(filename) return filename except: return filename
def write_file(path, content): try: path = control.legalFilename(path) if not isinstance(content, basestring): content = str(content) file = control.openFile(path, 'w') file.write(str(content)) file.close() except: log_utils.error()
def write_file(path, content): try: path = control.legalFilename(path) if not isinstance(content, six.string_types): content = str(content) file = control.openFile(path, 'w') file.write(str(content)) file.close() except Exception as e: pass
def write_file(path, content): try: path = control.legalFilename(path) # if not isinstance(content, basestring): if not isinstance(content, py_tools.string_types): # content = str(content) content = py_tools.ensure_str(content) file = control.openFile(path, 'w') file.write(str(content)) file.close() except: log_utils.error()
def create_folder(folder): try: folder = control.legalFilename(folder) control.makeFile(folder) try: if 'ftp://' not in folder: raise Exception() from ftplib import FTP ftparg = re.compile(r'ftp://(.+?):(.+?)@(.+?):?(\d+)?/(.+/?)').findall(folder) ftp = FTP(ftparg[0][2], ftparg[0][0], ftparg[0][1]) try: ftp.cwd(ftparg[0][4]) except: ftp.mkd(ftparg[0][4]) ftp.quit() except: log_utils.error() except: log_utils.error()