Revert changes to cli, apply suggestions

This commit is contained in:
Miroslav Kovar 2019-10-11 20:52:51 +02:00 committed by Lex Berezhny
parent 869be3e361
commit d4d1d87680
4 changed files with 12 additions and 15 deletions

View file

@ -2810,7 +2810,7 @@ class Daemon(metaclass=JSONRPCServerType):
@requires(WALLET_COMPONENT, STREAM_MANAGER_COMPONENT, BLOB_COMPONENT, DATABASE_COMPONENT)
async def jsonrpc_stream_update(
self, claim_id, bid=None, file_path=None, file_name=None,
self, claim_id, bid=None, file_path=None,
channel_id=None, channel_name=None, channel_account_id=None, clear_channel=False,
account_id=None, wallet_id=None, claim_address=None, funding_account_ids=None,
preview=False, blocking=False, replace=False, **kwargs):
@ -2979,7 +2979,7 @@ class Daemon(metaclass=JSONRPCServerType):
claim.stream.update(file_path=file_path, **kwargs)
else:
claim = Claim.from_bytes(old_txo.claim.to_bytes())
claim.stream.update(file_path=file_path, file_name=file_name, **kwargs)
claim.stream.update(file_path=file_path, **kwargs)
tx = await Transaction.claim_update(
old_txo, claim, amount, claim_address, funding_accounts, funding_accounts[0], channel
)
@ -2988,13 +2988,10 @@ class Daemon(metaclass=JSONRPCServerType):
stream_hash = None
if not preview:
old_stream_hash = await self.storage.get_stream_hash_for_sd_hash(old_txo.claim.stream.source.sd_hash)
old_stream = self.stream_manager.get_stream_by_stream_hash(old_stream_hash)
if not file_path and file_name and old_stream:
old_path, _ = os.path.split(old_stream.full_path)
file_path = os.path.join(old_path, file_name)
if file_path:
if old_stream:
await self.stream_manager.delete_stream(old_stream, delete_file=False)
if file_path is not None:
if old_stream_hash:
stream_to_delete = self.stream_manager.get_stream_by_stream_hash(old_stream_hash)
await self.stream_manager.delete_stream(stream_to_delete, delete_file=False)
file_stream = await self.stream_manager.create_stream(file_path)
new_txo.claim.stream.source.sd_hash = file_stream.sd_hash
new_txo.script.generate()

View file

@ -197,9 +197,9 @@ class CommandTestCase(IntegrationTestCase):
""" Synchronous version of `out` method. """
return json.loads(jsonrpc_dumps_pretty(value, ledger=self.ledger))['result']
def create_tempfile(self, data=None, prefix=None, suffix=None, dir=None):
dir = dir or self.daemon.conf.download_dir
file = tempfile.NamedTemporaryFile(prefix=prefix, suffix=suffix, dir=dir)
def create_tempfile(self, data=None, prefix=None, suffix=None, dir_path=None):
dir_path = dir_path or self.daemon.conf.download_dir
file = tempfile.NamedTemporaryFile(prefix=prefix, suffix=suffix, dir=dir_path)
file.write(data)
file.flush()

View file

@ -103,8 +103,8 @@ class FileCommands(CommandTestCase):
# Update the stream and assert the file name is not sanitized, but the suggested file name is
prefix, suffix = 'derpyderp?', '.ext.'
san_prefix, san_suffix = 'derpyderp', '.ext'
new_file_name = os.path.basename(self.create_tempfile(data=b'amazing content', prefix=prefix, suffix=suffix))
tx = await self.stream_update(claim_id, file_name=new_file_name)
new_file_path = self.create_tempfile(data=b'amazing content', prefix=prefix, suffix=suffix)
tx = await self.stream_update(claim_id, file_path=new_file_path)
full_path = (await self.daemon.jsonrpc_get('lbry://' + claim_name, save_file=True)).full_path
updated_stream = self.daemon.jsonrpc_file_list()[0]

View file

@ -78,7 +78,7 @@ class TestStreamDescriptor(AsyncioTestCase):
self.sd_dict['blobs'][-2]['length'] = 0
await self._test_invalid_sd()
async def test_sanitize_file_name(self):
def test_sanitize_file_name(self):
test_cases = [' t/-?t|.g.ext ', 'end_dot .', '.file\0\0', 'test n\16ame.ext', 'COM8', 'LPT2', '']
expected = ['t-t.g.ext', 'end_dot', '.file', 'test name.ext', '', '', '']
actual = [sanitize_file_name(tc) for tc in test_cases]