forked from gammu/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_file.py
executable file
·54 lines (36 loc) · 1 KB
/
add_file.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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# vim: expandtab sw=4 ts=4 sts=4:
'''
Wammu website
Takes a filename and inserts it into downloads database.
'''
import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import sys
sys.path = ['../'] + sys.path
import hashlib
from downloads.models import Release, Download
if len(sys.argv) < 6:
print 'Usage: add_file.py /base/path program version type file...'
sys.exit(1)
release = Release.objects.get(program = sys.argv[2], version = sys.argv[3])
dlpath = sys.argv[1]
while dlpath[-1] == '/':
dlpath = dlpath[:-1]
for f in sys.argv[5:]:
print "Adding %s..." % f
path, filename = os.path.split(f)
data = open(f).read()
dl = Download()
dl.release = release
md5 = hashlib.md5()
md5.update(data)
dl.md5 = md5.hexdigest()
sha1 = hashlib.sha1()
sha1.update(data)
dl.sha1 = sha1.hexdigest()
dl.size = len(data)
dl.platform = sys.argv[4]
dl.location = '%s/%s' % (dlpath, filename)
dl.save()