(browse_for, path="")
| 72 | return render_to_response('base.html', {'messages': messages}, [pre_processor]) |
| 73 | |
| 74 | def choose_path(browse_for, path=""): |
| 75 | path = os.path.normpath(unquotepath(path)) |
| 76 | |
| 77 | try: |
| 78 | path = path.decode("utf8") |
| 79 | except: |
| 80 | pass |
| 81 | |
| 82 | if os.path.isfile(path): |
| 83 | oldfile = path |
| 84 | path = os.path.dirname(path) |
| 85 | else: |
| 86 | oldfile = '' |
| 87 | |
| 88 | abs = False |
| 89 | |
| 90 | if os.path.isdir(path): |
| 91 | if os.path.isabs(path): |
| 92 | cwd = os.path.abspath(path) |
| 93 | abs = True |
| 94 | else: |
| 95 | cwd = relpath(path) |
| 96 | else: |
| 97 | cwd = os.getcwd() |
| 98 | |
| 99 | cwd = os.path.normpath(os.path.abspath(cwd)) |
| 100 | parentdir = os.path.dirname(cwd) |
| 101 | if not abs: |
| 102 | if os.path.abspath(cwd) == os.path.abspath("/"): |
| 103 | cwd = relpath(cwd) |
| 104 | else: |
| 105 | cwd = relpath(cwd) + os.path.sep |
| 106 | parentdir = relpath(parentdir) + os.path.sep |
| 107 | |
| 108 | if os.path.abspath(cwd) == os.path.abspath("/"): |
| 109 | parentdir = "" |
| 110 | |
| 111 | |
| 112 | # try: |
| 113 | # cwd = cwd.encode("utf8") |
| 114 | # except: |
| 115 | # pass |
| 116 | # |
| 117 | try: |
| 118 | folders = os.listdir(cwd) |
| 119 | except: |
| 120 | folders = [] |
| 121 | |
| 122 | files = [] |
| 123 | |
| 124 | for f in folders: |
| 125 | try: |
| 126 | # f = f.decode(getfilesystemencoding()) |
| 127 | data = {'name': f, 'fullpath': join(cwd, f)} |
| 128 | data['sort'] = data['fullpath'].lower() |
| 129 | data['modified'] = datetime.fromtimestamp(int(os.path.getmtime(join(cwd, f)))) |
| 130 | data['ext'] = os.path.splitext(f)[1] |
| 131 | except: |
no test coverage detected