summaryrefslogtreecommitdiff
path: root/repo/bin/upload-poolfiles
blob: d0f52e80220b3472cabc4ad106e8e093980f09d2 (plain)
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
#!/usr/bin/python3

import os
import psycopg2, subprocess

os.environ['PATH'] += ':/srv/apt/repo/bin' # path to upload-to-s3

pg = psycopg2.connect('service=pgapt')
cur = pg.cursor()

def upload_source_files():
  while True:
      cur.execute("""SELECT directory, filename FROM sourcefile WHERE upload IS NULL LIMIT 1 FOR UPDATE SKIP LOCKED""")
      sourcefile = cur.fetchone()
      if not sourcefile: # we are done
          return

      path = "%s/%s" % (sourcefile[0], sourcefile[1])
      filename = sourcefile[1]

      success = subprocess.call(['upload-to-s3', path])
      if success == 0:
          upload = 't'
      else:
          upload = 'f'

      cur.execute("""UPDATE sourcefile SET upload = %s WHERE filename = %s""",
              [upload, filename])

      pg.commit()

def upload_binary_files():
  while True:
      cur.execute("""SELECT package, version, arch, c->>'filename' FROM package WHERE upload IS NULL LIMIT 1 FOR UPDATE SKIP LOCKED""")
      packagerow = cur.fetchone()
      if not packagerow: # we are done
          return

      package = packagerow[0]
      version = packagerow[1]
      arch = packagerow[2]
      path = packagerow[3]

      success = subprocess.call(['upload-to-s3', path])
      if success == 0:
          upload = 't'
      else:
          upload = 'f'

      cur.execute("""UPDATE package SET upload = %s WHERE (package, version, arch) = (%s, %s, %s)""",
              [upload, package, version, arch])

      pg.commit()

upload_source_files()
upload_binary_files()