Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/dev.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ credential.password=testPwd
[path]
path.ebooks=ebooks
path.extras=ebooks/extras
#path.separate.ebooks=MY/EBOOKS/FOLDER
#path.separate.extras=MY/EXTRAS/FOLDER

[drive]
drive.oauth2_scope=https://www.googleapis.com/auth/drive
Expand Down
3 changes: 3 additions & 0 deletions config/prod_example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ credential.password=PACKTPUB_PASSWORD
[path]
path.ebooks=ebooks
path.extras=ebooks/extras
#path.separate.ebooks=MY/EBOOKS/FOLDER
#path.separate.extras=MY/EXTRAS/FOLDER
Copy link
Owner

@niqdev niqdev Dec 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, I like it in this way with the has_option

path.separate.space=_

[drive]
drive.oauth2_scope=https://www.googleapis.com/auth/drive
Expand Down
21 changes: 19 additions & 2 deletions script/packtpub.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,16 @@ def download_ebooks(self, types):
filename=self.info['filename'] + '.' + type)
for type in types]

directory = self.__config.get('path', 'path.ebooks')
if self.__config.has_option('path', 'path.separate.extras'):
space = self.__config.get('path', 'path.separate.space')

if space == '?':
space = ' '

directory = self.__config.get('path', 'path.separate.ebooks') + '/' + self.info['title'].encode('ascii', 'ignore').replace(' ', space) + space + '-' + space + self.info['author'].encode('ascii', 'ignore').replace(' ', space)
else:
directory = self.__config.get('path', 'path.ebooks')

for download in downloads_info:
self.info['paths'].append(
download_file(self.__session, download['url'], directory, download['filename'], self.__headers))
Expand All @@ -132,7 +141,15 @@ def download_extras(self):
"""
"""

directory = self.__config.get('path', 'path.extras')
if self.__config.has_option('path', 'path.separate.extras'):
space = self.__config.get('path', 'path.separate.space')

if space == '?':
space = ' '

directory = self.__config.get('path', 'path.separate.ebooks') + '/' + self.info['title'].encode('ascii', 'ignore').replace(' ', space) + space + '-' + space + self.info['author'].encode('ascii', 'ignore').replace(' ', space) + '/' + self.__config.get('path', 'path.separate.extras')
else:
directory = self.__config.get('path', 'path.extras')

url_image = self.info['url_image']
filename = self.info['filename'] + '_' + split(url_image)[1]
Expand Down