Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 639 prints in cdxj #640

Merged
merged 26 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f478ece
Merge pull request #2 from oduwsdl/master
anatoly-scherbakov Apr 27, 2020
15abc94
Replace print() with a logging call
anatoly-scherbakov Apr 27, 2020
2f2be09
Little cleanup, closes #639
anatoly-scherbakov Apr 27, 2020
5f47023
check_for_update.py and better test coverage
anatoly-scherbakov Apr 27, 2020
9c39bf2
Removed the PyPI version check
anatoly-scherbakov Apr 27, 2020
501e381
Remove logError()
anatoly-scherbakov Apr 27, 2020
6ae17f2
A few reformatted imports
anatoly-scherbakov Apr 27, 2020
b38909b
Merge branch 'issue-639-prints-in-cdxj' into issue-639-rebase
machawk1 Jun 29, 2020
422ed3f
Merge pull request #1 from oduwsdl/issue-639-rebase
machawk1 Jun 29, 2020
b6a6ef4
Merge pull request #3 from oduwsdl/master
machawk1 Jul 1, 2020
abfff15
Add missing json dependency
machawk1 Jul 1, 2020
2088f74
Merge pull request #3 from machawk1/issue-639-prints-in-cdxj
anatoly-scherbakov Jul 2, 2020
1ca49d7
introduce error_handler() decorator
anatoly-scherbakov Jul 5, 2020
6184276
Merge pull request #4 from oduwsdl/master
anatoly-scherbakov Jul 5, 2020
9780d0c
Fixed conflicts
anatoly-scherbakov Jul 5, 2020
76d6063
Fixed issues after merging conflicts
anatoly-scherbakov Jul 5, 2020
9bfac3a
Linter error fixed, docstring improved
anatoly-scherbakov Jul 5, 2020
a544698
tests for check_daemon_is_alive()
anatoly-scherbakov Jul 5, 2020
436e257
ipfs_client() is now caching the instance of IPFS client
anatoly-scherbakov Jul 5, 2020
04aa90c
Fix tests
anatoly-scherbakov Jul 5, 2020
f460e8b
More tests to improve coverage
anatoly-scherbakov Jul 5, 2020
e71715a
try-except clauses
anatoly-scherbakov Jul 5, 2020
e5ad8ef
Tests for error_handler.exception_logger()
anatoly-scherbakov Jul 5, 2020
144d897
Make linter a bit happier
anatoly-scherbakov Jul 5, 2020
df09869
Update ipwb/util.py
anatoly-scherbakov Jul 6, 2020
16bbb8f
Update ipwb/__main__.py
anatoly-scherbakov Jul 6, 2020
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
17 changes: 7 additions & 10 deletions ipwb/__main__.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import sys
import os
import argparse
import tempfile
import string # For generating a temp file for stdin
import random # For generating a temp file for stdin
from .__init__ import __version__ as ipwbVersion
from .__init__ import __version__ as ipwb_version

# ipwb modules
from . import replay
from . import indexer
from . import util as ipwbUtil

from .util import IPWBREPLAY_HOST, IPWBREPLAY_PORT
from . import util


def main():
ipwbUtil.checkForUpdate()
args = checkArgs(sys.argv)
util.check_pypi_for_update()
anatoly-scherbakov marked this conversation as resolved.
Show resolved Hide resolved
checkArgs(sys.argv)


def checkArgs_index(args):
if not ipwbUtil.isDaemonAlive():
if not util.isDaemonAlive():
sys.exit()
encKey = None
compressionLevel = None
Expand Down Expand Up @@ -140,11 +137,11 @@ def checkArgs(argsIn):
'-d', '--daemon',
help=("Multi-address of IPFS daemon "
"(default /dns/localhost/tcp/5001/http)"),
default=ipwbUtil.IPFSAPI_MUTLIADDRESS,
default=util.IPFSAPI_MUTLIADDRESS,
dest='daemon_address')
parser.add_argument(
'-v', '--version', help='Report the version of ipwb', action='version',
version='InterPlanetary Wayback ' + ipwbVersion)
version='InterPlanetary Wayback ' + ipwb_version)
anatoly-scherbakov marked this conversation as resolved.
Show resolved Hide resolved

argCount = len(argsIn)
cmdList = ['index', 'replay']
Expand Down
43 changes: 25 additions & 18 deletions ipwb/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import print_function

from os.path import expanduser
from os.path import basename

import os
import sys
Expand All @@ -15,17 +14,19 @@
import logging
import platform

from six.moves.urllib.request import urlopen
import json
from .__init__ import __version__ as ipwbVersion
from .__init__ import __version__ as ipwb_version

from pkg_resources import parse_version

# from requests.exceptions import ConnectionError
from ipfshttpclient.exceptions import ConnectionError
from ipfshttpclient.exceptions import AddressError
from multiaddr.exceptions import StringParseError


logger = logging.getLogger(__name__)


IPFSAPI_MUTLIADDRESS = '/dns/localhost/tcp/5001/http'
# or '/dns/{host}/tcp/{port}/http'
# or '/ip4/{ipaddress}/tcp/{port}/http'
Expand Down Expand Up @@ -305,22 +306,28 @@ def unsurt(surt):
return surt


def compareCurrentAndLatestIPWBVersions():
def compare_current_and_latest_ipwb_versions():
try:
resp = urlopen('https://pypi.python.org/pypi/ipwb/json')
jResp = json.loads(resp.read())
latestVersion = jResp['info']['version']
currentVersion = re.sub(r'\.0+', '.', ipwbVersion)
return (currentVersion, latestVersion)
except Exception as e:
return (None, None)
response = requests.get('https://pypi.python.org/pypi/ipwb/json').json()

latest_version = response['info']['version']
current_version = re.sub(r'\.0+', '.', ipwb_version)

return current_version, latest_version

except Exception:
return None, None


def checkForUpdate():
(current, latest) = compareCurrentAndLatestIPWBVersions()
def check_pypi_for_update():
(current, latest) = compare_current_and_latest_ipwb_versions()

if current != latest and current is not None:
print('This version of ipwb is outdated.'
' Please run pip install --upgrade ipwb.')
print('* Latest version: {0}'.format(latest))
print('* Installed version: {0}'.format(current))
logger.warning(
'This version of ipwb is outdated. ' +
'Please run:\n\n' +
' pip install --upgrade ipwb\n\n'
'* Latest version: %s\n' +
'* Installed version: %s',
latest, current
)