Skip to content

Commit

Permalink
Merge pull request #184 from abarrafo/ab-download-folder
Browse files Browse the repository at this point in the history
  • Loading branch information
jankatins committed Apr 12, 2020
2 parents 95c086b + 62e3d98 commit 8656d4d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ Note that for citeproc tests to pass you'll need to have [pandoc-citeproc](https
* [Felix Yan](https://github.com/felixonmars) - Added installation instructions for Arch Linux.
* [Kolen Cheung](https://github.com/ickc) - Implement `_get_pandoc_urls` for installing arbitrary version as well as the latest version of pandoc. Minor: README, Travis, setup.py.
* [Rebecca Heineman](https://github.com/burgerbecky) - Added scanning code for finding pandoc in Windows
* [Andrew Barraford](https://github.com/abarrafo) - Download destination.

## License

Expand Down
14 changes: 12 additions & 2 deletions pypandoc/pandoc_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _handle_win32(filename, targetfolder):
print("* Done.")


def download_pandoc(url=None, targetfolder=None, version="latest", quiet=False, delete_installer=False):
def download_pandoc(url=None, targetfolder=None, version="latest", quiet=False, delete_installer=False, download_folder=None):
"""Download and unpack pandoc
Downloads prebuild binaries for pandoc from `url` and unpacks it into
Expand All @@ -160,9 +160,12 @@ def download_pandoc(url=None, targetfolder=None, version="latest", quiet=False,
the latest available release at the time pypandoc was released.
:param str targetfolder: directory, where the binaries should be installed
to. If no `targetfolder` is give, uses a platform specific user
to. If no `targetfolder` is given, uses a platform specific user
location: `~/bin` on Linux, `~/Applications/pandoc` on Mac OS X, and
`~\\AppData\\Local\\Pandoc` on Windows.
:param str download_folder: Directory, where the installer should download files before unpacking
to the target folder. If no `download_folder` is given, uses the current directory. example: `/tmp/`, `/tmp`
"""
if quiet:
sys.stdout = open(os.devnull, 'w')
Expand All @@ -184,6 +187,13 @@ def download_pandoc(url=None, targetfolder=None, version="latest", quiet=False,
url = pandoc_urls[pf]

filename = url.split("/")[-1]

if download_folder is not None:
if download_folder.endswith('/'):
download_folder = download_folder[:-1]

filename = os.path.expanduser(download_folder) + '/' + filename

if os.path.isfile(filename):
print("* Using already downloaded file %s" % (filename))
else:
Expand Down

0 comments on commit 8656d4d

Please sign in to comment.