Single sourcing version number in fanficfare/__init__.py

This commit is contained in:
Jim Miller 2016-08-30 21:50:35 -05:00
parent 173fca8773
commit 43637fa67b
4 changed files with 33 additions and 15 deletions

View file

@ -32,6 +32,9 @@ except NameError:
# The class that all Interface Action plugin wrappers must inherit from
from calibre.customize import InterfaceActionBase
## single sourcing version number in fanficfare/__init__.py
from calibre_plugins.fanficfare_plugin.fanficfare import __version_num__
## Apparently the name for this class doesn't matter--it was still
## 'demo' for the first few versions.
class FanFicFareBase(InterfaceActionBase):
@ -48,7 +51,7 @@ class FanFicFareBase(InterfaceActionBase):
description = _('UI plugin to download FanFiction stories from various sites.')
supported_platforms = ['windows', 'osx', 'linux']
author = 'Jim Miller'
version = (2, 3, 6)
version = __version_num__
minimum_calibre_version = (1, 48, 0)
#: This field defines the GUI plugin class that contains all the code
@ -116,18 +119,18 @@ class FanFicFareBase(InterfaceActionBase):
from calibre_plugins.fanficfare_plugin.fanficfare.cli import main as fff_main
from calibre_plugins.fanficfare_plugin.prefs import PrefsFacade
from calibre.utils.config import prefs as calibre_prefs
from optparse import OptionParser
from optparse import OptionParser
parser = OptionParser('%prog --run-plugin '+self.name+' -- [options] <storyurl>')
parser.add_option('--library-path', '--with-library', default=None, help=_('Path to the calibre library. Default is to use the path stored in the settings.'))
# parser.add_option('--dont-notify-gui', default=False, action='store_true',
# help=_('Do not notify the running calibre GUI (if any) that the database has'
# ' changed. Use with care, as it can lead to database corruption!'))
pargs = [x for x in argv if x.startswith('--with-library') or x.startswith('--library-path')
or not x.startswith('-')]
opts, args = parser.parse_args(pargs)
fff_prefs = PrefsFacade(db(path=opts.library_path,
read_only=True))

View file

@ -17,7 +17,7 @@
try:
# just a way to switch between web service and CLI/PI
import google.appengine.api
import google.appengine.api
except:
try: # just a way to switch between CLI and PI
import calibre.constants
@ -32,3 +32,8 @@ except:
loghandler.setLevel(logging.DEBUG)
logger.setLevel(logging.DEBUG)
## single sourcing version number in fanficfare/__init__.py
## __version_num__ for calibre plugin
## __version__ moved from ../setup.py so cli.py can also display it.
__version_num__ = (2, 3, 6)
__version__ = ".".join([unicode(x) for x in __version_num__])

View file

@ -39,13 +39,13 @@ if sys.version_info >= (2, 7):
try:
# running under calibre
from calibre_plugins.fanficfare_plugin.fanficfare import adapters, writers, exceptions
from calibre_plugins.fanficfare_plugin.fanficfare import adapters, writers, exceptions, __version__
from calibre_plugins.fanficfare_plugin.fanficfare.configurable import Configuration
from calibre_plugins.fanficfare_plugin.fanficfare.epubutils import (
get_dcsource_chaptercount, get_update_data, reset_orig_chapters_epub)
from calibre_plugins.fanficfare_plugin.fanficfare.geturls import get_urls_from_page
except ImportError:
from fanficfare import adapters, writers, exceptions
from fanficfare import adapters, writers, exceptions, __version__
from fanficfare.configurable import Configuration
from fanficfare.epubutils import (
get_dcsource_chaptercount, get_update_data, reset_orig_chapters_epub)
@ -114,9 +114,17 @@ def main(argv=None, parser=None, passed_defaultsini=None, passed_personalini=Non
parser.add_option('-d', '--debug',
action='store_true', dest='debug',
help='Show debug output while downloading.', )
parser.add_option('-v', '--version',
action='store_true', dest='version',
help='Display version and quit.', )
options, args = parser.parse_args(argv)
if options.version:
## single sourcing version number in fanficfare/__init__.py
print("Version: %s" % __version__)
return
if not options.debug:
logger = logging.getLogger('fanficfare')
logger.setLevel(logging.INFO)
@ -142,7 +150,7 @@ def main(argv=None, parser=None, passed_defaultsini=None, passed_personalini=Non
urls=[]
with open(options.infile,"r") as infile:
#print "File exists and is readable"
#fileurls = [line.strip() for line in infile]
for url in infile:
url = url[:url.find('#')].strip()
@ -173,7 +181,7 @@ def do_download(arg,
options,
passed_defaultsini,
passed_personalini):
# Attempt to update an existing epub.
chaptercount = None
output_filename = None
@ -182,7 +190,7 @@ def do_download(arg,
# remove mark_new_chapters marks
reset_orig_chapters_epub(arg,arg)
return
if options.update:
try:
url, chaptercount = get_dcsource_chaptercount(arg)
@ -197,7 +205,7 @@ def do_download(arg,
url = arg
else:
url = arg
try:
configuration = Configuration(adapters.getConfigSectionsFor(url), options.format)
except exceptions.UnknownSite, e:
@ -269,10 +277,10 @@ def do_download(arg,
if not hasattr(options,'pagecache'):
options.pagecache = adapter.get_empty_pagecache()
options.cookiejar = adapter.get_empty_cookiejar()
adapter.set_pagecache(options.pagecache)
adapter.set_cookiejar(options.cookiejar)
adapter.setChaptersRange(options.begin, options.end)
# check for updating from URL (vs from file)

View file

@ -17,13 +17,15 @@ from os import path
with codecs.open('DESCRIPTION.rst', encoding='utf-8') as f:
long_description = f.read()
from fanficfare import __version__
setup(
name="FanFicFare",
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version="2.3.6",
version=__version__,
description='A tool for downloading fanfiction to eBook formats',
long_description=long_description,