Compare commits

...
31 Commits
Author SHA1 Message Date
hackrush ba8bd627a8 return cached resolve result for 1 block 2019-01-05 00:29:19 +05:30
hackrush e6528963ad Actually get the certificate_id 2018-12-25 12:16:06 +05:30
Lex Berezhny 6aa709e34e v0.30.3 2018-12-21 18:45:34 -05:00
Lex Berezhny e73f121c08 v0.30.3rc1 2018-12-19 09:12:56 -05:00
Victor Shyba 3b9d6c4f8e Instantiate resolver before the request to hold the selected height 2018-12-19 09:04:30 -05:00
Alyssa Callahan 69b60c19c3 Merge pull request #1712 from lbryio/readme-update
Update README.md
2018-12-17 10:47:29 -05:00
Lex Berezhny 04278cb1ab release script automatically figures out prerelease status 2018-12-14 22:25:06 -05:00
Lex Berezhny e8dec5b440 v0.30.2 2018-12-14 21:50:48 -05:00
Lex Berezhny 75f82b107e updated release script with unittests and ability to go from rc to final release 2018-12-14 21:50:30 -05:00
Jack Robison 0e90c4b611 Merge pull request #1717 from lbryio/fix-directory-args
fix directory cli args and update help message
2018-12-14 17:09:15 -05:00
Jack Robison fb66b68bc8 fix directory cli args, update help message 2018-12-14 15:51:11 -05:00
Victor Shyba c601677386 run schema unit tests on travis 2018-12-14 09:21:31 -05:00
Lex Berezhny 1fbd1cd04e v0.30.2rc2 2018-12-12 19:52:11 -05:00
Jack Robison 4a71b91fbf Merge pull request #1671 from lbryio/remove-android-helpers
remove `lbrynet.androidhelpers` module
2018-12-12 18:35:31 -05:00
Jack Robison b8b0d8b1ac refactor default directory setup, remove lbrynet.androidhelpers
fixes https://github.com/lbryio/lbry/issues/1606
2018-12-12 17:46:10 -05:00
Jack Robison 8ef73d3985 update docs 2018-12-12 12:19:26 -05:00
Jack Robison 05e556a5e3 fix generate_json_api script 2018-12-12 12:18:32 -05:00
Lex Berezhny d1da42bea8 Update README.md
* updated description and added bullet points for main features of this SDK
* lex (@eukreign ) is the official product owner of lbrysdk
2018-12-12 11:47:28 -05:00
Lex Berezhny 90685e8357 deploy release for tags 2018-12-12 00:10:50 -05:00
Lex Berezhny a471d5d167 v0.30.2rc1 2018-12-11 23:44:02 -05:00
Lex Berezhny 16122299e4 revert version back 0.30.1 2018-12-11 23:39:08 -05:00
Lex Berezhny 9f18da4bae release script (#1697)
* travis deploying to github
* release script
2018-12-11 23:24:19 -05:00
Lex Berezhny 1abce52867 v0.30.2rc1 2018-12-11 23:09:31 -05:00
Lex Berezhny 072e2b65d3 revert version change 2018-12-11 22:31:45 -05:00
Lex Berezhny f6d11e5467 0.30.1rc1 2018-12-11 22:29:40 -05:00
Oleg Silkin 458bddcb65 Removes Faker from Dependencies (#1687)
* Removes faker import and its usage
* Replaces data generated with faker with static data
* Drops faker as a dependency & removes extras require section
* Removes installation instruction for the test dependencies in setup.py
2018-12-11 20:19:58 -05:00
Victor Shyba 5fad43ff69 fix test tear down and unify test_commands 2018-12-11 16:34:37 -05:00
Victor Shyba 6992d0d947 add new test to tox.ini 2018-12-11 16:34:37 -05:00
Victor Shyba d1b0180437 add tests for claim_list_by_channel 2018-12-11 16:34:37 -05:00
Victor Shyba ba59e126cd forward errors outside of uris on channel listing 2018-12-11 16:34:37 -05:00
Victor Shyba 4e3467bb7e fix windows release type set script 2018-12-11 16:30:35 -05:00
32 changed files with 1132 additions and 516 deletions

No files matched your search

+21 -2
View File
@@ -25,7 +25,7 @@ jobs:
- pip install -e .[test]
script:
- HOME=/tmp coverage run -p --source=lbrynet -m unittest discover -v tests.unit.wallet
- HOME=/tmp coverage run -p --source=lbrynet -m twisted.trial --reactor=asyncio tests.unit.analytics tests.unit.components tests.unit.core tests.unit.cryptstream tests.unit.database tests.unit.dht tests.unit.lbryfilemanager tests.unit.lbrynet_daemon tests.unit.test_cli tests.unit.test_customLogger
- HOME=/tmp coverage run -p --source=lbrynet -m twisted.trial --reactor=asyncio tests.unit.analytics tests.unit.components tests.unit.core tests.unit.cryptstream tests.unit.database tests.unit.dht tests.unit.lbryfilemanager tests.unit.lbrynet_daemon tests.unit.test_cli tests.unit.test_customLogger tests.unit.schema
after_success:
- coverage combine
- bash <(curl -s https://codecov.io/bash)
@@ -51,8 +51,18 @@ jobs:
install:
- docker pull lbry/pyinstaller34_32bits:py371
script:
- python scripts/set_build.py
- docker run -v "$(pwd):/src/lbry" lbry/pyinstaller34_32bits:py371 lbry/scripts/wine_build.sh
- sudo zip -j dist/lbrynet-windows.zip dist/lbrynet.exe
deploy:
provider: releases
api_key: $GITHUB_OAUTH_TOKEN
file: dist/lbrynet-windows.zip
skip_cleanup: true
overwrite: true
draft: true
on:
tags: true
addons:
artifacts:
working_dir: dist
@@ -63,6 +73,7 @@ jobs:
- &build
name: "Linux"
env: OS=linux
install:
- pip3 install pyinstaller
- pip3 install git+https://github.com/lbryio/torba.git
@@ -73,7 +84,15 @@ jobs:
- chmod +x dist/lbrynet
- zip -j dist/lbrynet-${OS}.zip dist/lbrynet
- ./dist/lbrynet --version
env: OS=linux
deploy:
provider: releases
api_key: $GITHUB_OAUTH_TOKEN
file: dist/lbrynet-${OS}.zip
skip_cleanup: true
overwrite: true
draft: true
on:
tags: true
addons:
artifacts:
working_dir: dist
+1 -1
View File
@@ -57,7 +57,7 @@ To install:
python --version # Python 2 is not supported. Make sure you're on Python 3.7
pip install --editable .[test] # [test] installs extras needed for running the tests
pip install -e .
```
To verify your installation, `which lbrynet` should return a path inside of the `lbry-venv` folder created by the `virtualenv` command.
+11 -4
View File
@@ -1,8 +1,15 @@
# <img src="https://raw.githubusercontent.com/lbryio/lbry/master/lbry.png" alt="LBRY" width="48" height="36" /> LBRY [![Build Status](https://travis-ci.org/lbryio/lbry.svg?branch=master)](https://travis-ci.org/lbryio/lbry) [![Test Coverage](https://codecov.io/gh/lbryio/lbry/branch/master/graph/badge.svg)](https://codecov.io/gh/lbryio/lbry)
# <img src="https://raw.githubusercontent.com/lbryio/lbry/master/lbry.png" alt="LBRY" width="48" height="36" /> LBRY SDK [![Build Status](https://travis-ci.org/lbryio/lbry.svg?branch=master)](https://travis-ci.org/lbryio/lbry) [![Test Coverage](https://codecov.io/gh/lbryio/lbry/branch/master/graph/badge.svg)](https://codecov.io/gh/lbryio/lbry)
LBRY is an open-source protocol providing distribution, discovery, and purchase of digital content (data) via a decentralized peer-to-peer network. It utilizes the [LBRY blockchain](https://github.com/lbryio/lbrycrd) as a global namespace and database of digital content. Blockchain entries contain searchable content metadata, identities, rights and access rules. LBRY also provides a data network that consists of peers (seeders) uploading and downloading data from other peers, possibly in exchange for payments, as well as a distributed hash table used by peers to discover other peers.
LBRY is a decentralized peer-to-peer network providing distribution, discovery, and purchase of digital content (data). It utilizes the [LBRY blockchain](https://github.com/lbryio/lbrycrd) as a global namespace and database of digital content. Blockchain entries contain searchable content metadata, identities, rights and access rules. LBRY also provides a data network that consists of peers (seeders) uploading and downloading data from other peers, possibly in exchange for payments, as well as a distributed hash table used by peers to discover other peers.
This project provides an SDK for building applications using the LBRY protocol. The SDK is written in Python 3.7+ using Twisted. For other languages or platforms, a JSON-RPC API is provided.
LBRY SDK for Python is currently the most full featured implementation of the LBRY Network protocols and includes many useful components and tools for building decentralized applications. Primary features and components:
* Built on Python 3.7+ and `asyncio`.
* DHT (Distributed Hash Table) implementation for finding peers ([lbrynet.dht](https://github.com/lbryio/lbry/tree/master/lbrynet/dht)).
* Blob exchange protocol for downloading content and negotiating payments ([lbrynet.blob_exchange](https://github.com/lbryio/lbry/tree/master/lbrynet/blob_exchange)).
* Protobuf schema for encoding and decoding metadata stored on the blockchain ([lbrynet.schema](https://github.com/lbryio/lbry/tree/master/lbrynet/schema)).
* Wallet implementation for the LBRY blockchain ([lbrynet.extras.wallet](https://github.com/lbryio/lbry/tree/master/lbrynet/extras/wallet)).
* Daemon with a JSON-RPC API to ease building end user applications in any language and for automating various tasks ([lbrynet.extras.daemon](https://github.com/lbryio/lbry/tree/master/lbrynet/extras/daemon)).
## Installation
@@ -38,7 +45,7 @@ We take security seriously. Please contact security@lbry.io regarding any securi
## Contact
The primary contact for this project is [@jackrobison](mailto:jack@lbry.io).
The primary contact for this project is [@eukreign](mailto:lex@lbry.io).
## Additional information and links
+147 -61
View File
@@ -43,19 +43,13 @@
{
"name": "account_id",
"type": "str",
"description": "If provided only the balance for this account will be given",
"description": "If provided only the balance for this account will be given. Otherwise default account.",
"is_required": false
},
{
"name": "address",
"type": "str",
"description": "If provided only the balance for this address will be given",
"is_required": false
},
{
"name": "include_unconfirmed",
"type": "bool",
"description": "Include unconfirmed",
"name": "confirmations",
"type": "int",
"description": "Only include transactions with this many confirmed blocks.",
"is_required": false
}
],
@@ -83,18 +77,25 @@
{
"name": "account_decrypt",
"description": "Decrypt an encrypted account, this will remove the wallet password",
"arguments": [],
"arguments": [
{
"name": "account_id",
"type": "str",
"description": "id for the account to decrypt",
"is_required": false
}
],
"returns": "(bool) true if wallet is decrypted, otherwise false"
},
{
"name": "account_encrypt",
"description": "Encrypt a wallet with a password, if the wallet is already encrypted this will update\nthe password",
"description": "Encrypt an unencrypted account with a password",
"arguments": [
{
"name": "new_password",
"name": "account_id",
"type": "str",
"description": "password string to be used for encrypting wallet",
"is_required": true
"description": "id for the account to encrypt",
"is_required": false
}
],
"returns": "(bool) true if wallet is decrypted, otherwise false"
@@ -107,13 +108,13 @@
"name": "to_account",
"type": "str",
"description": "send to this account",
"is_required": true
"is_required": false
},
{
"name": "from_account",
"type": "str",
"description": "spend from this account",
"is_required": true
"is_required": false
},
{
"name": "amount",
@@ -155,13 +156,7 @@
{
"name": "confirmations",
"type": "int",
"description": "required confirmations (default: 6)",
"is_required": false
},
{
"name": "include_reserved",
"type": "bool",
"description": "include reserved UTXOs (default: false)",
"description": "required confirmations (default: 0)",
"is_required": false
},
{
@@ -179,6 +174,19 @@
],
"returns": "(map) balance of account(s)"
},
{
"name": "account_lock",
"description": "Lock an unlocked account",
"arguments": [
{
"name": "account_id",
"type": "str",
"description": "id for the account to lock",
"is_required": false
}
],
"returns": "(bool) true if account is locked, otherwise false"
},
{
"name": "account_max_address_gap",
"description": "Finds ranges of consecutive addresses that are unused and returns the length\nof the longest such range: for change and receiving address chains. This is\nuseful to figure out ideal values to set for 'receiving_gap' and 'change_gap'\naccount settings.",
@@ -205,6 +213,25 @@
],
"returns": "(map) details of removed account"
},
{
"name": "account_send",
"description": "Send the same number of credits to multiple addresses.",
"arguments": [
{
"name": "account_id",
"type": "str",
"description": "account to fund the transaction",
"is_required": false
},
{
"name": "broadcast",
"type": "bool",
"description": "actually broadcast the transaction, default: false.",
"is_required": false
}
],
"returns": ""
},
{
"name": "account_set",
"description": "Change various settings on an account.",
@@ -259,10 +286,10 @@
"description": "Unlock an encrypted account",
"arguments": [
{
"name": "password",
"name": "account_id",
"type": "str",
"description": "password for unlocking wallet",
"is_required": true
"description": "id for the account to unlock",
"is_required": false
}
],
"returns": "(bool) true if account is unlocked, otherwise false"
@@ -295,23 +322,22 @@
"type": "str",
"description": "id of the account to use",
"is_required": false
},
{
"name": "page",
"type": "int",
"description": "page to return during paginating",
"is_required": false
},
{
"name": "page_size",
"type": "int",
"description": "number of items on page during pagination",
"is_required": false
}
],
"returns": "List of wallet addresses"
},
{
"name": "address_public_key",
"description": "Get public key from wallet address",
"arguments": [
{
"name": "address",
"type": "str",
"description": "address for which to get the public key",
"is_required": true
}
],
"returns": "(list) list of public keys associated with address.\n Could contain more than one public key if multisig."
},
{
"name": "address_unused",
"description": "Return an address containing no balance, will create\na new address if there is none.",
@@ -535,7 +561,26 @@
{
"name": "channel_list",
"description": "Get certificate claim infos for channels that can be published to",
"arguments": [],
"arguments": [
{
"name": "account_id",
"type": "str",
"description": "id of the account to use",
"is_required": false
},
{
"name": "page",
"type": "int",
"description": "page to return during paginating",
"is_required": false
},
{
"name": "page_size",
"type": "int",
"description": "number of items on page during pagination",
"is_required": false
}
],
"returns": "(list) ClaimDict, includes 'is_mine' field to indicate if the certificate claim\n is in the wallet."
},
{
@@ -553,6 +598,12 @@
"type": "decimal",
"description": "bid amount on the channel",
"is_required": true
},
{
"name": "account_id",
"type": "str",
"description": "id of the account to store channel",
"is_required": false
}
],
"returns": "(dict) Dictionary containing result of the claim\n {\n 'tx' : (str) hex encoded transaction\n 'txid' : (str) txid of resulting claim\n 'nout' : (int) nout of the resulting claim\n 'fee' : (float) fee paid for the claim transaction\n 'claim_id' : (str) claim ID of the resulting claim\n }"
@@ -584,6 +635,12 @@
"type": "str",
"description": "id of the account to use",
"is_required": false
},
{
"name": "blocking",
"type": "bool",
"description": "wait until abandon is in mempool",
"is_required": false
}
],
"returns": "(dict) Dictionary containing result of the claim\n {\n success: (bool) True if txn is successful\n txid : (str) txid of resulting transaction\n }"
@@ -641,6 +698,18 @@
"type": "str",
"description": "id of the account to query",
"is_required": false
},
{
"name": "page",
"type": "int",
"description": "page to return during paginating",
"is_required": false
},
{
"name": "page_size",
"type": "int",
"description": "number of items on page during pagination",
"is_required": false
}
],
"returns": "(list) List of name claims owned by user\n [\n {\n 'address': (str) address that owns the claim\n 'amount': (float) amount assigned to the claim\n 'blocks_to_expiration': (int) number of blocks until it expires\n 'category': (str) \"claim\", \"update\" , or \"support\"\n 'claim_id': (str) claim ID of the claim\n 'confirmations': (int) number of blocks of confirmations for the claim\n 'expiration_height': (int) the block height which the claim will expire\n 'expired': (bool) true if expired, false otherwise\n 'height': (int) height of the block containing the claim\n 'is_spent': (bool) true if claim is abandoned, false otherwise\n 'name': (str) name of the claim\n 'permanent_url': (str) permanent url of the claim,\n 'txid': (str) txid of the claim\n 'nout': (int) nout of the claim\n 'value': (str) value of the claim\n },\n ]"
@@ -676,25 +745,6 @@
],
"returns": "(dict) Dictionary containing the transaction information\n {\n \"hex\": (str) raw transaction,\n \"inputs\": (list) inputs(dict) used for the transaction,\n \"outputs\": (list) outputs(dict) for the transaction,\n \"total_fee\": (int) fee in dewies,\n \"total_input\": (int) total of inputs in dewies,\n \"total_output\": (int) total of outputs in dewies(input - fees),\n \"txid\": (str) txid of the transaction,\n }"
},
{
"name": "claim_renew",
"description": "Renew claim(s) or support(s)",
"arguments": [
{
"name": "outpoint",
"type": "str",
"description": "outpoint of the claim to renew",
"is_required": true
},
{
"name": "height",
"type": "str",
"description": "update claims expiring before or at this block height",
"is_required": true
}
],
"returns": "(dict) Dictionary where key is the the original claim's outpoint and\n value is the result of the renewal\n {\n outpoint:{\n\n 'tx' : (str) hex encoded transaction\n 'txid' : (str) txid of resulting claim\n 'nout' : (int) nout of the resulting claim\n 'fee' : (float) fee paid for the claim transaction\n 'claim_id' : (str) claim ID of the resulting claim\n },\n }"
},
{
"name": "claim_send_to_address",
"description": "Send a name claim to an address",
@@ -1190,6 +1240,18 @@
"description": "claim id of the publisher channel, does not check for channel claim being in the wallet. This allows publishing to a channel where only the certificate private key is in the wallet.",
"is_required": false
},
{
"name": "channel_account_id",
"type": "str",
"description": "one or more account ids for accounts to look in for channel certificates, defaults to all accounts.",
"is_required": false
},
{
"name": "account_id",
"type": "str",
"description": "account to use for funding the transaction",
"is_required": false
},
{
"name": "claim_address",
"type": "str",
@@ -1363,7 +1425,7 @@
"name": "status",
"description": "Get daemon status",
"arguments": [],
"returns": "(dict) lbrynet-daemon status\n {\n 'installation_id': (str) installation id - base58,\n 'is_running': (bool),\n 'is_first_run': bool,\n 'skipped_components': (list) [names of skipped components (str)],\n 'startup_status': { Does not include components which have been skipped\n 'database': (bool),\n 'wallet': (bool),\n 'session': (bool),\n 'dht': (bool),\n 'hash_announcer': (bool),\n 'stream_identifier': (bool),\n 'file_manager': (bool),\n 'blob_manager': (bool),\n 'blockchain_headers': (bool),\n 'peer_protocol_server': (bool),\n 'reflector': (bool),\n 'upnp': (bool),\n 'exchange_rate_manager': (bool),\n },\n 'connection_status': {\n 'code': (str) connection status code,\n 'message': (str) connection status message\n },\n 'blockchain_headers': {\n 'downloading_headers': (bool),\n 'download_progress': (float) 0-100.0\n },\n 'wallet': {\n 'blocks': (int) local blockchain height,\n 'blocks_behind': (int) remote_height - local_height,\n 'best_blockhash': (str) block hash of most recent block,\n 'is_encrypted': (bool),\n 'is_locked': (bool),\n },\n 'dht': {\n 'node_id': (str) lbry dht node id - hex encoded,\n 'peers_in_routing_table': (int) the number of peers in the routing table,\n },\n 'blob_manager': {\n 'finished_blobs': (int) number of finished blobs in the blob manager,\n },\n 'hash_announcer': {\n 'announce_queue_size': (int) number of blobs currently queued to be announced\n },\n 'file_manager': {\n 'managed_files': (int) count of files in the file manager,\n }\n }"
"returns": "(dict) lbrynet-daemon status\n {\n 'installation_id': (str) installation id - base58,\n 'is_running': (bool),\n 'is_first_run': bool,\n 'skipped_components': (list) [names of skipped components (str)],\n 'startup_status': { Does not include components which have been skipped\n 'database': (bool),\n 'wallet': (bool),\n 'session': (bool),\n 'dht': (bool),\n 'hash_announcer': (bool),\n 'stream_identifier': (bool),\n 'file_manager': (bool),\n 'blob_manager': (bool),\n 'blockchain_headers': (bool),\n 'peer_protocol_server': (bool),\n 'reflector': (bool),\n 'upnp': (bool),\n 'exchange_rate_manager': (bool),\n },\n 'connection_status': {\n 'code': (str) connection status code,\n 'message': (str) connection status message\n },\n 'blockchain_headers': {\n 'downloading_headers': (bool),\n 'download_progress': (float) 0-100.0\n },\n 'wallet': {\n 'blocks': (int) local blockchain height,\n 'blocks_behind': (int) remote_height - local_height,\n 'best_blockhash': (str) block hash of most recent block,\n 'is_encrypted': (bool),\n 'is_locked': (bool),\n },\n 'dht': {\n 'node_id': (str) lbry dht node id - hex encoded,\n 'peers_in_routing_table': (int) the number of peers in the routing table,\n },\n 'blob_manager': {\n 'finished_blobs': (int) number of finished blobs in the blob manager,\n },\n 'hash_announcer': {\n 'announce_queue_size': (int) number of blobs currently queued to be announced\n },\n 'file_manager': {\n 'managed_files': (int) count of files in the file manager,\n },\n 'upnp': {\n 'aioupnp_version': (str),\n 'redirects': {\n <TCP | UDP>: (int) external_port,\n },\n 'gateway': (str) manufacturer and model,\n 'dht_redirect_set': (bool),\n 'peer_redirect_set': (bool),\n 'external_ip': (str) external ip address,\n }\n }"
},
{
"name": "stop",
@@ -1424,6 +1486,18 @@
"type": "str",
"description": "id of the account to query",
"is_required": false
},
{
"name": "page",
"type": "int",
"description": "page to return during paginating",
"is_required": false
},
{
"name": "page_size",
"type": "int",
"description": "number of items on page during pagination",
"is_required": false
}
],
"returns": "(list) List of transactions\n\n {\n \"claim_info\": (list) claim info if in txn [{\n \"address\": (str) address of claim,\n \"balance_delta\": (float) bid amount,\n \"amount\": (float) claim amount,\n \"claim_id\": (str) claim id,\n \"claim_name\": (str) claim name,\n \"nout\": (int) nout\n }],\n \"abandon_info\": (list) abandon info if in txn [{\n \"address\": (str) address of abandoned claim,\n \"balance_delta\": (float) returned amount,\n \"amount\": (float) claim amount,\n \"claim_id\": (str) claim id,\n \"claim_name\": (str) claim name,\n \"nout\": (int) nout\n }],\n \"confirmations\": (int) number of confirmations for the txn,\n \"date\": (str) date and time of txn,\n \"fee\": (float) txn fee,\n \"support_info\": (list) support info if in txn [{\n \"address\": (str) address of support,\n \"balance_delta\": (float) support amount,\n \"amount\": (float) support amount,\n \"claim_id\": (str) claim id,\n \"claim_name\": (str) claim name,\n \"is_tip\": (bool),\n \"nout\": (int) nout\n }],\n \"timestamp\": (int) timestamp,\n \"txid\": (str) txn id,\n \"update_info\": (list) update info if in txn [{\n \"address\": (str) address of claim,\n \"balance_delta\": (float) credited/debited\n \"amount\": (float) absolute amount,\n \"claim_id\": (str) claim id,\n \"claim_name\": (str) claim name,\n \"nout\": (int) nout\n }],\n \"value\": (float) value of txn\n }"
@@ -1450,6 +1524,18 @@
"type": "str",
"description": "id of the account to query",
"is_required": false
},
{
"name": "page",
"type": "int",
"description": "page to return during paginating",
"is_required": false
},
{
"name": "page_size",
"type": "int",
"description": "number of items on page during pagination",
"is_required": false
}
],
"returns": "(list) List of unspent transaction outputs (UTXOs)\n [\n {\n \"address\": (str) the output address\n \"amount\": (float) unspent amount\n \"height\": (int) block height\n \"is_claim\": (bool) is the tx a claim\n \"is_coinbase\": (bool) is the tx a coinbase tx\n \"is_support\": (bool) is the tx a support\n \"is_update\": (bool) is the tx an update\n \"nout\": (int) nout of the output\n \"txid\": (str) txid of the output\n },\n ...\n ]"
+1 -1
View File
@@ -3,7 +3,7 @@ from lbrynet.custom_logger import install_logger
__name__ = "lbrynet"
__version__ = "0.30.1"
__version__ = "0.30.3"
version = tuple(__version__.split('.'))
install_logger()
-1
View File
@@ -1 +0,0 @@
from . import paths
-26
View File
@@ -1,26 +0,0 @@
# App root files dir
# https://developer.android.com/reference/android/content/ContextWrapper.html#getFilesDir%28%29
def android_files_dir():
return None
# Base internal storage path
def android_internal_storage_dir():
return None
# Base external (SD card, if present) storage path
def android_external_storage_dir():
return None
# Internal device storage (private app folder)
# https://developer.android.com/reference/android/content/ContextWrapper.html#getExternalFilesDirs(java.lang.String)
def android_app_internal_storage_dir():
return None
# External (app folder on SD card, if present) storage
# https://developer.android.com/reference/android/content/ContextWrapper.html#getExternalFilesDirs(java.lang.String)
def android_app_external_storage_dir():
return None
+135 -114
View File
@@ -1,24 +1,15 @@
import base58
import json
import logging
import os
import re
import sys
import yaml
import typing
import json
import logging
import envparse
import base58
import yaml
from appdirs import user_data_dir, user_config_dir
from lbrynet import utils
from lbrynet.p2p.Error import InvalidCurrencyError, NoSuchDirectoryError
from lbrynet.androidhelpers.paths import (
android_internal_storage_dir,
android_app_internal_storage_dir
)
try:
from lbrynet.winpaths import get_path, FOLDERID, UserHandle
except (ImportError, ValueError, NameError):
# Android platform: NameError: name 'c_wchar' is not defined
pass
from lbrynet.p2p.Error import InvalidCurrencyError
log = logging.getLogger(__name__)
@@ -59,89 +50,68 @@ settings_encoders = {
'.yml': yaml.safe_dump
}
# set by CLI when the user specifies an alternate config file path
conf_file = None
def _get_old_directories(platform_type):
directories = {}
if platform_type == WINDOWS:
appdata = get_path(FOLDERID.RoamingAppData, UserHandle.current)
directories['data'] = os.path.join(appdata, 'lbrynet')
directories['lbryum'] = os.path.join(appdata, 'lbryum')
directories['download'] = get_path(FOLDERID.Downloads, UserHandle.current)
elif platform_type == DARWIN:
directories['data'] = user_data_dir('LBRY')
directories['lbryum'] = os.path.expanduser('~/.lbryum')
directories['download'] = os.path.expanduser('~/Downloads')
elif platform_type == LINUX:
directories['data'] = os.path.expanduser('~/.lbrynet')
directories['lbryum'] = os.path.expanduser('~/.lbryum')
directories['download'] = os.path.expanduser('~/Downloads')
else:
raise ValueError('unknown platform value')
return directories
def _get_new_directories(platform_type):
directories = {}
if platform_type == ANDROID:
directories['data'] = '%s/lbrynet' % android_app_internal_storage_dir()
directories['lbryum'] = '%s/lbryum' % android_app_internal_storage_dir()
directories['download'] = '%s/Download' % android_internal_storage_dir()
elif platform_type == WINDOWS:
directories['data'] = user_data_dir('lbrynet', 'lbry')
directories['lbryum'] = user_data_dir('lbryum', 'lbry')
directories['download'] = get_path(FOLDERID.Downloads, UserHandle.current)
elif platform_type == DARWIN:
directories = _get_old_directories(platform_type)
elif platform_type == LINUX:
directories['data'] = user_data_dir('lbry/lbrynet')
directories['lbryum'] = user_data_dir('lbry/lbryum')
try:
with open(os.path.join(user_config_dir(), 'user-dirs.dirs'), 'r') as xdg:
down_dir = re.search(r'XDG_DOWNLOAD_DIR=(.+)', xdg.read()).group(1)
down_dir = re.sub('\$HOME', os.getenv('HOME'), down_dir)
directories['download'] = re.sub('\"', '', down_dir)
except EnvironmentError:
directories['download'] = os.getenv('XDG_DOWNLOAD_DIR')
if not directories['download']:
directories['download'] = os.path.expanduser('~/Downloads')
else:
raise ValueError('unknown platform value')
return directories
if 'ANDROID_ARGUMENT' in os.environ:
# https://github.com/kivy/kivy/blob/master/kivy/utils.py#L417-L421
platform = ANDROID
dirs = _get_new_directories(ANDROID)
elif 'darwin' in sys.platform:
platform = DARWIN
dirs = _get_old_directories(DARWIN)
elif 'win' in sys.platform:
platform = WINDOWS
if os.path.isdir(_get_old_directories(WINDOWS)['data']) or \
os.path.isdir(_get_old_directories(WINDOWS)['lbryum']):
dirs = _get_old_directories(WINDOWS)
else:
dirs = _get_new_directories(WINDOWS)
else:
platform = LINUX
if os.path.isdir(_get_old_directories(LINUX)['data']) or \
os.path.isdir(_get_old_directories(LINUX)['lbryum']):
dirs = _get_old_directories(LINUX)
else:
dirs = _get_new_directories(LINUX)
default_data_dir = dirs['data']
default_lbryum_dir = dirs['lbryum']
default_download_dir = dirs['download']
ICON_PATH = 'icons' if platform is WINDOWS else 'app.icns'
def get_windows_directories() -> typing.Tuple[str, str, str]:
from lbrynet.winpaths import get_path, FOLDERID, UserHandle
download_dir = get_path(FOLDERID.Downloads, UserHandle.current)
# old
appdata = get_path(FOLDERID.RoamingAppData, UserHandle.current)
data_dir = os.path.join(appdata, 'lbrynet')
lbryum_dir = os.path.join(appdata, 'lbryum')
if os.path.isdir(data_dir) or os.path.isdir(lbryum_dir):
return data_dir, lbryum_dir, download_dir
# new
data_dir = user_data_dir('lbrynet', 'lbry')
lbryum_dir = user_data_dir('lbryum', 'lbry')
download_dir = get_path(FOLDERID.Downloads, UserHandle.current)
return data_dir, lbryum_dir, download_dir
def get_darwin_directories() -> typing.Tuple[str, str, str]:
data_dir = user_data_dir('LBRY')
lbryum_dir = os.path.expanduser('~/.lbryum')
download_dir = os.path.expanduser('~/Downloads')
return data_dir, lbryum_dir, download_dir
def get_linux_directories() -> typing.Tuple[str, str, str]:
download_dir = None
try:
with open(os.path.join(user_config_dir(), 'user-dirs.dirs'), 'r') as xdg:
down_dir = re.search(r'XDG_DOWNLOAD_DIR=(.+)', xdg.read()).group(1)
down_dir = re.sub('\$HOME', os.getenv('HOME'), down_dir)
download_dir = re.sub('\"', '', down_dir)
except EnvironmentError:
download_dir = os.getenv('XDG_DOWNLOAD_DIR')
if not download_dir:
download_dir = os.path.expanduser('~/Downloads')
# old
data_dir = os.path.expanduser('~/.lbrynet')
lbryum_dir = os.path.expanduser('~/.lbryum')
if os.path.isdir(data_dir) or os.path.isdir(lbryum_dir):
return data_dir, lbryum_dir, download_dir
# new
return user_data_dir('lbry/lbrynet'), user_data_dir('lbry/lbryum'), download_dir
def server_port(server_and_port):
server, port = server_and_port.split(':')
return server, int(port)
@@ -226,6 +196,11 @@ FIXED_SETTINGS = {
}
ADJUSTABLE_SETTINGS = {
'data_dir': (str, ''), # these blank defaults will be updated to OS specific defaults
'wallet_dir': (str, ''),
'lbryum_wallet_dir': (str, ''), # to be deprecated
'download_directory': (str, ''),
# By default, daemon will block all cross origin requests
# but if this is set, this value will be used for the
# Access-Control-Allow-Origin. For example
@@ -244,18 +219,15 @@ ADJUSTABLE_SETTINGS = {
# will not be made automatically)
'auto_renew_claim_height_delta': (int, 0),
'cache_time': (int, 150),
'data_dir': (str, default_data_dir),
'data_rate': (float, .0001), # points/megabyte
'delete_blobs_on_remove': (bool, True),
'dht_node_port': (int, 4444),
'download_directory': (str, default_download_dir),
'download_timeout': (int, 180),
'download_mirrors': (list, ['blobs.lbry.io']),
'is_generous_host': (bool, True),
'announce_head_blobs_only': (bool, True),
'concurrent_announcers': (int, DEFAULT_CONCURRENT_ANNOUNCERS),
'known_dht_nodes': (list, DEFAULT_DHT_NODES, server_list, server_list_reverse),
'lbryum_wallet_dir': (str, default_lbryum_dir),
'max_connections_per_stream': (int, 5),
'seek_head_blob_first': (bool, True),
# TODO: writing json on the cmd line is a pain, come up with a nicer
@@ -290,16 +262,34 @@ ADJUSTABLE_SETTINGS = {
}
class Config:
def __init__(self, fixed_defaults, adjustable_defaults, persisted_settings=None,
environment=None, cli_settings=None):
optional_str = typing.Optional[str]
class Config:
def __init__(self, fixed_defaults, adjustable_defaults: typing.Dict, persisted_settings=None, environment=None,
cli_settings=None, data_dir: optional_str = None, wallet_dir: optional_str = None,
download_dir: optional_str = None, file_name: optional_str = None):
self._installation_id = None
self._session_id = base58.b58encode(utils.generate_id()).decode()
self._node_id = None
self._fixed_defaults = fixed_defaults
self._adjustable_defaults = adjustable_defaults
# copy the default adjustable settings
self._adjustable_defaults = {k: v for k, v in adjustable_defaults.items()}
# set the os specific default directories
if platform is WINDOWS:
self.default_data_dir, self.default_wallet_dir, self.default_download_dir = get_windows_directories()
elif platform is DARWIN:
self.default_data_dir, self.default_wallet_dir, self.default_download_dir = get_darwin_directories()
elif platform is LINUX:
self.default_data_dir, self.default_wallet_dir, self.default_download_dir = get_linux_directories()
else:
assert None not in [data_dir, wallet_dir, download_dir]
self.default_data_dir = data_dir
self.default_wallet_dir = wallet_dir
self.default_download_dir = download_dir
self._data = {
TYPE_DEFAULT: {}, # defaults
@@ -336,6 +326,31 @@ class Config:
cli_settings = {}
self._validate_settings(cli_settings)
self._data[TYPE_CLI].update(cli_settings)
self.file_name = file_name or 'daemon_settings.yml'
@property
def data_dir(self) -> optional_str:
data_dir = self.get('data_dir')
if not data_dir:
return
return os.path.expanduser(os.path.expandvars(data_dir))
@property
def download_dir(self) -> optional_str:
download_dir = self.get('download_directory')
if not download_dir:
return
return os.path.expanduser(os.path.expandvars(download_dir))
@property
def wallet_dir(self) -> optional_str:
if self.get('lbryum_wallet_dir') and not self.get('wallet_dir'):
log.warning("'lbryum_wallet_dir' setting will be deprecated, please update to 'wallet_dir'")
self['wallet_dir'] = self['lbryum_wallet_dir']
wallet_dir = self.get('wallet_dir')
if not wallet_dir:
return
return os.path.expanduser(os.path.expandvars(wallet_dir))
def __repr__(self):
return self.get_current_settings_dict().__repr__()
@@ -395,7 +410,7 @@ class Config:
elif name == "download_directory":
directory = str(value)
if not os.path.exists(directory):
raise NoSuchDirectoryError(directory)
log.warning("download directory '%s' does not exist", directory)
def is_default(self, name):
"""Check if a config value is wasn't specified by the user
@@ -483,16 +498,15 @@ class Config:
}
def save_conf_file_settings(self):
path = conf_file or self.get_valid_settings_filename()
# reverse the conversions done after loading the settings from the conf
# file
rev = self._convert_conf_file_lists_reverse(self._data[TYPE_PERSISTED])
ext = os.path.splitext(path)[1]
ext = os.path.splitext(self.file_name)[1]
encoder = settings_encoders.get(ext, False)
if not encoder:
raise ValueError('Unknown settings format: {}. Available formats: {}'
.format(ext, list(settings_encoders.keys())))
with open(path, 'w') as settings_file:
with open(os.path.join(self.data_dir, self.file_name), 'w') as settings_file:
settings_file.write(encoder(rev))
@staticmethod
@@ -520,14 +534,18 @@ class Config:
settings.node_id = settings.get_node_id()
def load_conf_file_settings(self):
path = conf_file or self.get_valid_settings_filename()
self._read_conf_file(path)
path = os.path.join(self.data_dir or self.default_data_dir, self.file_name)
if os.path.isfile(path):
self._read_conf_file(path)
self['data_dir'] = self.data_dir or self.default_data_dir
self['download_directory'] = self.download_dir or self.default_download_dir
self['wallet_dir'] = self.wallet_dir or self.default_wallet_dir
# initialize members depending on config file
self.initialize_post_conf_load()
def _read_conf_file(self, path):
if not path or not os.path.exists(path):
return
raise FileNotFoundError(path)
ext = os.path.splitext(path)[1]
decoder = settings_decoders.get(ext, False)
if not decoder:
@@ -562,13 +580,15 @@ class Config:
# although there is a risk of a race condition here we don't
# expect there to be multiple processes accessing this
# directory so the risk can be ignored
if not os.path.isdir(self['data_dir']):
os.makedirs(self['data_dir'])
return self['data_dir']
if not os.path.isdir(self.data_dir):
os.makedirs(self.data_dir)
if not os.path.isdir(os.path.join(self.data_dir, "blobfiles")):
os.makedirs(os.path.join(self.data_dir, "blobfiles"))
return self.data_dir
def ensure_wallet_dir(self):
if not os.path.isdir(self['lbryum_wallet_dir']):
os.makedirs(self['lbryum_wallet_dir'])
if not os.path.isdir(self.wallet_dir):
os.makedirs(self.wallet_dir)
def get_log_filename(self):
"""
@@ -589,13 +609,6 @@ class Config:
def get_db_revision_filename(self):
return os.path.join(self.ensure_data_dir(), self['DB_REVISION_FILE_NAME'])
def get_valid_settings_filename(self):
data_dir = self.ensure_data_dir()
json_path = os.path.join(data_dir, 'daemon_settings.json')
if os.path.isfile(json_path):
return json_path
return os.path.join(data_dir, 'daemon_settings.yml')
def get_installation_id(self):
install_id_filename = os.path.join(self.ensure_data_dir(), "install_id")
if not self._installation_id:
@@ -624,7 +637,7 @@ class Config:
return self._session_id
settings = None # type: Config
settings: Config = None
def get_default_env():
@@ -639,10 +652,18 @@ def get_default_env():
return Env(**env_defaults)
def initialize_settings(load_conf_file=True):
def initialize_settings(load_conf_file: typing.Optional[bool] = True,
data_dir: optional_str = None, wallet_dir: optional_str = None,
download_dir: optional_str = None):
global settings
if settings is None:
settings = Config(FIXED_SETTINGS, ADJUSTABLE_SETTINGS,
environment=get_default_env())
environment=get_default_env(), data_dir=data_dir, wallet_dir=wallet_dir,
download_dir=download_dir)
if load_conf_file:
settings.load_conf_file_settings()
settings['data_dir'] = settings.data_dir or settings.default_data_dir
settings['download_directory'] = settings.download_dir or settings.default_download_dir
settings['wallet_dir'] = settings.wallet_dir or settings.default_wallet_dir
settings.ensure_data_dir()
settings.ensure_wallet_dir()
+135 -27
View File
@@ -1,4 +1,16 @@
import sys
import os
import json
import asyncio
import argparse
import typing
# Set SSL_CERT_FILE env variable for Twisted SSL verification on Windows
# This needs to happen before anything else
if 'win' in sys.platform:
import certifi
os.environ['SSL_CERT_FILE'] = certifi.where()
from twisted.internet import asyncioreactor
if 'twisted.internet.reactor' not in sys.modules:
asyncioreactor.install()
@@ -10,28 +22,93 @@ else:
# https://github.com/kivy/kivy/issues/4182
del sys.modules['twisted.internet.reactor']
asyncioreactor.install()
from twisted.internet import reactor
import json
import asyncio
from twisted.internet import reactor
import logging
from aiohttp.client_exceptions import ClientConnectorError
from requests.exceptions import ConnectionError
from docopt import docopt
from textwrap import dedent
from lbrynet import __name__ as lbrynet_name
from lbrynet import conf, log_support, __name__ as lbrynet_name
from lbrynet.utils import check_connection, json_dumps_pretty
from lbrynet.extras.daemon.Daemon import Daemon
from lbrynet.extras.daemon.DaemonControl import start as daemon_main
from lbrynet.extras.daemon.DaemonConsole import main as daemon_console
from lbrynet.extras.daemon.auth.client import LBRYAPIClient
from lbrynet.extras.system_info import get_platform
log = logging.getLogger(lbrynet_name)
async def execute_command(method, params, conf_path=None):
optional_path_getter_type = typing.Optional[typing.Callable[[], str]]
def start_daemon(settings: typing.Optional[typing.Dict] = None,
console_output: typing.Optional[bool] = True, verbose: typing.Optional[typing.List[str]] = None,
data_dir: typing.Optional[str] = None, wallet_dir: typing.Optional[str] = None,
download_dir: typing.Optional[str] = None):
settings = settings or {}
conf.initialize_settings(data_dir=data_dir, wallet_dir=wallet_dir, download_dir=download_dir)
for k, v in settings.items():
conf.settings.update({k, v}, data_types=(conf.TYPE_CLI,))
log_support.configure_logging(conf.settings.get_log_filename(), console_output, verbose)
log_support.configure_loggly_handler()
log.debug('Final Settings: %s', conf.settings.get_current_settings_dict())
log.info("Starting lbrynet-daemon from command line")
if check_connection():
daemon = Daemon()
daemon.start_listening()
reactor.run()
else:
log.info("Not connected to internet, unable to start")
def start_daemon_with_cli_args(argv=None, data_dir: typing.Optional[str] = None,
wallet_dir: typing.Optional[str] = None, download_dir: typing.Optional[str] = None):
parser = argparse.ArgumentParser()
parser.add_argument(
"--http-auth", dest="useauth", action="store_true", default=False
)
parser.add_argument(
'--quiet', dest='quiet', action="store_true",
help='Disable all console output.'
)
parser.add_argument(
'--verbose', nargs="*",
help=('Enable debug output. Optionally specify loggers for which debug output '
'should selectively be applied.')
)
parser.add_argument(
'--version', action="store_true",
help='Show daemon version and quit'
)
args = parser.parse_args(argv)
settings = {}
if args.useauth:
settings['use_auth_http'] = True
verbose = None
if args.verbose:
verbose = args.verbose
console_output = not args.quiet
if args.version:
print(json_dumps_pretty(get_platform()))
return
return start_daemon(settings, console_output, verbose, data_dir, wallet_dir, download_dir)
async def execute_command(method, params, data_dir: typing.Optional[str] = None,
wallet_dir: typing.Optional[str] = None, download_dir: typing.Optional[str] = None):
# this check if the daemon is running or not
conf.initialize_settings(data_dir=data_dir, wallet_dir=wallet_dir, download_dir=download_dir)
api = None
try:
api = await LBRYAPIClient.get_client(conf_path)
api = await LBRYAPIClient.get_client()
await api.status()
except (ClientConnectorError, ConnectionError):
if api:
@@ -58,16 +135,26 @@ def print_help():
lbrynet - LBRY command line client.
USAGE
lbrynet [--conf <config file>] <command> [<args>]
lbrynet [--data_dir=<blob and database directory>] [--wallet_dir=<wallet directory>]
[--download_dir=<downloads directory>] <command> [<args>]
EXAMPLES
lbrynet start # starts the daemon. The daemon needs to be running for commands to work
lbrynet help # display this message
lbrynet help <command_name> # get help for a command(doesn't need the daemon to be running)
lbrynet commands # list available commands
lbrynet status # get the running status of the daemon
lbrynet --conf ~/l1.conf # use ~/l1.conf as config file
lbrynet resolve what # resolve a name
lbrynet start # starts the daemon and listens for jsonrpc commands
lbrynet help # display this message
lbrynet help <command_name> # get help for a command(doesn't need the daemon to be running)
lbrynet commands # list available commands
lbrynet status # get the running status of the daemon
lbrynet resolve what # resolve a name
lbrynet --wallet_dir=~/wallet2 start # start the daemon using an alternative wallet directory
lbrynet --data_dir=~/lbry start # start the daemon using an alternative data directory
lbrynet --data_dir=~/lbry <command_name> # run a command on a daemon using an alternative data directory,
# which can contain a full daemon_settings.yml config file.
# Note: since the daemon is what runs the wallet and
# downloads files, only the --data_dir setting is needed when
# running commands. The wallet_dir and download_dir would only
# by used when starting the daemon.
"""))
@@ -119,15 +206,36 @@ def main(argv=None):
print_help()
return 1
conf_path = None
if len(argv) and argv[0] == "--conf":
if len(argv) < 2:
print("No config file specified for --conf option")
print_help()
return 1
dir_args = {}
if len(argv) > 2:
dir_arg_keys = [
'data_dir',
'wallet_dir',
'download_directory'
]
conf_path = argv[1]
argv = argv[2:]
for arg in argv:
found_dir_arg = False
for key in dir_arg_keys:
if arg.startswith(f'--{key}='):
if key in dir_args:
print(f"Multiple values provided for '{key}' argument")
print_help()
return 1
dir_args[key] = os.path.expanduser(os.path.expandvars(arg.lstrip(f'--{key}=')))
found_dir_arg = True
if not found_dir_arg:
break
argv = argv[len(dir_args):]
data_dir = dir_args.get('data_dir')
wallet_dir = dir_args.get('wallet_dir')
download_dir = dir_args.get('download_directory')
for k, v in dir_args.items():
if not os.path.isdir(v):
print(f"'{data_dir}' is not a directory, cannot use it for {k}")
return 1
method, args = argv[0], argv[1:]
@@ -145,7 +253,7 @@ def main(argv=None):
return 0
elif method == 'start':
sys.exit(daemon_main(args, conf_path))
sys.exit(start_daemon_with_cli_args(args, data_dir, wallet_dir, download_dir))
elif method == 'console':
sys.exit(daemon_console())
@@ -167,7 +275,7 @@ def main(argv=None):
parsed = docopt(fn.__doc__, args)
params = set_kwargs(parsed)
loop = asyncio.get_event_loop()
loop.run_until_complete(execute_command(method, params, conf_path))
loop.run_until_complete(execute_command(method, params, data_dir, wallet_dir, download_dir))
return 0
+34 -90
View File
@@ -59,62 +59,18 @@ def from_future(coroutine: asyncio.coroutine) -> defer.Deferred:
return defer.Deferred.fromFuture(asyncio.ensure_future(coroutine))
def get_wallet_config():
wallet_type = GCS('wallet')
if wallet_type == conf.LBRYCRD_WALLET:
raise ValueError('LBRYcrd Wallet is no longer supported')
elif wallet_type != conf.LBRYUM_WALLET:
raise ValueError(f'Wallet Type {wallet_type} is not valid')
lbryum_servers = {address: {'t': str(port)}
for address, port in GCS('lbryum_servers')}
config = {
'auto_connect': True,
'chain': GCS('blockchain_name'),
'default_servers': lbryum_servers
}
if 'use_keyring' in conf.settings:
config['use_keyring'] = GCS('use_keyring')
if conf.settings['lbryum_wallet_dir']:
config['lbryum_path'] = GCS('lbryum_wallet_dir')
return config
class ConfigSettings:
@staticmethod
def get_conf_setting(setting_name):
return conf.settings[setting_name]
@staticmethod
def get_blobfiles_dir():
if conf.settings['BLOBFILES_DIR'] == "blobfiles":
return os.path.join(GCS("data_dir"), "blobfiles")
else:
log.info("Using non-default blobfiles directory: %s", conf.settings['BLOBFILES_DIR'])
return conf.settings['BLOBFILES_DIR']
@staticmethod
def get_node_id():
return conf.settings.node_id
@staticmethod
@defer.inlineCallbacks
def get_external_ip(): # used if upnp is disabled or non-functioning
try:
buf = []
response = yield treq.get("https://api.lbry.io/ip")
yield treq.collect(response, buf.append)
parsed = json.loads(b"".join(buf).decode())
if parsed['success']:
return parsed['data']['ip']
return
except Exception as err:
return
# Shorthand for common ConfigSettings methods
CS = ConfigSettings
GCS = ConfigSettings.get_conf_setting
@defer.inlineCallbacks
def get_external_ip(): # used if upnp is disabled or non-functioning
try:
buf = []
response = yield treq.get("https://api.lbry.io/ip")
yield treq.collect(response, buf.append)
parsed = json.loads(b"".join(buf).decode())
if parsed['success']:
return parsed['data']['ip']
return
except Exception as err:
return
class DatabaseComponent(Component):
@@ -130,7 +86,7 @@ class DatabaseComponent(Component):
@staticmethod
def get_current_db_revision():
return 9
return 10
@staticmethod
def get_revision_filename():
@@ -146,18 +102,6 @@ class DatabaseComponent(Component):
# check directories exist, create them if they don't
log.info("Loading databases")
if not os.path.exists(GCS('download_directory')):
os.mkdir(GCS('download_directory'))
if not os.path.exists(GCS('data_dir')):
os.mkdir(GCS('data_dir'))
self._write_db_revision_file(self.get_current_db_revision())
log.debug("Created the db revision file: %s", self.get_revision_filename())
if not os.path.exists(CS.get_blobfiles_dir()):
os.mkdir(CS.get_blobfiles_dir())
log.debug("Created the blobfile directory: %s", str(CS.get_blobfiles_dir()))
if not os.path.exists(self.get_revision_filename()):
log.warning("db_revision file not found. Creating it")
self._write_db_revision_file(self.get_current_db_revision())
@@ -174,13 +118,13 @@ class DatabaseComponent(Component):
from lbrynet.extras.daemon.migrator import dbmigrator
log.info("Upgrading your databases (revision %i to %i)", old_revision, self.get_current_db_revision())
yield threads.deferToThread(
dbmigrator.migrate_db, GCS('data_dir'), old_revision, self.get_current_db_revision()
dbmigrator.migrate_db, conf.settings.data_dir, old_revision, self.get_current_db_revision()
)
self._write_db_revision_file(self.get_current_db_revision())
log.info("Finished upgrading the databases.")
# start SQLiteStorage
self.storage = SQLiteStorage(GCS('data_dir'))
self.storage = SQLiteStorage(conf.settings.data_dir)
yield self.storage.setup()
@defer.inlineCallbacks
@@ -198,9 +142,9 @@ class HeadersComponent(Component):
def __init__(self, component_manager):
super().__init__(component_manager)
self.headers_dir = os.path.join(conf.settings['lbryum_wallet_dir'], 'lbc_mainnet')
self.headers_dir = os.path.join(conf.settings.wallet_dir, 'lbc_mainnet')
self.headers_file = os.path.join(self.headers_dir, 'headers')
self.old_file = os.path.join(conf.settings['lbryum_wallet_dir'], 'blockchain_headers')
self.old_file = os.path.join(conf.settings.wallet_dir, 'blockchain_headers')
self._downloading_headers = None
self._headers_progress_percent = 0
@@ -260,7 +204,7 @@ class HeadersComponent(Component):
ledger = SimpleNamespace()
ledger.config = {
'default_servers': conf.settings['lbryum_servers'],
'data_path': conf.settings['lbryum_wallet_dir']
'data_path': conf.settings.wallet_dir
}
net = Network(ledger)
first_connection = net.on_connected.first
@@ -395,7 +339,7 @@ class BlobComponent(Component):
dht_node = self.component_manager.get_component(DHT_COMPONENT)
if dht_node:
datastore = dht_node._dataStore
self.blob_manager = DiskBlobManager(CS.get_blobfiles_dir(), storage, datastore)
self.blob_manager = DiskBlobManager(os.path.join(conf.settings.data_dir, "blobfiles"), storage, datastore)
return self.blob_manager.setup()
def stop(self):
@@ -428,34 +372,34 @@ class DHTComponent(Component):
def get_status(self):
return {
'node_id': binascii.hexlify(CS.get_node_id()),
'node_id': binascii.hexlify(conf.settings.get_node_id()),
'peers_in_routing_table': 0 if not self.dht_node else len(self.dht_node.contacts)
}
@defer.inlineCallbacks
def start(self):
self.upnp_component = self.component_manager.get_component(UPNP_COMPONENT)
self.external_peer_port = self.upnp_component.upnp_redirects.get("TCP", GCS("peer_port"))
self.external_udp_port = self.upnp_component.upnp_redirects.get("UDP", GCS("dht_node_port"))
node_id = CS.get_node_id()
self.external_peer_port = self.upnp_component.upnp_redirects.get("TCP", conf.settings["peer_port"])
self.external_udp_port = self.upnp_component.upnp_redirects.get("UDP", conf.settings["dht_node_port"])
node_id = conf.settings.get_node_id()
if node_id is None:
node_id = generate_id()
external_ip = self.upnp_component.external_ip
if not external_ip:
log.warning("UPnP component failed to get external ip")
external_ip = yield CS.get_external_ip()
external_ip = yield get_external_ip()
if not external_ip:
log.warning("failed to get external ip")
self.dht_node = Node(
node_id=node_id,
udpPort=GCS('dht_node_port'),
udpPort=conf.settings['dht_node_port'],
externalUDPPort=self.external_udp_port,
externalIP=external_ip,
peerPort=self.external_peer_port
)
yield self.dht_node.start(GCS('known_dht_nodes'), block_on_join=False)
yield self.dht_node.start(conf.settings['known_dht_nodes'], block_on_join=False)
log.info("Started the dht")
@defer.inlineCallbacks
@@ -565,7 +509,7 @@ class FileManagerComponent(Component):
blob_manager,
storage,
wallet,
GCS('download_directory')
conf.settings.download_dir
)
yield sd_identifier.add_stream_downloader_factory(EncryptedFileStreamType, file_saver_factory)
@@ -598,7 +542,7 @@ class PeerProtocolServerComponent(Component):
def start(self):
wallet = self.component_manager.get_component(WALLET_COMPONENT)
upnp = self.component_manager.get_component(UPNP_COMPONENT)
peer_port = GCS('peer_port')
peer_port = conf.settings['peer_port']
query_handlers = {
handler.get_primary_query_identifier(): handler for handler in [
BlobRequestHandlerFactory(
@@ -640,7 +584,7 @@ class ReflectorComponent(Component):
def __init__(self, component_manager):
super().__init__(component_manager)
self.reflector_server_port = GCS('reflector_port')
self.reflector_server_port = conf.settings['reflector_port']
self.reflector_server = None
@property
@@ -673,9 +617,9 @@ class UPnPComponent(Component):
def __init__(self, component_manager):
super().__init__(component_manager)
self._int_peer_port = GCS('peer_port')
self._int_dht_node_port = GCS('dht_node_port')
self.use_upnp = GCS('use_upnp')
self._int_peer_port = conf.settings['peer_port']
self._int_dht_node_port = conf.settings['dht_node_port']
self.use_upnp = conf.settings['use_upnp']
self.upnp = None
self.upnp_redirects = {}
self.external_ip = None
@@ -719,7 +663,7 @@ class UPnPComponent(Component):
if external_ip == "0.0.0.0" or not external_ip:
log.warning("unable to get external ip from UPnP, checking lbry.io fallback")
external_ip = yield CS.get_external_ip()
external_ip = yield get_external_ip()
if self.external_ip and self.external_ip != external_ip:
log.info("external ip changed from %s to %s", self.external_ip, external_ip)
self.external_ip = external_ip
@@ -775,7 +719,7 @@ class UPnPComponent(Component):
def start(self):
log.info("detecting external ip")
if not self.use_upnp:
self.external_ip = yield CS.get_external_ip()
self.external_ip = yield get_external_ip()
return
success = False
yield self._maintain_redirects()
+4 -2
View File
@@ -166,9 +166,9 @@ def sort_claim_results(claims):
def is_first_run():
if os.path.isfile(conf.settings.get_db_revision_filename()):
return False
if os.path.isfile(os.path.join(conf.settings['data_dir'], 'lbrynet.sqlite')):
if os.path.isfile(os.path.join(conf.settings.data_dir, 'lbrynet.sqlite')):
return False
if os.path.isfile(os.path.join(conf.settings['lbryum_wallet_dir'], 'blockchain_headers')):
if os.path.isfile(os.path.join(conf.settings.wallet_dir, 'blockchain_headers')):
return False
return True
@@ -2633,6 +2633,8 @@ class Daemon(AuthJSONRPCServer):
results[chan_uri] = {"error": "%s is not a valid uri" % chan_uri}
resolved = await self.wallet_manager.resolve(*valid_uris, page=page, page_size=page_size)
if 'error' in resolved:
return {'error': resolved['error']}
for u in resolved:
if 'error' in resolved[u]:
results[u] = resolved[u]
-72
View File
@@ -1,72 +0,0 @@
import os
import sys
# Set SSL_CERT_FILE env variable for Twisted SSL verification on Windows
# This needs to happen before anything else
if 'win' in sys.platform:
import certifi
os.environ['SSL_CERT_FILE'] = certifi.where()
import argparse
import logging.handlers
from twisted.internet import reactor
from lbrynet import utils, conf, log_support
from lbrynet.extras import system_info
from lbrynet.extras.daemon.Daemon import Daemon
log = logging.getLogger(__name__)
def test_internet_connection():
return utils.check_connection()
def start(argv=None, conf_path=None):
if conf_path is not None:
conf.conf_file = conf_path
conf.initialize_settings()
parser = argparse.ArgumentParser()
parser.add_argument(
"--http-auth", dest="useauth", action="store_true", default=conf.settings['use_auth_http']
)
parser.add_argument(
'--quiet', dest='quiet', action="store_true",
help='Disable all console output.'
)
parser.add_argument(
'--verbose', nargs="*",
help=('Enable debug output. Optionally specify loggers for which debug output '
'should selectively be applied.')
)
parser.add_argument(
'--version', action="store_true",
help='Show daemon version and quit'
)
args = parser.parse_args(argv)
if args.useauth:
conf.settings.update({'use_auth_http': args.useauth}, data_types=(conf.TYPE_CLI,))
if args.version:
version = system_info.get_platform()
version['installation_id'] = conf.settings.installation_id
print(utils.json_dumps_pretty(version))
return
lbrynet_log = conf.settings.get_log_filename()
log_support.configure_logging(lbrynet_log, not args.quiet, args.verbose)
log_support.configure_loggly_handler()
log.debug('Final Settings: %s', conf.settings.get_current_settings_dict())
log.info("Starting lbrynet-daemon from command line")
if test_internet_connection():
daemon = Daemon()
daemon.start_listening()
reactor.run()
else:
log.info("Not connected to internet, unable to start")
+1 -1
View File
@@ -41,7 +41,7 @@ class GetStream:
self.data_rate = data_rate or conf.settings['data_rate']
self.max_key_fee = max_key_fee or conf.settings['max_key_fee'][1]
self.disable_max_key_fee = disable_max_key_fee or conf.settings['disable_max_key_fee']
self.download_directory = conf.settings['download_directory']
self.download_directory = conf.settings.download_dir
self.timeout_counter = 0
self.code = None
self.sd_hash = None
+1 -4
View File
@@ -125,9 +125,6 @@ class AuthAPIClient:
class LBRYAPIClient:
@staticmethod
def get_client(conf_path=None):
conf.conf_file = conf_path
if not conf.settings:
conf.initialize_settings()
def get_client():
return AuthAPIClient.get_client() if conf.settings['use_auth_http'] else \
UnAuthAPIClient.from_url(conf.settings.get_api_connection_string())
+4 -4
View File
@@ -73,8 +73,8 @@ class Keyring:
@classmethod
def load_from_disk(cls):
api_key_path = os.path.join(conf.settings['data_dir'], 'auth_token')
api_ssl_cert_path = os.path.join(conf.settings['data_dir'], 'api_ssl_cert.pem')
api_key_path = os.path.join(conf.settings.data_dir, 'auth_token')
api_ssl_cert_path = os.path.join(conf.settings.data_dir, 'api_ssl_cert.pem')
if not os.path.isfile(api_key_path) or not os.path.isfile(api_ssl_cert_path):
return
with open(api_key_path, 'rb') as f:
@@ -122,10 +122,10 @@ class Keyring:
auth_token = APIKey.create(seed=None, name="api")
with open(os.path.join(conf.settings['data_dir'], 'auth_token'), 'wb') as f:
with open(os.path.join(conf.settings.data_dir, 'auth_token'), 'wb') as f:
f.write(auth_token.secret.encode())
with open(os.path.join(conf.settings['data_dir'], 'api_ssl_cert.pem'), 'wb') as f:
with open(os.path.join(conf.settings.data_dir, 'api_ssl_cert.pem'), 'wb') as f:
f.write(public_certificate.encode())
return cls(auth_token, public_certificate, private_certificate)
@@ -22,6 +22,8 @@ def migrate_db(db_dir, start, end):
from .migrate7to8 import do_migration
elif current == 8:
from .migrate8to9 import do_migration
elif current == 9:
from .migrate9to10 import do_migration
else:
raise Exception("DB migration of version {} to {} is not available".format(current,
current+1))
@@ -7,8 +7,6 @@ from lbrynet.schema.decode import smart_decode
log = logging.getLogger(__name__)
download_directory = conf.settings['download_directory']
CREATE_TABLES_QUERY = """
pragma foreign_keys=on;
pragma journal_mode=WAL;
@@ -190,7 +188,7 @@ def do_migration(db_dir):
# insert the file
transaction.execute(
"insert or ignore into file values (?, ?, ?, ?, ?)",
(stream_hash, stream_name, download_directory.encode('hex'),
(stream_hash, stream_name, conf.settings.download_dir.encode('hex'),
data_rate, status)
)
@@ -0,0 +1,11 @@
import sqlite3
import os
def do_migration(db_dir):
db_path = os.path.join(db_dir, "lbrynet.sqlite")
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.executescript("ALTER TABLE claim ADD resolved_at int DEFAULT 0 NOT NULL;")
connection.commit()
connection.close()
+31 -12
View File
@@ -12,6 +12,7 @@ from lbrynet.schema.claim import ClaimDict
from lbrynet.schema.decode import smart_decode
from lbrynet.blob.CryptBlob import CryptBlobInfo
from lbrynet.dht.constants import dataExpireTimeout
from lbrynet.schema.uri import parse_lbry_uri
log = logging.getLogger(__name__)
@@ -386,8 +387,8 @@ class SQLiteStorage:
def _store_stream(transaction):
transaction.execute("insert into stream values (?, ?, ?, ?, ?);",
(stream_hash, sd_hash, stream_key, stream_name,
suggested_file_name))
(stream_hash, sd_hash, stream_key, stream_name,
suggested_file_name))
for blob_info in stream_blob_infos:
transaction.execute("insert into stream_blob values (?, ?, ?, ?)",
@@ -568,13 +569,11 @@ class SQLiteStorage:
return self.db.runInteraction(_save_support)
def get_supports(self, *claim_ids):
def _format_support(outpoint, supported_id, amount, address):
def _format_support(outpoint, amount):
return {
"txid": outpoint.split(":")[0],
"nout": int(outpoint.split(":")[1]),
"claim_id": supported_id,
"amount": dewies_to_lbc(amount),
"address": address,
}
def _get_supports(transaction):
@@ -582,7 +581,7 @@ class SQLiteStorage:
_format_support(*support_info)
for support_info in _batched_select(
transaction,
"select * from support where claim_id in {}",
"select support_outpoint, amount from support where claim_id in {}",
tuple(claim_ids)
)
]
@@ -604,8 +603,9 @@ class SQLiteStorage:
height = claim_info['height']
address = claim_info['address']
sequence = claim_info['claim_sequence']
resolved_at = claim_info['height'] + claim_info['depth']
try:
certificate_id = claim_info['value'].get('content_claims_to_update', {}).get('certificateId')
certificate_id = claim_info['value'].get('publisherSignature', {}).get('certificateId')
except AttributeError:
certificate_id = None
try:
@@ -617,8 +617,9 @@ class SQLiteStorage:
source_hash = None
serialized = claim_info.get('hex') or hexlify(smart_decode(claim_info['value']).serialized)
transaction.execute(
"insert or replace into claim values (?, ?, ?, ?, ?, ?, ?, ?, ?)",
(outpoint, claim_id, name, amount, height, serialized, certificate_id, address, sequence)
"insert or replace into claim values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(outpoint, claim_id, name, amount, height, serialized, certificate_id, address, sequence,
resolved_at)
)
if 'supports' in claim_info: # if this response doesn't have support info don't overwrite the existing
# support info
@@ -794,6 +795,24 @@ class SQLiteStorage:
claims[stream_hash] = claim
defer.returnValue(claims)
def get_resolved_at_for_outpoint(self, outpoint):
return self.run_and_return_one_or_none(
"select resolved_at from claim "
"where claim_outpoint = ?",
outpoint
)
def get_outpoint_for_uri(self, uri):
uri = parse_lbry_uri(uri)
claim_id_param = "%" if not uri.claim_id else uri.claim_id
return self.run_and_return_one_or_none(
"select claim_outpoint from claim "
"where claim_name=? and claim_id like ?"
"order by height desc, amount desc "
"limit 1",
uri.name, claim_id_param
)
@defer.inlineCallbacks
def get_claim(self, claim_outpoint, include_supports=True):
def _get_claim(transaction):
@@ -872,19 +891,19 @@ class SQLiteStorage:
# Helper functions
def _format_claim_response(outpoint, claim_id, name, amount, height, serialized, channel_id, address, claim_sequence):
def _format_claim_response(outpoint, claim_id, name, amount, height, serialized, _channel_id, address, claim_sequence,
_resolved_at):
r = {
"name": name,
"claim_id": claim_id,
"address": address,
"claim_sequence": claim_sequence,
"hex": serialized,
"value": ClaimDict.deserialize(unhexlify(serialized)).claim_dict,
"height": height,
"amount": dewies_to_lbc(amount),
"nout": int(outpoint.split(":")[1]),
"txid": outpoint.split(":")[0],
"channel_claim_id": channel_id,
"channel_name": None
}
return r
+1 -1
View File
@@ -30,4 +30,4 @@ def lbc_to_dewies(lbc: str) -> int:
def dewies_to_lbc(dewies) -> str:
return satoshis_to_coins(dewies)
return dewies if isinstance(dewies, str) else satoshis_to_coins(dewies)
+2 -1
View File
@@ -65,8 +65,9 @@ class MainNetLedger(BaseLedger):
except Exception as e:
return {'error': str(e)}
try:
resolver = self.resolver
resolutions = await self.network.get_values_for_uris(self.headers.hash().decode(), *uris)
return await self.resolver._handle_resolutions(resolutions, uris, page, page_size)
return await resolver._handle_resolutions(resolutions, uris, page, page_size)
except Exception as e:
return {'error': str(e)}
+47 -3
View File
@@ -10,6 +10,7 @@ from typing import Optional
from twisted.internet import defer
from lbrynet.schema.schema import SECP256k1
from lbrynet.schema.uri import parse_lbry_uri
from torba.client.basemanager import BaseWalletManager
from torba.rpc.jsonrpc import CodeMessageError
@@ -25,6 +26,10 @@ from lbrynet.extras.wallet.dewies import dewies_to_lbc
log = logging.getLogger(__name__)
def d2f(deferred):
return deferred.asFuture(asyncio.get_event_loop())
class ReservedPoints:
def __init__(self, identifier, amount):
self.identifier = identifier
@@ -171,12 +176,12 @@ class LbryWalletManager(BaseWalletManager):
ledger_config = {
'auto_connect': True,
'default_servers': settings['lbryum_servers'],
'data_path': settings['lbryum_wallet_dir'],
'data_path': settings.wallet_dir,
'use_keyring': settings['use_keyring'],
#'db': db
}
wallets_directory = os.path.join(settings['lbryum_wallet_dir'], 'wallets')
wallets_directory = os.path.join(settings.wallet_dir, 'wallets')
if not os.path.exists(wallets_directory):
os.mkdir(wallets_directory)
@@ -268,16 +273,55 @@ class LbryWalletManager(BaseWalletManager):
def get_info_exchanger(self):
return LBRYcrdAddressRequester(self)
async def fetch_from_cache(self, uri):
resolver = self.ledger.resolver
is_channel = parse_lbry_uri(uri).is_channel
claim_outpoint = await d2f(self.old_db.get_outpoint_for_uri(uri))
last_resolved_at = await d2f(self.old_db.get_resolved_at_for_outpoint(claim_outpoint))
if not last_resolved_at or resolver.height - last_resolved_at > 1:
return False
log.info("trying to fetch %s from cache", uri)
claim = await d2f(self.old_db.get_claim(claim_outpoint))
claim['depth'] = resolver.height - claim['height']
result = {"claim": claim}
if claim.get("channel_name", False):
certificate_uri = "{}#{}".format(claim.get("channel_name", ""),
claim['value'].get('publisherSignature', {}).get('certificateId'))
certificate_outpoint = await d2f(self.old_db.get_outpoint_for_uri(certificate_uri))
certificate = await d2f(self.old_db.get_claim(certificate_outpoint))
certificate['depth'] = resolver.height - certificate['height']
result["certificate"] = await resolver.parse_and_validate_claim_result(certificate)
result["claim"] = await resolver.parse_and_validate_claim_result(result["claim"],
certificate=result.get(
"certificate", None))
if is_channel:
result = {"certificate": result["claim"]}
return result
async def resolve(self, *uris, **kwargs):
page = kwargs.get('page', 0)
page_size = kwargs.get('page_size', 10)
check_cache = kwargs.get('check_cache', False) # TODO: put caching back (was force_refresh parameter)
cached_results = dict()
needed = list()
if check_cache:
for uri in uris:
cached_results[uri] = await self.fetch_from_cache(uri)
needed = [key for key in cached_results if not cached_results[key]]
ledger: MainNetLedger = self.default_account.ledger
results = await ledger.resolve(page, page_size, *uris)
results = await ledger.resolve(page, page_size, *needed)
if 'error' not in results:
await self.old_db.save_claims_for_resolve([
value for value in results.values() if 'error' not in value
]).asFuture(asyncio.get_event_loop())
results = {**cached_results, **results}
return results
async def get_claims_for_name(self, name: str):
+7 -1
View File
@@ -180,7 +180,8 @@ class Resolver:
if decoded.has_signature:
if certificate is None:
log.info("fetching certificate to check claim signature")
certificate = await self.network.get_claims_by_ids(decoded.certificate_id.decode())
certificate_id = decoded.certificate_id.decode()
certificate = (await self.network.get_claims_by_ids(certificate_id)).get(certificate_id, {})
if not certificate:
log.warning('Certificate %s not found', decoded.certificate_id)
claim_result['has_signature'] = True
@@ -298,6 +299,11 @@ def format_amount_value(obj):
if not isinstance(obj[k], float):
obj[k] = dewies_to_lbc(obj[k])
elif k == 'supports' and isinstance(v, list):
# supports are already in the desired format
# the following 2 lines are bad as supports should be passed in a consistent manner
# but it is unavoidable at the moment because of so much other code linked to this :-(
if v and isinstance(v[0], dict):
continue
obj[k] = [{'txid': txid, 'nout': nout, 'amount': dewies_to_lbc(amount)}
for (txid, nout, amount) in v]
elif isinstance(v, (list, dict)):
+1 -1
View File
@@ -3,7 +3,7 @@ import re
import json
import inspect
from textwrap import dedent
from lbrynet.daemon.Daemon import Daemon
from lbrynet.extras.daemon.Daemon import Daemon
SECTIONS = re.compile("(.*?)Usage:(.*?)Options:(.*?)Returns:(.*)", re.DOTALL)
+228
View File
@@ -0,0 +1,228 @@
import os
import re
import io
import sys
import json
import argparse
import unittest
from datetime import date
from getpass import getpass
try:
import github3
except ImportError:
print('To run release tool you need to install github3.py:')
print('')
print(' $ pip install github3.py')
print('')
sys.exit(1)
AREA_RENAME = {
'api': 'API'
}
def get_github():
config_path = os.path.expanduser('~/.lbry-release-tool.json')
if os.path.exists(config_path):
with open(config_path, 'r') as config_file:
config = json.load(config_file)
return github3.login(token=config['token'])
print('GitHub Credentials')
username = input('username: ')
password = getpass('password: ')
gh = github3.authorize(
username, password, ['repo'], 'lbry release tool',
two_factor_callback=lambda: input('Enter 2FA: ')
)
with open(config_path, 'w') as config_file:
json.dump({'token': gh.token}, config_file)
return github3.login(token=gh.token)
def get_labels(pr, prefix):
for label in pr.labels:
label_name = label['name']
if label_name.startswith(f'{prefix}: '):
yield label_name[len(f'{prefix}: '):]
def get_label(pr, prefix):
for label in get_labels(pr, prefix):
return label
def get_previous_final(repo, current_release):
assert current_release.rc is not None, "Need an rc to find the previous final release."
previous = None
for release in repo.releases(current_release.rc + 1):
previous = release
return previous
class Version:
def __init__(self, major=0, minor=0, micro=0, rc=None):
self.major = int(major)
self.minor = int(minor)
self.micro = int(micro)
self.rc = rc if rc is None else int(rc)
@classmethod
def from_string(cls, version_string):
(major, minor, micro), rc = version_string.split('.'), None
if 'rc' in micro:
micro, rc = micro.split('rc')
return cls(major, minor, micro, rc)
@classmethod
def from_content(cls, content):
src = content.decoded.decode('utf-8')
version = re.search('__version__ = "(.*?)"', src).group(1)
return cls.from_string(version)
def increment(self, action):
cls = self.__class__
if action == '*-rc':
assert self.rc is not None, f"Can't drop rc designation because {self} is already not an rc."
return cls(self.major, self.minor, self.micro)
elif action == '*+rc':
assert self.rc is not None, "Must already be an rc to increment."
return cls(self.major, self.minor, self.micro, self.rc+1)
assert self.rc is None, f"Can't start a new rc because {self} is already an rc."
if action == 'major+rc':
return cls(self.major+1, rc=1)
elif action == 'minor+rc':
return cls(self.major, self.minor+1, rc=1)
elif action == 'micro+rc':
return cls(self.major, self.minor, self.micro+1, 1)
raise ValueError(f'unknown action: {action}')
@property
def tag(self):
return f'v{self}'
def __str__(self):
version = '.'.join(str(p) for p in [self.major, self.minor, self.micro])
if self.rc is not None:
version += f'rc{self.rc}'
return version
def release(args):
gh = get_github()
repo = gh.repository('lbryio', 'lbry')
version_file = repo.file_contents('lbrynet/__init__.py')
current_version = Version.from_content(version_file)
print(f'Current Version: {current_version}')
new_version = current_version.increment(args.action)
print(f' New Version: {new_version}')
print()
if args.action == '*-rc':
previous_release = get_previous_final(repo, current_version)
else:
previous_release = repo.release_from_tag(current_version.tag)
areas = {}
for pr in gh.search_issues(f"merged:>={previous_release._json_data['created_at']} repo:lbryio/lbry"):
for area_name in get_labels(pr, 'area'):
area = areas.setdefault(area_name, [])
type_label = get_label(pr, "type")
if not (args.action == '*-rc' and type_label == 'fixup'):
area.append(f' * [{type_label}] {pr.title} ({pr.html_url})')
area_names = list(areas.keys())
area_names.sort()
body = io.StringIO()
w = lambda s: body.write(s+'\n')
w(f'## [{new_version}] - {date.today().isoformat()}')
for area in area_names:
prs = areas[area]
area = AREA_RENAME.get(area, area.capitalize())
w('')
w(f'### {area}')
for pr in prs:
w(pr)
print(body.getvalue())
if not args.dry_run:
commit = version_file.update(
new_version.tag,
version_file.decoded.decode('utf-8').replace(str(current_version), str(new_version)).encode()
)['commit']
repo.create_tag(
tag=new_version.tag,
message=new_version.tag,
sha=commit.sha,
obj_type='commit',
tagger=commit.committer
)
repo.create_release(
new_version.tag,
name=new_version.tag,
body=body.getvalue(),
draft=True,
prerelease=new_version.rc is not None
)
class TestReleaseTool(unittest.TestCase):
def test_version_parsing(self):
self.assertTrue(str(Version.from_string('1.2.3')), '1.2.3')
self.assertTrue(str(Version.from_string('1.2.3rc4')), '1.2.3rc4')
def test_version_increment(self):
v = Version.from_string('1.2.3')
self.assertTrue(str(v.increment('major+rc')), '2.0.0rc1')
self.assertTrue(str(v.increment('minor+rc')), '1.3.0rc1')
self.assertTrue(str(v.increment('micro+rc')), '1.2.4rc1')
with self.assertRaisesRegex(AssertionError, "Must already be an rc to increment."):
v.increment('*+rc')
with self.assertRaisesRegex(AssertionError, "Can't drop rc designation"):
v.increment('*-rc')
v = Version.from_string('1.2.3rc3')
self.assertTrue(str(v.increment('*+rc')), '1.2.3rc4')
self.assertTrue(str(v.increment('*-rc')), '1.2.3')
with self.assertRaisesRegex(AssertionError, "already an rc"):
v.increment('major+rc')
with self.assertRaisesRegex(AssertionError, "already an rc"):
v.increment('minor+rc')
with self.assertRaisesRegex(AssertionError, "already an rc"):
v.increment('micro+rc')
def test():
runner = unittest.TextTestRunner(verbosity=2)
loader = unittest.TestLoader()
suite = loader.loadTestsFromTestCase(TestReleaseTool)
runner.run(suite)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--test", default=False, action="store_true", help="run unit tests")
parser.add_argument("--dry-run", default=False, action="store_true", help="show what will be done")
parser.add_argument("action", nargs="?", choices=['major+rc', 'minor+rc', 'micro+rc', '*+rc', '*-rc'])
args = parser.parse_args()
if args.test:
test()
else:
release(args)
if __name__ == "__main__":
main()
-1
View File
@@ -14,7 +14,6 @@ cd twisted && pip install -e .[tls] && cd ..
cd torba && pip install -e . && cd ..
cd lbry
python scripts/set_build.py
# Download from their CI until its not released. Remove later!
wget -Onetifaces-0.10.7-cp37-cp37m-win32.whl https://ci.appveyor.com/api/buildjobs/6hworunifsymrhp2/artifacts/dist%2Fnetifaces-0.10.7-cp37-cp37m-win32.whl
-5
View File
@@ -44,9 +44,4 @@ setup(
'docopt',
'colorama==0.3.7',
],
extras_require={
'test': (
'faker==0.8.17',
)
}
)
+44 -8
View File
@@ -126,10 +126,10 @@ class CommandTestCase(IntegrationTestCase):
logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)
lbry_conf.settings = None
lbry_conf.initialize_settings(load_conf_file=False)
lbry_conf.settings['data_dir'] = self.wallet_node.data_path
lbry_conf.settings['lbryum_wallet_dir'] = self.wallet_node.data_path
lbry_conf.settings['download_directory'] = self.wallet_node.data_path
lbry_conf.initialize_settings(
load_conf_file=False, data_dir=self.wallet_node.data_path, wallet_dir=self.wallet_node.data_path,
download_dir=self.wallet_node.data_path
)
lbry_conf.settings['use_upnp'] = False
lbry_conf.settings['reflect_uploads'] = False
lbry_conf.settings['blockchain_name'] = 'lbrycrd_regtest'
@@ -167,6 +167,7 @@ class CommandTestCase(IntegrationTestCase):
self.manager.old_db = self.daemon.storage
async def tearDown(self):
self.conductor.spv_node.server.stop()
await super().tearDown()
self.wallet_component._running = False
await d2f(self.daemon._shutdown())
@@ -487,7 +488,7 @@ class ClaimManagement(CommandTestCase):
VERBOSITY = logging.WARN
async def make_claim(self, name='hovercraft', amount='1.0', data=b'hi!', channel_name=None):
async def make_claim(self, name='hovercraft', amount='1.0', data=b'hi!', channel_name=None, confirm=True):
with tempfile.NamedTemporaryFile() as file:
file.write(data)
file.flush()
@@ -495,9 +496,10 @@ class ClaimManagement(CommandTestCase):
name, amount, file_path=file.name, channel_name=channel_name
))
self.assertTrue(claim['success'])
await self.on_transaction_dict(claim['tx'])
await self.generate(1)
await self.on_transaction_dict(claim['tx'])
if confirm:
await self.on_transaction_dict(claim['tx'])
await self.generate(1)
await self.on_transaction_dict(claim['tx'])
return claim
async def craft_claim(self, name, amount_dewies, claim_dict, address):
@@ -711,6 +713,40 @@ class ClaimManagement(CommandTestCase):
self.assertTrue(response[uri]['claim']['signature_is_valid'])
self.assertEqual(response[uri]['claim']['txid'], original_claim['tx']['txid'])
async def test_claim_list_by_channel(self):
self.maxDiff = None
tx = await self.daemon.jsonrpc_account_fund(None, None, '0.001', outputs=100, broadcast=True)
await self.ledger.wait(tx)
await self.generate(1)
await self.ledger.wait(tx)
channel = await self.out(self.daemon.jsonrpc_channel_new('@abc', "0.0001"))
self.assertTrue(channel['success'])
await self.confirm_tx(channel['tx']['txid'])
# 4 claims per block, 3 blocks. Sorted by height (descending) then claim_id (ascending).
claims = []
for j in range(3):
same_height_claims = []
for k in range(3):
claim = await self.make_claim(amount='0.000001', name=f'c{j}-{k}', channel_name='@abc', confirm=False)
self.assertTrue(claim['success'])
same_height_claims.append(claim['claim_id'])
await self.on_transaction_dict(claim['tx'])
claim = await self.make_claim(amount='0.000001', name=f'c{j}-4', channel_name='@abc', confirm=True)
self.assertTrue(claim['success'])
same_height_claims.append(claim['claim_id'])
same_height_claims.sort(key=lambda x: int(x, 16))
claims = same_height_claims + claims
page = await self.out(self.daemon.jsonrpc_claim_list_by_channel(1, page_size=20, uri='@abc'))
page_claim_ids = [item['claim_id'] for item in page['@abc']['claims_in_channel']]
self.assertEqual(page_claim_ids, claims)
page = await self.out(self.daemon.jsonrpc_claim_list_by_channel(1, page_size=6, uri='@abc'))
page_claim_ids = [item['claim_id'] for item in page['@abc']['claims_in_channel']]
self.assertEqual(page_claim_ids, claims[:6])
out_of_bounds = await self.out(self.daemon.jsonrpc_claim_list_by_channel(2, page_size=20, uri='@abc'))
self.assertEqual(out_of_bounds['error'], 'claim 20 greater than max 12')
async def test_regular_supports_and_tip_supports(self):
# account2 will be used to send tips and supports to account1
account2_id = (await self.daemon.jsonrpc_account_create('second account'))['id']
+6
View File
@@ -502,6 +502,12 @@ def mock_conf_settings(obj, settings={}):
conf.initialize_settings(False)
original_settings = conf.settings
conf.settings = conf.Config(conf.FIXED_SETTINGS, conf.ADJUSTABLE_SETTINGS)
conf.settings['data_dir'] = settings.get('data_dir') or conf.settings.data_dir \
or conf.settings.default_data_dir
conf.settings['download_directory'] = settings.get('download_directory') or conf.settings.download_dir \
or conf.settings.default_download_dir
conf.settings['wallet_dir'] = settings.get('wallet_dir') or conf.settings.wallet_dir or \
conf.settings.default_wallet_dir
conf.settings.installation_id = conf.settings.get_installation_id()
conf.settings.node_id = conf.settings.get_node_id()
conf.settings.update(settings)
+241 -45
View File
@@ -1,12 +1,9 @@
from unittest import mock
import json
import random
from os import path
from twisted.internet import defer
from twisted.trial import unittest
from faker import Faker
from lbrynet import conf
from lbrynet.schema.decode import smart_decode
from lbrynet.extras.daemon.storage import SQLiteStorage
@@ -29,7 +26,6 @@ from tests.mocks import ExchangeRateManager as DummyExchangeRateManager
from tests.mocks import BTCLBCFeed, USDBTCFeed
from tests.test_utils import is_android
def get_test_daemon(data_rate=None, generous=True, with_fee=False):
if data_rate is None:
data_rate = conf.ADJUSTABLE_SETTINGS['data_rate'][1]
@@ -152,8 +148,6 @@ class TestFileListSorting(unittest.TestCase):
def setUp(self):
mock_conf_settings(self)
test_utils.reset_time(self)
self.faker = Faker('en_US')
self.faker.seed(129) # contains 3 same points paid (5.9)
self.test_daemon = get_test_daemon()
self.test_daemon.file_manager.lbry_files = self._get_fake_lbry_files()
@@ -268,44 +262,246 @@ class TestFileListSorting(unittest.TestCase):
with self.assertRaisesRegex(Exception, expected_message):
yield self.test_daemon.jsonrpc_file_list(sort=sort_options)
def _get_fake_lbry_files(self):
return [self._get_fake_lbry_file() for _ in range(10)]
@staticmethod
def _get_fake_lbry_files():
faked_lbry_files = []
for metadata in FAKED_LBRY_FILES:
lbry_file = mock.Mock(spec=ManagedEncryptedFileDownloader)
for attribute in metadata:
setattr(lbry_file, attribute, metadata[attribute])
faked_lbry_files.append(lbry_file)
return faked_lbry_files
def _get_fake_lbry_file(self):
lbry_file = mock.Mock(spec=ManagedEncryptedFileDownloader)
file_path = self.faker.file_path()
stream_name = self.faker.file_name()
channel_claim_id = self.faker.sha1()
channel_name = self.faker.simple_profile()['username']
faked_attributes = {
'channel_claim_id': channel_claim_id,
'channel_name': '@' + channel_name,
'claim_id': self.faker.sha1(),
'claim_name': '-'.join(self.faker.words(4)),
'completed': self.faker.boolean(),
'download_directory': path.dirname(file_path),
'download_path': file_path,
'file_name': path.basename(file_path),
'key': self.faker.md5(raw_output=True),
'metadata': {
'author': channel_name,
'nsfw': random.randint(0, 1) == 1,
},
'mime_type': self.faker.mime_type(),
'nout': abs(self.faker.pyint()),
'outpoint': self.faker.md5() + self.faker.md5(),
'points_paid': self.faker.pyfloat(left_digits=1, right_digits=1, positive=True),
'sd_hash': self.faker.md5() + self.faker.md5() + self.faker.md5(),
'stopped': self.faker.boolean(),
'stream_hash': self.faker.md5() + self.faker.md5() + self.faker.md5(),
'stream_name': stream_name,
'suggested_file_name': stream_name,
'txid': self.faker.md5() + self.faker.md5(),
'written_bytes': self.faker.pyint(),
}
for key in faked_attributes:
setattr(lbry_file, key, faked_attributes[key])
return lbry_file
FAKED_LBRY_FILES = (
{
'channel_claim_id': '3aace03b007d108c668d201533b7b07ab2981d47',
'channel_name': '@ashlee27',
'claim_id': 'cb63e644b6629467c031d0097d52ab6e0f1a5bf8',
'claim_name': 'very-skill-place-growth',
'completed': True,
'download_directory': '/usually',
'download_path': '/usually/any.mov',
'file_name': 'any.mov',
'key': b'>a\x11}\xec\xc2j\x1c\xe9\xc5l]\xfc\x16s|',
'metadata': {'author': 'ashlee27', 'nsfw': True},
'mime_type': 'multipart/signed',
'nout': 7197,
'outpoint': 'c5633a5932f9c8e3e5b9799c07251b236e3aec078b0546614f24a932b6b133f6',
'points_paid': 8.2,
'sd_hash': '3354ecf502870f6f6d59d21188755c1361c2cffaeb458764c179c136b26c4795083acfd93b3920218870b1a9c22535ef',
'stopped': True,
'stream_hash': 'c8f58a686726116c15a8de7f33b4f0d72504777c7dd0c48ba94d7bbea23d9c82b2f977081cd7c49d25d6a2841b232e1d',
'stream_name': 'down.txt',
'suggested_file_name': 'down.txt',
'txid': '1c02986bfdb77b1c338e60b60c4c9febc59130af2e225f51665067c3d3419a35',
'written_bytes': 6838,
},
{
'channel_claim_id': 'dade35ea84001858d7cf10f50be3b5fea3e57fb7',
'channel_name': '@richard64',
'claim_id': '1c01096727da90140d333197fa8aaf88893f6ea8',
'claim_name': 'room-tonight-produce-good',
'completed': False,
'download_directory': '/ability',
'download_path': '/ability/day.tiff',
'file_name': 'day.tiff',
'key': b'`\x86j\xba\x97\x0c\xe4L\xad\x06nC\x8b]\xd6&',
'metadata': {'author': 'richard64', 'nsfw': False},
'mime_type': 'multipart/related',
'nout': 9678,
'outpoint': '0138083012ce4ff5a6e4c0ec2fc08e11a52ebd2306d70a20f36424011f7c1330',
'points_paid': 2.5,
'sd_hash': '9e98f5e4bd4393b45a41839fe72a4df1f94b029e2339f8b14b9eaa9fec2be5245b160a59cfcc80fa86c1f91da67d5581',
'stopped': False,
'stream_hash': '7403ff9319292bdb022d66d0b88401775c6bb355fc0a75fe01452950fb19642ba58d492d34e24d8bf58375e6c2fca16f',
'stream_name': 'including.mp3',
'suggested_file_name': 'including.mp3',
'txid': '345bfc7b4a0c042b14474ac2cecf099236aec5a6730943630ffb176e7b421121',
'written_bytes': 8438,
},
{
'channel_claim_id': '59766071ea2df38b4a751834a77246bf8ff8071d',
'channel_name': '@bfrederick',
'claim_id': '1c08967d515ac2a5fd3cb4e477fde18bddde22e2',
'claim_name': 'at-first-skill-agency',
'completed': True,
'download_directory': '/agree',
'download_path': '/agree/different.json',
'file_name': 'different.json',
'key': b'\xc06\xb9\x8e\x00S\xdbX\x1cC\xbd+\xfc\xea\xc96',
'metadata': {'author': 'bfrederick', 'nsfw': True},
'mime_type': 'image/svg+xml',
'nout': 2975,
'outpoint': '62bb992e11c562e8064aec094e2b4eefb422e50b13ae49dc10f440a60f8e99bc',
'points_paid': 9.1,
'sd_hash': '3d809caf1266ec1ab78cc046a62f388434b6c59f85844500f59a1c75b4303b9ea27c532a231556e8b9776c544677bdf7',
'stopped': True,
'stream_hash': '9ecb8cf7dca7260f90666f05c88882017c786d31b572f3cba9447099ca9b49cdcb93f801db2249b7d32ff44ca6ffd69c',
'stream_name': 'north.doc',
'suggested_file_name': 'north.doc',
'txid': '98e12bce3a5db96e3513f1ff45afca8b69d61324117d6e839075ac512dd86251',
'written_bytes': 1929,
},
{
'channel_claim_id': '046c8a762cd158a6e5b112d7d9c9e4b778f27388',
'channel_name': '@heidiherring',
'claim_id': '3d7573264601af7b5402cd54a66c13f2f93f296f',
'claim_name': 'drop-hot-military-drive',
'completed': False,
'download_directory': '/letter',
'download_path': '/letter/than.ppt',
'file_name': 'than.ppt',
'key': b'\n\xa7\xb3\x05\xab\x8e\xcc\n\xdcn\xd9\x81\xf3m\xf1t',
'metadata': {'author': 'heidiherring', 'nsfw': True},
'mime_type': 'text/javascript',
'nout': 3452,
'outpoint': '5e8b55ffe59774366804c384f632f728f769bad566c784c6a23f1081724d00ea',
'points_paid': 5.9,
'sd_hash': 'c945b0acaf1c97dd7f262cf73cc3813ab6552f695ab00a445ca07a2a4da43bf3bb020cc7e338b484405d0865ef836480',
'stopped': False,
'stream_hash': '692ea08506d13422c875ce9d49fb9fe90b828d259d46c53adffa68a045e3852d4763b90ef94ef3864a1164bcab7eefa0',
'stream_name': 'few.css',
'suggested_file_name': 'few.css',
'txid': '9ef901facbf8bc133cfe67793fe4423c048753dab8370d987f6f552ed6483bbb',
'written_bytes': 9498,
},
{
'channel_claim_id': 'adc87fa84d601aa1760d0f4585f02e60bc82c703',
'channel_name': '@xsteele',
'claim_id': '9022e1fd14646f6a4f6708566fbb6f6ac10ba3d5',
'claim_name': 'mean-television-miss-yourself',
'completed': True,
'download_directory': '/its',
'download_path': '/its/add.mp3',
'file_name': 'add.mp3',
'key': b'\xdc\xd1\xf1i!\x85\xc6\xc8\\\xe0\xd7\xc0\xceN<l',
'metadata': {'author': 'xsteele', 'nsfw': False},
'mime_type': 'message/imdn+xml',
'nout': 7924,
'outpoint': '4fd8a071fd00050006a666de076595d7a61e04dac0ce8bf9ef90024d2415ba30',
'points_paid': 6.1,
'sd_hash': 'ac28c50337bd16b4a753a2ae6bdad25cbb93270b83f593ec238b8237ce4ddf30aff676eb7025211d970ab5a5cca204c7',
'stopped': True,
'stream_hash': 'a0a9aa762fb6599f94e7098d70cc14ced34d08c210863d62b6d1e9c7eb523d98d0d8e3c80ddc03ce68b51f99e88024b5',
'stream_name': 'picture.csv',
'suggested_file_name': 'picture.csv',
'txid': 'b4df85f9be396f2d9a3b9172f826be9899608d827cabc5196863ec27d3a32f82',
'written_bytes': 9220,
},
{
'channel_claim_id': '79d17bbcb93b31c20fe395190dc199d871268ef1',
'channel_name': '@michelle50',
'claim_id': 'daf4c15cd3da305e7b29b0028cf801c61bd67e30',
'claim_name': 'card-oil-since-take',
'completed': True,
'download_directory': '/lawyer',
'download_path': '/lawyer/hotel.bmp',
'file_name': 'hotel.bmp',
'key': b'\xda<-\x11-\xbb\xe3u\x80\xffX\x01N\xfc\x01)',
'metadata': {'author': 'michelle50', 'nsfw': True},
'mime_type': 'image/png',
'nout': 5576,
'outpoint': '27a62194fbf658327899431ecf251866bd0eec4da24d0b3feb8c440c4ea3ac1a',
'points_paid': 7.1,
'sd_hash': '20e4fc4513d7ea6f270e2021f7057c78e175754561e7db94e10c41d6d74ca639bb3c4d6e38dc2817ce303629c901d1a2',
'stopped': False,
'stream_hash': '781785e554fadb275ba75ee58cc5db0063f4d9cf2a1f1c4053a586ddce20089197d42e6640398cec75c8623a7c38ae0b',
'stream_name': 'paper.jpeg',
'suggested_file_name': 'paper.jpeg',
'txid': '8647c42f762694237804eeed4cbde776490a4f3b8b293ca41f550488098f883e',
'written_bytes': 7382,
},
{
'channel_claim_id': '7e4cee485713909665c21246ba22159e0a20a820',
'channel_name': '@jlewis',
'claim_id': '7bc402e4bc6a8b1c1aa2184e8e082eb1d0353db3',
'claim_name': 'heavy-street-meeting-and',
'completed': True,
'download_directory': '/personal',
'download_path': '/personal/remember.mp3',
'file_name': 'remember.mp3',
'key': b'\x1c\x9d%\x1e\xe4\xab\xb9\x0c\xac<\x86\xc7P;\xfdO',
'metadata': {'author': 'jlewis', 'nsfw': True},
'mime_type': 'video/x-matroska',
'nout': 8116,
'outpoint': 'e2da970db0edb37680519a58de53dc088e6d26d5c4a37ae37d5c0f1901f30197',
'points_paid': 4.8,
'sd_hash': 'f42913f4bfba90f157b4744b55e4043d79d2d658dc08aa306b34a3ae4a1c1c37759fd9f0b4b8181f539bd60373746954',
'stopped': True,
'stream_hash': '4051a577422fe2b444c9c572a0a1b3f731e0ed2e5eb3b9a3aaa4ce1b0ec694cd7786e224c94a126fc9a868f1b93cb2e1',
'stream_name': 'feel.html',
'suggested_file_name': 'feel.html',
'txid': 'c88e0c86ebbca20d0dafed682711a0b2e02e80637515c25eb26f2a589385bfe2',
'written_bytes': 9337,
},
{
'channel_claim_id': '13aa3c28c0c8bb08a679a010f63bd3f4b5234e73',
'channel_name': '@brittanyhicks',
'claim_id': '3c9c02bf1bfcedb2654f9003c464df9059a8e6b0',
'claim_name': 'cold-music-admit-technology',
'completed': True,
'download_directory': '/nor',
'download_path': '/nor/might.bmp',
'file_name': 'might.bmp',
'key': b'\rh\xb3jqR\\\xdb\xb9\xa0a\xa4J\xa4\xacs',
'metadata': {'author': 'brittanyhicks', 'nsfw': True},
'mime_type': 'application/xop+xml',
'nout': 8338,
'outpoint': 'a68a9dfa301292e1d0fe60a9bb0bcefa3e4e26630269064c8d2dd0f578427a10',
'points_paid': 5.9,
'sd_hash': '48fef5178b93b542495d19d76407692802ab529d989539b203a1cb38ce35ec2d4e9ea7d31eac660f715c39b69cd574ec',
'stopped': True,
'stream_hash': '2052889a9447ea73d743ec2c8c71678bf60616c01cd05d0a4d34a1aa92ee334585771a28f42cfe1b4124645352325946',
'stream_name': 'shoulder.js',
'suggested_file_name': 'shoulder.js',
'txid': 'b3f5f9db4c40157f348b9cf7dcb4ae3c53fe5e43481a4b66b2cc2334ae5ad2cb',
'written_bytes': 9736,
},
{
'channel_claim_id': 'a18b45f2131fd79fea6bb493d94349c9734ef211',
'channel_name': '@kswanson',
'claim_id': '1223727010f0b4b9f6f45ca95cad0bfb3ce759a0',
'claim_name': 'often-speech-provide-run',
'completed': True,
'download_directory': '/member',
'download_path': '/member/physical.json',
'file_name': 'physical.json',
'key': b"'\xa7\x9b!\t\x86\xe2q\x15S\x9c\x92S@7;",
'metadata': {'author': 'kswanson', 'nsfw': True},
'mime_type': 'multipart/form-data',
'nout': 7028,
'outpoint': '818a4265723d7682cff4cc89d9b3433af48636ba42d2ca1e65eef8b7f9bef0ad',
'points_paid': 8.4,
'sd_hash': 'c808d997ff914c4986e420c4b2547ab030082da28ffebe2a0844ad6325c9f276fad5a003b18dcd015397e41b71d172e2',
'stopped': False,
'stream_hash': '2d457dda5ed01009b3812ff60bd24cbc2a0cb1361f566433d71dbce7d757977deac7f5aca62a60ec63eaa1b401194da5',
'stream_name': 'country.avi',
'suggested_file_name': 'country.avi',
'txid': '42db2b952c578afcb8f640c2a12e563ba1a31b18fc8357d2f04f5de6c8515fba',
'written_bytes': 9688,
},
{
'channel_claim_id': '84a06ce77cde8ed1511e268fcfdebd8feb1333e2',
'channel_name': '@davidsonjeffrey',
'claim_id': '8fb403f0bb0695530935a0991a7eb7218c46eed9',
'claim_name': 'option-company-glass-this',
'completed': True,
'download_directory': '/environment',
'download_path': '/environment/decade.odt',
'file_name': 'decade.odt',
'key': b')\xa3h\x12\xf2\xd5RPkWojN\x08%\x0e',
'metadata': {'author': 'davidsonjeffrey', 'nsfw': True},
'mime_type': 'video/webm',
'nout': 8810,
'outpoint': '04da67fe9c6d129812e16045c02f1f670d3e329e7a9c0872712aaa74876becdd',
'points_paid': 5.9,
'sd_hash': '394eb1e0caf0d7dbeb80d435631534dc716229fac035aebe2af1729af5cbbad1c4fa503ce7fa7cc01e5366d1ce9d9d07',
'stopped': False,
'stream_hash': '1904d27ab8c784b7ae770980f004522e36089e86e3ce95d3005c3829cf4ad1571c5fe248a3f67a54521e07290a9e7466',
'stream_name': 'score.wav',
'suggested_file_name': 'score.wav',
'txid': 'd2f8ecfac4491e1de186b43a5e561413304769a1683612a16633dd3e725ff1e0',
'written_bytes': 7929,
},
)
+14 -15
View File
@@ -2,8 +2,10 @@ import os
import json
import sys
import tempfile
import shutil
from unittest import skipIf
from twisted.trial import unittest
from twisted.internet import defer
from lbrynet import conf
from lbrynet.p2p.Error import InvalidCurrencyError
@@ -15,11 +17,12 @@ class SettingsTest(unittest.TestCase):
def tearDown(self):
del os.environ['LBRY_TEST']
@staticmethod
def get_mock_config_instance():
def get_mock_config_instance(self):
settings = {'test': (str, '')}
env = conf.Env(**settings)
return conf.Config({}, settings, environment=env)
self.tmp_dir = tempfile.mkdtemp()
self.addCleanup(lambda : defer.succeed(shutil.rmtree(self.tmp_dir)))
return conf.Config({}, settings, environment=env, data_dir=self.tmp_dir, wallet_dir=self.tmp_dir, download_dir=self.tmp_dir)
def test_envvar_is_read(self):
settings = self.get_mock_config_instance()
@@ -72,20 +75,19 @@ class SettingsTest(unittest.TestCase):
out = settings.get('max_key_fee')
self.assertEqual(out, valid_setting)
def test_data_dir(self):
# check if these directories are returned as string and not unicode
# otherwise there will be problems when calling os.path.join on
# unicode directory names with string file names
self.assertEqual(str, type(conf.default_download_dir))
self.assertEqual(str, type(conf.default_data_dir))
self.assertEqual(str, type(conf.default_lbryum_dir))
settings = conf.Config({}, {})
self.assertEqual(str, type(settings.download_dir))
self.assertEqual(str, type(settings.data_dir))
self.assertEqual(str, type(settings.wallet_dir))
@skipIf('win' in sys.platform, 'fix me!')
def test_load_save_config_file(self):
# setup settings
adjustable_settings = {'data_dir': (str, conf.default_data_dir),
'lbryum_servers': (list, [])}
adjustable_settings = {'lbryum_servers': (list, [])}
env = conf.Env(**adjustable_settings)
settings = conf.Config({}, adjustable_settings, environment=env)
conf.settings = settings
@@ -110,13 +112,10 @@ class SettingsTest(unittest.TestCase):
def test_load_file(self):
settings = self.get_mock_config_instance()
# nonexistent file
conf.conf_file = 'monkey.yml'
with self.assertRaises(FileNotFoundError):
settings.load_conf_file_settings()
# invalid extensions
for filename in ('monkey.yymmll', 'monkey'):
conf.conf_file = filename
settings.file_name = filename
with open(os.path.join(self.tmp_dir, filename), "w"):
pass
with self.assertRaises(ValueError):
settings.load_conf_file_settings()
+1 -10
View File
@@ -14,13 +14,4 @@ commands =
orchstr8 download
coverage run -p --source={envsitepackagesdir}/lbrynet -m unittest integration.wallet.test_transactions.BasicTransactionTest
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.cli
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.AccountManagement
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.ClaimManagement.test_update_claim_holding_address
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.ClaimManagement.test_publishing_checks_all_accounts_for_certificate
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.ClaimManagement.test_updating_claim_includes_claim_value_in_balance_check
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.ClaimManagement.test_abandoning_claim_at_loss
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.ClaimManagement.test_abandoned_channel_with_signed_claims
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.ClaimManagement.test_regular_supports_and_tip_supports
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.ClaimManagement.test_create_update_and_abandon_claim
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.EpicAdventuresOfChris45
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands.TransactionCommandsTestCase
coverage run -p --source={envsitepackagesdir}/lbrynet -m twisted.trial --reactor=asyncio integration.wallet.test_commands