-
Notifications
You must be signed in to change notification settings - Fork 0
/
putup.py
75 lines (70 loc) · 1.92 KB
/
putup.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
import urllib2, os, shutil
STATUSURL='http://fuseki.net/putup/head'
STATUSPATH='head'
LIVE_BASE='/home/ernop/fuseki.net/public/putup/images'
from util import *
def dlstatus():
cmd='rsync -av [email protected]:/home/ernop/fuseki.net/public/putup/head .'
res=os.system(cmd)
if res:
import ipdb;ipdb.set_trace();print 'ipdb!'
print 'problem dling.'
return False
return True
def getstatus():
dlstatus()
res=open(STATUSPATH,'r').readlines()
status={}
for l in res:
l=l.strip()
if l.startswith('#'):continue
a,b=l.split('=')
status[a]=b
log(str(status))
return status
def putstatus(status):
writestatus(status)
cmd='rsync -av head [email protected]:/home/ernop/fuseki.net/public/putup/head'
log(cmd)
os.system(cmd)
def writestatus(status):
out=[]
for k,v in status.items():
out.append('%s=%s\n'%(str(k),str(v)))
outfp=open('head','w')
for o in out:
outfp.write(o)
outfp.close()
def putup(fp):
"""find the current HEAD. add 1. upload the image to that dir."""
if not getlock('head','putup %s'%fp):return False
status=getstatus()
if not status:
res['res']='failed to get status.'
return res
head, fn = os.path.split(fp)
fb, ext=os.path.splitext(fn)
headplusone=int(status['head'])+1
status['head']=str(headplusone)
newfn=str(headplusone)+ext
newfn=newfn.lower()
src=fp
local_dest=os.path.join('images',newfn)
shutil.copy(src, local_dest)
cmd='chmod 644 %s'%local_dest
os.system(cmd)
src=local_dest
dest=os.path.join(LIVE_BASE, newfn)
rsync_dest='[email protected]:'+dest
cmd='rsync -av "%s" "%s"'%(src, rsync_dest)
log(cmd)
res={}
cmdres=os.system(cmd)
if not cmdres:
res['res']='success'
else:
res['res']=cmdres
res['newfn']=newfn
putstatus(status)
unlock('head')
return res