-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush-packages.py
84 lines (72 loc) · 1.47 KB
/
push-packages.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import re
from ftplib import FTP
import util
import sys
host = 'office.lan'
user = 'user'
password = 'password'
remote = '/manjaro/'
path = util.get_download_path()
files = util.get_files_in_dir(path)
# updated packages
pkgs = {}
for f in files:
if f.endswith('.sig'):
continue
pk = util.get_package_info(f)
if pk is None:
continue
pkgs[pk['name']] = pk
print(str(len(pkgs)) + ' packages\n')
# connect ftp
ftp = None
ftpfiles=[]
try:
ftp = FTP(host, user, password)
ftp.set_pasv(False)
ftp.cwd(remote)
ftpfiles = ftp.nlst()
except Exception as e:
print(e)
sys.exit()
# del old
print('\ndeleting old packages...')
delcount = 0
for f in ftpfiles:
pk = util.get_package_info(f)
if pk is None:
continue
pkg = pk['name']
ver = pk['version']
# are we related to new files?
if pkg not in pkgs:
continue
# delete older versions
if ver != pkgs[pkg]['version']:
try:
ftp.delete(f)
ftp.delete(f + '.sig')
print(pkg + ' ' + ver)
delcount += 1
except Exception as e:
print(f + ' -> doesnt exist or is root')
# push new files
print('\nadding new packages...')
pushcount = 0
for f in files:
filepath = path + f
pk = util.get_package_info(f)
try:
with open(filepath, 'rb') as openfile:
ftp.storbinary(f'STOR {f}', openfile)
if pk is None:
print(f)
else:
print(pk['name'] + ' ' + pk['version'])
pushcount += 1
except Exception as e:
print(e)
ftp.quit()
print()
print(str(delcount) + ' deletions')
print(str(pushcount) + ' additions')