Created
February 2, 2016 17:29
-
-
Save AlexTalker/01c8685b912fb96ef29c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from sys import argv | |
from os import listdir, symlink, unlink | |
from os.path import isfile, join, getctime | |
from fnmatch import fnmatch | |
from datetime import datetime, date | |
from subprocess import run, Popen, PIPE | |
from ftpush import ftpush | |
from parse_db import DBReader | |
REPODIR = 'repo' | |
REPONAME = 'alextalker' | |
PKGDIR_x86_64 = join(REPODIR, 'x86_64') | |
ROOT = '/htdocs/aurrepo' | |
tday = date.today() | |
tday = datetime.combine(tday, datetime.min.time()) | |
def is_fresh_package(d, f): | |
fn = join(d,f) | |
if isfile(fn) and fnmatch(f, '*.pkg.tar.xz'): | |
t = datetime.fromtimestamp(getctime(fn)) | |
if t >= tday: | |
print(fn,t) | |
return True | |
return False | |
only_package_names = [] | |
for d in argv[1:]: | |
only_package_names += [(d,f) for f in listdir(d) if is_fresh_package(d,f)] | |
db = DBReader(join(PKGDIR_x86_64, REPONAME + '.db.tar.xz')) | |
old_files = [] | |
files = [] | |
for d,f in only_package_names: | |
pkg = join(PKGDIR_x86_64, f) | |
files.append(pkg) | |
try: | |
unlink(pkg) | |
except FileNotFoundError: | |
pass | |
symlink(join('..', '..', d,f), pkg) | |
if d in db: | |
old_files.append(db[d]['filename']) | |
del db | |
# dirs = list(set([d for d,_ in only_package_names])) | |
# old_files = Popen(['./get-older-package-names.zsh', join(PKGDIR_x86_64, REPONAME)] + dirs, stdout=PIPE) | |
# old_files = old_files.stdout.read().decode().split(' ') | |
files = [join(PKGDIR_x86_64, REPONAME + '.db.tar.xz')] + files | |
run(['repo-add', '-R'] + files) | |
# Push it out | |
ftpush([ROOT], [old_files], 'upload-to-repo.ini', True) # Clean up on the server side | |
ftpush([ROOT], [files], 'upload-to-repo.ini') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment