Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
yzqzss committed Sep 15, 2024
1 parent 25f97f6 commit 0956343
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 31 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ __pycache__

index-v2.json
sourceCodes.txt
success_repos.txt
success_repos.txt

.pdm-python
23 changes: 1 addition & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@
# F-Droid_src
# fdroid-push-swh

## Install

```shell
pip install -r requirements.txt
```

## Usage

```shell
python3 main.py --help
```

```shell
usage: main.py [-h] [--refresh] [--swh-token SWH_TOKEN] [--list-only]

options:
-h, --help show this help message and exit
--refresh Redownload index-v2.json
--swh-token SWH_TOKEN
--list-only Only list repos to sourceCodes.txt, do not submit to SWH
```
188 changes: 188 additions & 0 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[project]
name = "fdroid_push_swh"
version = "0.1.0"
description = "aaaa"
authors = [
{name = "yzqzss", email = "[email protected]"},
]
dependencies = [
"requests",
"tqdm",
"httpx",
]
requires-python = ">=3.12"
readme = "README.md"
license = {text = "AGPL"}

[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[project.scripts]
fdroid-push-swh = "fdroid_push_swh:main"

[tool.pdm]
distribution = true
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

8 changes: 8 additions & 0 deletions src/fdroid_push_swh/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import logging
from fdroid_push_swh.main import main as lib_main

import asyncio

def main():
logging.basicConfig(level=logging.INFO)
asyncio.run(lib_main())
10 changes: 5 additions & 5 deletions main.py → src/fdroid_push_swh/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import tqdm
import argparse

from swh import git_swh
from fdroid_push_swh.swh import git_swh

json_url = 'https://f-droid.org/repo/index-v2.json'
json_cache = Path('index-v2.json')
Expand All @@ -28,12 +28,12 @@ async def main():
else:
r = requests.get(json_url, stream=True)
r.raise_for_status()
data = b''
_data = b''
for chunk in tqdm.tqdm(r.iter_content(chunk_size=1024 * 1024), unit='chunk', unit_scale=True):
data += chunk
_data += chunk
with json_cache.open('wb') as f:
f.write(data)
data: dict = json.loads(data)
f.write(_data)
data: dict = json.loads(_data)
print(len(data)//1024//1024, 'MiB')
packages = data.get('packages', {})

Expand Down
2 changes: 2 additions & 0 deletions swh.py → src/fdroid_push_swh/swh.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ async def post_git_url(client: httpx.AsyncClient, url: str, swh_token: str):
save_request_status = r_json['save_request_status']
request_url = r_json['request_url']
return

# Why I commented out the following code? IDK what I thought 1 year ago (2023), lol.
while True:
await asyncio.sleep(10)
r = await client.get(request_url, headers=headers, follow_redirects=True)
Expand Down
Empty file added tests/__init__.py
Empty file.

0 comments on commit 0956343

Please sign in to comment.