Variable dest was defined on wrong place.
Details
Details
Diff Detail
Diff Detail
- Repository
- rLTRN libtaskotron
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| kparal | |
| jskladan |
Variable dest was defined on wrong place.
lint
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | libtaskotron/file_utils.py (5 lines) |
| Commit | Tree | Parents | Author | Summary | Date |
|---|---|---|---|---|---|
| c3278c8a4ba1 | 23ab0d4d352c | c568ab64ab68 | Lukas Brabec | fix: file_utils.py dest variable definiton | Jun 26 2014, 1:23 PM |
| c568ab64ab68 | 7aadb68f936d | 55a7edc7736d | Lukas Brabec | fix: file_utils.py dest variable definiton | Jun 26 2014, 1:04 PM |
| Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | 59 | def download(url, dirname, filename=None, overwrite=False, grabber=None): | |||
|---|---|---|---|---|---|
| 76 | :raise TaskotronRemoteError: if download fails or directory can't be created | 76 | :raise TaskotronRemoteError: if download fails or directory can't be created | ||
| 77 | ''' | 77 | ''' | ||
| 78 | if not grabber: | 78 | if not grabber: | ||
| 79 | grabber = get_urlgrabber() | 79 | grabber = get_urlgrabber() | ||
| 80 | 80 | | |||
| 81 | if not filename: | 81 | if not filename: | ||
| 82 | filename = os.path.basename(url) | 82 | filename = os.path.basename(url) | ||
| 83 | 83 | | |||
| 84 | dest = os.path.join(dirname, filename) | ||||
| 84 | 85 | | |||
| 85 | if os.path.exists(dirname): | 86 | if os.path.exists(dirname): | ||
| 86 | if not os.path.isdir(dirname): | 87 | if not os.path.isdir(dirname): | ||
| 87 | raise TaskotronRemoteError( | 88 | raise TaskotronRemoteError( | ||
| 88 | "Can't create directory: %r It is an already " | 89 | "Can't create directory: %r It is an already " | ||
| 89 | "existing file.", dirname) | 90 | "existing file.", dirname) | ||
| 90 | else: | 91 | else: | ||
| 91 | try: | 92 | try: | ||
| 92 | makedirs(dirname) | 93 | makedirs(dirname) | ||
| 93 | except OSError, e: | 94 | except OSError, e: | ||
| 94 | log.exception("Can't create directory: %s", dest) | 95 | log.exception("Can't create directory: %s", dirname) | ||
| 95 | raise TaskotronRemoteError(e) | 96 | raise TaskotronRemoteError(e) | ||
| 96 | 97 | | |||
| 97 | dest = os.path.join(dirname, filename) | | |||
| 98 | | ||||
| 99 | # overwrite? | 98 | # overwrite? | ||
| 100 | if os.path.exists(dest): | 99 | if os.path.exists(dest): | ||
| 101 | if overwrite: | 100 | if overwrite: | ||
| 102 | os.remove(dest) | 101 | os.remove(dest) | ||
| 103 | else: | 102 | else: | ||
| 104 | log.debug('Already downloaded: %s', os.path.basename(dest)) | 103 | log.debug('Already downloaded: %s', os.path.basename(dest)) | ||
| 105 | return dest | 104 | return dest | ||
| 106 | 105 | | |||
| 107 | log.debug('Downloading: %s', url) | 106 | log.debug('Downloading: %s', url) | ||
| 108 | try: | 107 | try: | ||
| 109 | grabber.urlgrab(url, dest) | 108 | grabber.urlgrab(url, dest) | ||
| 110 | except urlgrabber.grabber.URLGrabError, e: | 109 | except urlgrabber.grabber.URLGrabError, e: | ||
| 111 | log.exception('Download failed for: %s', url) | 110 | log.exception('Download failed for: %s', url) | ||
| 112 | # the file can be incomplete, remove | 111 | # the file can be incomplete, remove | ||
| 113 | if os.path.exists(dest): | 112 | if os.path.exists(dest): | ||
| 114 | try: | 113 | try: | ||
| 115 | os.remove(dest) | 114 | os.remove(dest) | ||
| 116 | except OSError, e: | 115 | except OSError, e: | ||
| 117 | log.exception('Could not delete incomplete file: %s', dest) | 116 | log.exception('Could not delete incomplete file: %s', dest) | ||
| 118 | raise TaskotronRemoteError(e) | 117 | raise TaskotronRemoteError(e) | ||
| 119 | 118 | | |||
| 120 | return dest | 119 | return dest | ||
| 121 | No newline at end of file | 120 | No newline at end of file | ||
This was not really the problem (although moving this line does not really break anything). See below.