switch from config.version to config.app_version
This commit is contained in:
parent
8dc17071ce
commit
43aef86e7e
7 changed files with 86 additions and 22 deletions
|
|
@ -870,7 +870,7 @@ class DownloadQueue(metaclass=Singleton):
|
|||
)
|
||||
continue
|
||||
|
||||
LOG.info(f"Re-queuing item '{item_ref} {item.info.extras=}' for download.")
|
||||
LOG.info(f"Retrying item '{item_ref} {item.info.extras=}' for download.")
|
||||
|
||||
try:
|
||||
await self.clear([item.info._id], remove_file=False)
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ class Notification(metaclass=Singleton):
|
|||
self._file: Path = Path(file) if file else Path(config.config_path).joinpath("notifications.json")
|
||||
self._client: httpx.AsyncClient = client or httpx.AsyncClient()
|
||||
self._encoder: Encoder = encoder or Encoder()
|
||||
self._version = config.version
|
||||
self._version = config.app_version
|
||||
|
||||
if self._file.exists() and "600" != self._file.stat().st_mode:
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -109,10 +109,6 @@ class Config:
|
|||
pip_ignore_updates: bool = False
|
||||
"""Ignore pip package updates."""
|
||||
|
||||
# immutable config vars.
|
||||
version: str = APP_VERSION
|
||||
"The version of the application."
|
||||
|
||||
app_version: str = APP_VERSION
|
||||
"The version of the application, same as `version`."
|
||||
|
||||
|
|
@ -194,7 +190,6 @@ class Config:
|
|||
"The variables that are set manually."
|
||||
|
||||
_immutable: tuple = (
|
||||
"version",
|
||||
"__instance",
|
||||
"ytdl_options",
|
||||
"started",
|
||||
|
|
@ -241,7 +236,6 @@ class Config:
|
|||
"download_path",
|
||||
"keep_archive",
|
||||
"output_template",
|
||||
"version",
|
||||
"started",
|
||||
"remove_files",
|
||||
"ui_update_title",
|
||||
|
|
@ -457,6 +451,9 @@ class Config:
|
|||
)
|
||||
raise ValueError(msg)
|
||||
|
||||
if "dev-master" == self.app_version:
|
||||
self._version_via_git()
|
||||
|
||||
def _get_attributes(self) -> dict:
|
||||
attrs: dict = {}
|
||||
vClass: str = self.__class__
|
||||
|
|
@ -524,3 +521,66 @@ class Config:
|
|||
return YTDLP_VERSION
|
||||
except ImportError:
|
||||
return "0.0.0"
|
||||
|
||||
def _version_via_git(self):
|
||||
"""
|
||||
Updates the version of the application using git tags.
|
||||
This is used to set the version to the latest git tag.
|
||||
"""
|
||||
git_path: str = Path(__file__).parent / ".." / ".." / ".git"
|
||||
if not git_path.exists():
|
||||
return
|
||||
|
||||
try:
|
||||
import subprocess
|
||||
|
||||
branch_result = subprocess.run( # noqa: S603
|
||||
["git", "rev-parse", "--abbrev-ref", "HEAD"], # noqa: S607
|
||||
cwd=os.path.dirname(git_path),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
|
||||
if 0 != branch_result.returncode:
|
||||
logging.error(f"Git rev-parse failed: {branch_result.stderr.strip()}")
|
||||
return
|
||||
|
||||
branch_name: str = branch_result.stdout.strip()
|
||||
if not branch_name:
|
||||
logging.warning("Git branch name is empty.")
|
||||
return
|
||||
|
||||
commit_result = subprocess.run( # noqa: S603
|
||||
["git", "log", "-1", "--format=%ct_%H"], # noqa: S607
|
||||
cwd=os.path.dirname(git_path),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
|
||||
if 0 != commit_result.returncode:
|
||||
logging.error(f"Git log failed: {commit_result.stderr.strip()}")
|
||||
return
|
||||
|
||||
commit_info: str = commit_result.stdout.strip()
|
||||
if not commit_info:
|
||||
logging.warning("Git commit info is empty.")
|
||||
return
|
||||
|
||||
commit_date, commit_sha = commit_info.split("_", 1)
|
||||
commit_date = time.strftime("%Y%m%d", time.localtime(int(commit_date)))
|
||||
|
||||
self.app_version = f"{branch_name}-{commit_date}-{commit_sha[:8]}"
|
||||
self.app_branch = branch_name
|
||||
self.app_commit_sha = commit_sha
|
||||
self.app_build_date = commit_date
|
||||
version_data = {
|
||||
"version": self.app_version,
|
||||
"branch": self.app_branch,
|
||||
"commit": self.app_commit_sha,
|
||||
"build_date": self.app_build_date,
|
||||
}
|
||||
logging.info(f"Application version info set to '{version_data}'")
|
||||
except Exception as e:
|
||||
logging.error(f"Error while getting git version: {e!s}")
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ class Main:
|
|||
|
||||
def started(_):
|
||||
LOG.info("=" * 40)
|
||||
LOG.info(f"YTPTube {self._config.version} - started on http://{host}:{port}{self._config.base_path}")
|
||||
LOG.info(f"YTPTube {self._config.app_version} - started on http://{host}:{port}{self._config.base_path}")
|
||||
LOG.info("=" * 40)
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ async def get_thumbnail(request: Request, config: Config) -> Response:
|
|||
"proxy": ytdlp_args.get("proxy", None),
|
||||
"headers": {
|
||||
"User-Agent": ytdlp_args.get(
|
||||
"user_agent", request.headers.get("User-Agent", f"YTPTube/{config.version}")
|
||||
"user_agent", request.headers.get("User-Agent", f"YTPTube/{config.app_version}")
|
||||
),
|
||||
},
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ async def get_background(request: Request, config: Config, cache: Cache) -> Resp
|
|||
opts = {
|
||||
"proxy": ytdlp_args.get("proxy", None),
|
||||
"headers": {
|
||||
"User-Agent": ytdlp_args.get("user_agent", f"YTPTube/{config.version}"),
|
||||
"User-Agent": ytdlp_args.get("user_agent", f"YTPTube/{config.app_version}"),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@
|
|||
<div class="column is-8-mobile">
|
||||
<div class="has-text-left" v-if="config.app?.app_version">
|
||||
© {{ Year }} - <NuxtLink href="https://github.com/ArabCoders/ytptube" target="_blank">YTPTube</NuxtLink>
|
||||
<span class="is-hidden-mobile"
|
||||
<span class="is-hidden-mobile has-tooltip"
|
||||
v-tooltip="`Build Date: ${config.app?.app_build_date}, Branch: ${config.app?.app_branch}, commit: ${config.app?.app_commit_sha}`">
|
||||
({{ config?.app?.app_version || 'unknown' }})</span>
|
||||
- <NuxtLink target="_blank" href="https://github.com/yt-dlp/yt-dlp">yt-dlp</NuxtLink>
|
||||
|
|
|
|||
|
|
@ -47,13 +47,17 @@ hr {
|
|||
<hr>
|
||||
<ul>
|
||||
<li v-for="commit in log.commits" :key="commit.sha">
|
||||
<strong>{{ ucFirst(commit.message).replace(/\.$/, "") }}.</strong> -
|
||||
<strong>
|
||||
{{ ucFirst(commit.message).replace(/\.$/, "") }}.
|
||||
</strong> -
|
||||
<small>
|
||||
<NuxtLink :to="`${REPO}/commit/${commit.full_sha}`" target="_blank">
|
||||
<span class="has-tooltip" v-tooltip="`SHA: ${commit.full_sha} - Date: ${commit.date}`">
|
||||
{{ moment(commit.date).fromNow() }}
|
||||
</span>
|
||||
</NuxtLink>
|
||||
<span v-tooltip="'Code is at this commit.'" v-if="commit.full_sha === app_sha" class="icon has-text-success"><i
|
||||
class="fas fa-check" /></span>
|
||||
</small>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
@ -80,19 +84,19 @@ const REPO = `https://github.com/arabcoders/${PROJECT}`
|
|||
const REPO_URL = `https://arabcoders.github.io/${PROJECT}/CHANGELOG.json?version={version}`
|
||||
|
||||
const logs = ref<changelogs>([])
|
||||
const api_version = ref('')
|
||||
const api_branch = ref('')
|
||||
const api_sha = ref('')
|
||||
const app_version = ref('')
|
||||
const app_branch = ref('')
|
||||
const app_sha = ref('')
|
||||
const isLoading = ref(true)
|
||||
|
||||
const loadContent = async () => {
|
||||
if ('' === api_version.value || logs.value.length > 0) {
|
||||
if ('' === app_version.value || logs.value.length > 0) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
try {
|
||||
const changes = await fetch(REPO_URL.replace('{branch}', api_branch.value).replace('{version}', api_version.value))
|
||||
const changes = await fetch(REPO_URL.replace('{branch}', app_branch.value).replace('{version}', app_version.value))
|
||||
logs.value = await changes.json()
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
|
|
@ -110,7 +114,7 @@ const loadContent = async () => {
|
|||
}
|
||||
|
||||
const isInstalled = (log: changeset) => {
|
||||
const installed = String(api_sha.value)
|
||||
const installed = String(app_sha.value)
|
||||
|
||||
if (log.full_sha.startsWith(installed)) {
|
||||
return true
|
||||
|
|
@ -127,9 +131,9 @@ const isInstalled = (log: changeset) => {
|
|||
|
||||
onMounted(async () => {
|
||||
await awaiter(config.isLoaded)
|
||||
api_branch.value = config.app.app_branch
|
||||
api_version.value = config.app.app_version
|
||||
api_sha.value = config.app.app_commit_sha
|
||||
app_branch.value = config.app.app_branch
|
||||
app_version.value = config.app.app_version
|
||||
app_sha.value = config.app.app_commit_sha
|
||||
loadContent()
|
||||
})
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in a new issue