配置读取;解析文件目录,生成db.json
This commit is contained in:
commit
0962af6579
4 changed files with 197 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.vscode
|
||||
config.ini
|
15
Pipfile
Normal file
15
Pipfile
Normal file
|
@ -0,0 +1,15 @@
|
|||
[[source]]
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
|
||||
[dev-packages]
|
||||
black = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.9"
|
||||
|
||||
[pipenv]
|
||||
allow_prereleases = true
|
129
Pipfile.lock
generated
Normal file
129
Pipfile.lock
generated
Normal file
|
@ -0,0 +1,129 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "841a2d369692928656cccaf937b8e83c04af6dfa2f7addb75236739b24bff7fa"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.9"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {},
|
||||
"develop": {
|
||||
"black": {
|
||||
"hashes": [
|
||||
"sha256:6eb7448da9143ee65b856a5f3676b7dda98ad9abe0f87fce8c59291f15e82a5b",
|
||||
"sha256:a9952229092e325fe5f3dae56d81f639b23f7131eb840781947e4b2886030f33"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==21.10b0"
|
||||
},
|
||||
"click": {
|
||||
"hashes": [
|
||||
"sha256:353f466495adaeb40b6b5f592f9f91cb22372351c84caeb068132442a4518ef3",
|
||||
"sha256:410e932b050f5eed773c4cda94de75971c89cdb3155a72a0831139a79e5ecb5b"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==8.0.3"
|
||||
},
|
||||
"mypy-extensions": {
|
||||
"hashes": [
|
||||
"sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d",
|
||||
"sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"
|
||||
],
|
||||
"version": "==0.4.3"
|
||||
},
|
||||
"pathspec": {
|
||||
"hashes": [
|
||||
"sha256:7d15c4ddb0b5c802d161efc417ec1a2558ea2653c2e8ad9c19098201dc1c993a",
|
||||
"sha256:e564499435a2673d586f6b2130bb5b95f04a3ba06f81b8f895b651a3c76aabb1"
|
||||
],
|
||||
"version": "==0.9.0"
|
||||
},
|
||||
"platformdirs": {
|
||||
"hashes": [
|
||||
"sha256:367a5e80b3d04d2428ffa76d33f124cf11e8fff2acdaa9b43d545f5c7d661ef2",
|
||||
"sha256:8868bbe3c3c80d42f20156f22e7131d2fb321f5bc86a2a345375c6481a67021d"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==2.4.0"
|
||||
},
|
||||
"regex": {
|
||||
"hashes": [
|
||||
"sha256:04ed2819b7c9d83ae3dfbbfea770f0d0780c732b5cbbd8269aa910dbe0205361",
|
||||
"sha256:05d8ddf6bb4f50342ecddee4deb621588a013afe13d9c77cf6eb58c5ad1bc21f",
|
||||
"sha256:09c9ff0c67f4949f14b2ddf935bc36cafd0fd4db6d3334a3e5a24a532773b2d1",
|
||||
"sha256:0aa74d18236f8a31b911caafc28aed2a8444bcca8e61eb377949771f84710ada",
|
||||
"sha256:0da1b6e39affa1b6da2106745c9d73f576ffe4484cbdfbd5e1c9b9872532eec8",
|
||||
"sha256:0ef40aa8e39dff52480e21c38b36486a0c256b3b93d0094e7a06ab517a246994",
|
||||
"sha256:197331fffc684af34534328a9e4a7d0a118d9a838b393b80abb7af4f709acad7",
|
||||
"sha256:1b4cf110002a8b6d039d2d4bed15095e5ddf3d9e4aa5eb67476eba0256c93893",
|
||||
"sha256:20675d8bd3c2cc8dbfafd60a220ec04d0018564f101f80a64e56f4e4ed0afe55",
|
||||
"sha256:29dfb06ef5c47b41dcb3bf4fdf2983c048711e16a3bf74814be14089a1933b3c",
|
||||
"sha256:2a394085589dc549ad976290c93f688620af898ac49d46269ad6cdf3ef29bc58",
|
||||
"sha256:2f189743257300e9b3a3b4fdea10f46bf6d33ef580856b2a6bfc2073653c2287",
|
||||
"sha256:3383f0d47e5e343fa5facd87a6f95de101c488d0aec1f41da00fcc019179aefc",
|
||||
"sha256:495d98445daaa4657093fc54a5d53cffe41acec5c1edac901aac8061fc7c2f85",
|
||||
"sha256:4b4d2b514c30a9c8f80f5d78ec978719f1c3823662a5ba0809c03f0cad4c5de6",
|
||||
"sha256:50ceaaaa88abec74393301336a2494734386cf3cafa51dde26367b139fe86336",
|
||||
"sha256:5867bc04011ee03ed3160df2f378cdee732aa3ed070b4760b029ebefbea6116c",
|
||||
"sha256:5b4036abc6b3307146a81358cd4d4d091bd9a2fe3edaca9b95f66e7ba6d06e20",
|
||||
"sha256:68939d7fdc417174ee4975fd78aec41ae484de606add311d1387011484ce1da3",
|
||||
"sha256:69e047c969f7b952bc55274e2b5189117ff2322b049a4c9143f94af8976b55f6",
|
||||
"sha256:6a1ed9aef9748d76cf39e08529be9209bdfcf34e70c9133abf966d954a59bc6d",
|
||||
"sha256:6b3f8852cf597388851c1d3d1073fb3694e5647303c002813aa230d41a9ec5fc",
|
||||
"sha256:6c26d8d18ae84584d58e34c9ac5c8528110483d080dca77626fd62cdb316c0a2",
|
||||
"sha256:724a1601ae73521e1e9fda0a3015915ae0d1931772802fcf7f0dd83f111d11d2",
|
||||
"sha256:75ad34d49fdd9faef0f4ccf9286c63ee9610d4664d92b13cdb4c4407e834921c",
|
||||
"sha256:767cb9ba1e6151692fd27449f06550fbdbd82b42236b5a31bac862a1da628860",
|
||||
"sha256:78c80cd9939b42eeac4f0556f689a6eda987b81678149071853391b922d98f64",
|
||||
"sha256:7f44ee70fa7f346551550f8ec4650a4354b9494c0d1dfa08100fe056d6910388",
|
||||
"sha256:8228e75d340e48b360d5e963acf1332b5c9080f73ec6ce8cf483ec7e0542f2dd",
|
||||
"sha256:86baabf4f346b612665ab9f5f38377def21f824c89574e71c67e5c38e4971e5c",
|
||||
"sha256:8ae9d75bbfebd402e1254b09a721c037ec9f018750a5091bea8c705729bbf5c1",
|
||||
"sha256:95fa9665d8dac10c109a3dcc7d476b7f27b32fe22190b433c2a2b7eb903aa646",
|
||||
"sha256:a3abab9f5d487061b0d99beb5ff2d1619a3652c8b785bc66aca7682d8b7d4116",
|
||||
"sha256:a5bb5637a2fe6d8710d5f0b5600556c64fb3d49449502e9dece2038a9753e8b8",
|
||||
"sha256:b06599e60c421fb0512a2cef8553e6ea072a72081e51158f487e2d207b947aa9",
|
||||
"sha256:b0bd3cccb9e6e61ed64a01075353ded1e012b8c4af222496eb5478dc48a5c0b4",
|
||||
"sha256:b662e04e0fc8f3b99d9beacecc5e000b9a68bdb25ba5b64211ebe263e907f3a2",
|
||||
"sha256:b77c919379409ae92a5b13ef2452c509632efaa40b926fab9eac7839ae9a266a",
|
||||
"sha256:c1f3b0f23437eea6c1781bcc7d1d14f7c8a3032142ac660dc7ca43ba1a139e30",
|
||||
"sha256:c61568c1633abfddd21552a261d3e1a83eda7e3fb1d46e148d61fd41d5541a8d",
|
||||
"sha256:cc93c277d6793a26cdb9bcadc6d6d9db9c6a6cf2aae207bbaef2f16d53570d43",
|
||||
"sha256:ce0625900e4d6d9a43f50e897f6aaa1a52e5e4931f994a1b8e9f6a4e49185e4e",
|
||||
"sha256:cef78eab573f07378f26662f24d28c706e6765a95980cce98a91d025d481ab95",
|
||||
"sha256:cf725b99f897b8e6d24d8b102320a31551530d7aae1e2fe42eb1ee85173f57b6",
|
||||
"sha256:d9108787c320940acc6676000716c3dc1734db9e14facbd98c13920972aee21b",
|
||||
"sha256:dd31271de74c8f3e296644f9a12d9ad60bdc3fc8d3b8e8a26ccbf777169e5a0d",
|
||||
"sha256:e4f6741b5506cbad28bfc46397c2e267ca59b357c075ea6b68f7781c5a8b150a",
|
||||
"sha256:e829fc2a1bcbb18c6579fd5fb563b93f25973b0451cf4e2a22933c991792e2cb",
|
||||
"sha256:ea372838910264443ad233a92a20279574b7f0e9743b5e5de526e274895b7274"
|
||||
],
|
||||
"version": "==2021.11.1"
|
||||
},
|
||||
"tomli": {
|
||||
"hashes": [
|
||||
"sha256:c6ce0015eb38820eaf32b5db832dbc26deb3dd427bd5f6556cf0acac2c214fee",
|
||||
"sha256:f04066f68f5554911363063a30b108d2b5a5b1a010aa8b6132af78489fe3aade"
|
||||
],
|
||||
"markers": "python_version >= '3.6'",
|
||||
"version": "==1.2.2"
|
||||
},
|
||||
"typing-extensions": {
|
||||
"hashes": [
|
||||
"sha256:49f75d16ff11f1cd258e1b988ccff82a3ca5570217d7ad8c5f48205dd99a677e",
|
||||
"sha256:d8226d10bc02a29bcc81df19a26e56a9647f8b0a6d4a83924139f4a8b01f17b7",
|
||||
"sha256:f1d25edafde516b146ecd0613dabcc61409817af4766fbbcfb8d1ad4ec441a34"
|
||||
],
|
||||
"version": "==3.10.0.2"
|
||||
}
|
||||
}
|
||||
}
|
51
manage.py
Normal file
51
manage.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
from configparser import ConfigParser
|
||||
from pathlib import Path
|
||||
from json import dump
|
||||
|
||||
config = ConfigParser()
|
||||
|
||||
conf = config.read("config.ini")
|
||||
|
||||
options = {"ftp": ["host", "user", "pass", "lftp"], "file": ["local", "remote"]}
|
||||
|
||||
|
||||
def check_config_valid(config: ConfigParser, options: dict[str, list[str]]) -> bool:
|
||||
for sec in options:
|
||||
if not config.has_section(sec):
|
||||
return False
|
||||
for opt in options[sec]:
|
||||
if not config.has_option(sec, opt):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def default_config(config: ConfigParser, options: dict[str, list[str]]) -> None:
|
||||
config.clear()
|
||||
for sec in options:
|
||||
config.add_section(sec)
|
||||
for opt in options[sec]:
|
||||
config[sec][opt] = ""
|
||||
with open("config.ini", "w") as f:
|
||||
config.write(f)
|
||||
|
||||
|
||||
if not check_config_valid(config, options):
|
||||
default_config(config, options)
|
||||
|
||||
|
||||
def generate_db(config: ConfigParser) -> None:
|
||||
local_dir = Path(config["file"]["local"])
|
||||
categories = Path(local_dir, "categories")
|
||||
output = []
|
||||
for category in categories.iterdir():
|
||||
if not category.is_dir():
|
||||
continue
|
||||
output_category = {"name": category.name, "files": []}
|
||||
for file in category.iterdir():
|
||||
output_category["files"].append(file.name)
|
||||
output.append(output_category)
|
||||
with open(Path(local_dir, "db.json"), "w") as f:
|
||||
dump(output, f)
|
||||
|
||||
|
||||
generate_db(config)
|
Loading…
Reference in a new issue