mycelium-client 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mycelium_client/__about__.py +1 -0
- mycelium_client/__init__.py +0 -0
- mycelium_client/__main__.py +6 -0
- mycelium_client/cli/__init__.py +80 -0
- mycelium_client-0.1.0.dist-info/METADATA +43 -0
- mycelium_client-0.1.0.dist-info/RECORD +9 -0
- mycelium_client-0.1.0.dist-info/WHEEL +4 -0
- mycelium_client-0.1.0.dist-info/entry_points.txt +2 -0
- mycelium_client-0.1.0.dist-info/licenses/LICENSE.txt +9 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
File without changes
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import click
|
|
2
|
+
from os import environ
|
|
3
|
+
from requests import get
|
|
4
|
+
from json import loads
|
|
5
|
+
from urllib import parse
|
|
6
|
+
from random import shuffle
|
|
7
|
+
from tqdm import tqdm
|
|
8
|
+
from hashlib import sha256
|
|
9
|
+
from mycelium_client.__about__ import __version__
|
|
10
|
+
|
|
11
|
+
default_oak = environ.get("MYCELIUM_OAK", None)
|
|
12
|
+
oak_option_help = "Oak to fetch listings from. (Defaults to value of environment variable MYCELIUM_OAK if not specified; errors out if neither are specified.)"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@click.group(
|
|
16
|
+
context_settings={"help_option_names": ["-h", "--help"]},
|
|
17
|
+
invoke_without_command=True,
|
|
18
|
+
)
|
|
19
|
+
@click.version_option(version=__version__, prog_name="mycelium-client")
|
|
20
|
+
def mycelium_client():
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@click.command(name="show")
|
|
25
|
+
@click.option("--filter-hash", default=None, help="Hash to show listings for.")
|
|
26
|
+
@click.option("--oak", default=None, help=oak_option_help)
|
|
27
|
+
def show_hashes(filter_hash: str, oak: str):
|
|
28
|
+
if oak:
|
|
29
|
+
hashes = loads(get(oak).content)
|
|
30
|
+
elif default_oak:
|
|
31
|
+
hashes = loads(get(default_oak).content)
|
|
32
|
+
else:
|
|
33
|
+
raise click.ClickException("No Oak specified.")
|
|
34
|
+
if filter_hash:
|
|
35
|
+
if hashes.get(filter_hash):
|
|
36
|
+
click.echo(f"Hash: {filter_hash}")
|
|
37
|
+
for server, timestamp in hashes[filter_hash].items():
|
|
38
|
+
click.echo(f"* {server} (last submitted at {timestamp})")
|
|
39
|
+
else:
|
|
40
|
+
raise click.ClickException("No such hash.")
|
|
41
|
+
else:
|
|
42
|
+
for key, value in hashes.items():
|
|
43
|
+
click.echo(f"## Hash: {key}")
|
|
44
|
+
for server, timestamp in value.items():
|
|
45
|
+
click.echo(f"* {server} (last submitted at {timestamp})")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@click.command(name="fetch")
|
|
49
|
+
@click.argument("asset_hash")
|
|
50
|
+
@click.argument("output_file", default="output")
|
|
51
|
+
@click.option("--oak", default=None, help=oak_option_help)
|
|
52
|
+
def fetch_hash(asset_hash: str, output_file: str):
|
|
53
|
+
if oak:
|
|
54
|
+
hashes = loads(get(oak).content)
|
|
55
|
+
elif default_oak:
|
|
56
|
+
hashes = loads(get(default_oak).content)
|
|
57
|
+
else:
|
|
58
|
+
raise click.ClickException("No Oak specified.")
|
|
59
|
+
if hashes.get(asset_hash):
|
|
60
|
+
servers = list(hashes[
|
|
61
|
+
asset_hash
|
|
62
|
+
].keys()) # This might be using memory referencing under the hood, but doesn't matter. hashes will exit scope soon anyway.
|
|
63
|
+
shuffle(servers)
|
|
64
|
+
|
|
65
|
+
for i in tqdm(servers):
|
|
66
|
+
req = get(i).content
|
|
67
|
+
m = sha256()
|
|
68
|
+
m.update(req)
|
|
69
|
+
if m.hexdigest() == asset_hash:
|
|
70
|
+
click.echo("File located! Writing to disk...")
|
|
71
|
+
with open(output_file, "wb") as f:
|
|
72
|
+
f.write(req)
|
|
73
|
+
click.echo("Written!")
|
|
74
|
+
break
|
|
75
|
+
else:
|
|
76
|
+
raise click.ClickException("Hash not found.")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
mycelium_client.add_command(show_hashes)
|
|
80
|
+
mycelium_client.add_command(fetch_hash)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mycelium-client
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The official client for the Mycelium file-sharing protocol.
|
|
5
|
+
Author-email: PPPDUD <mojavesoft@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE.txt
|
|
8
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
9
|
+
Classifier: Programming Language :: Python
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
16
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
17
|
+
Requires-Python: >=3.8
|
|
18
|
+
Requires-Dist: click~=8.4
|
|
19
|
+
Requires-Dist: requests
|
|
20
|
+
Requires-Dist: tqdm
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# mycelium-client
|
|
24
|
+
|
|
25
|
+
[](https://pypi.org/project/mycelium-client)
|
|
26
|
+
[](https://pypi.org/project/mycelium-client)
|
|
27
|
+
|
|
28
|
+
-----
|
|
29
|
+
|
|
30
|
+
## Table of Contents
|
|
31
|
+
|
|
32
|
+
- [Installation](#installation)
|
|
33
|
+
- [License](#license)
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```console
|
|
38
|
+
pip install mycelium-client
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
`mycelium-client` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
mycelium_client/__about__.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
|
|
2
|
+
mycelium_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
mycelium_client/__main__.py,sha256=eOADwR4LodMtLedVaUoQuTho_jTgG9jTh_J_PbMT7X0,124
|
|
4
|
+
mycelium_client/cli/__init__.py,sha256=mwnS4Tc94KfFg87OLOq06iqRQRV5sKsFk901bYOXGRM,2766
|
|
5
|
+
mycelium_client-0.1.0.dist-info/METADATA,sha256=3c-iCSSeE4RU5YV_k21AOutJqPPyuBxbIMgnh52YkZk,1367
|
|
6
|
+
mycelium_client-0.1.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
7
|
+
mycelium_client-0.1.0.dist-info/entry_points.txt,sha256=iwOJ3acTBbgZk9Eec-jmS2M6Cb9AzI7I4WKAOdbglXA,72
|
|
8
|
+
mycelium_client-0.1.0.dist-info/licenses/LICENSE.txt,sha256=i1Jrem2zriU378LNqCUVut1dFMC5JXu0SdPey20NZbA,1094
|
|
9
|
+
mycelium_client-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-present PPPDUD <mojavesoft@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|