3
# Copyright (C) 2007 Julian Andres Klode <jak@jak-linux.org>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
# - Be portable (use right seperator)
27
Upload a folder to a ftp site, create indexes and remove obsolete files
28
and folders on target.
32
__copyright__ = 'Copyright (C) 2007 Julian Andres Klode'
35
from os.path import exists as path_exists
45
if dir[:7] == 'http://' or dir[:6] == 'ftp://' or dir[:8] == 'https://':
47
local = open('/tmp/.rev.gz', 'wb')
48
remote = urllib2.urlopen(ndname(dir) + '.rev.gz')
49
local.write(remote.read())
53
if path_exists(dir + ".rev.gz"):
54
from ftpsynclib.tuned_gzip import GzipFile
55
rev = GzipFile(dir + ".rev.gz", "rb")
59
print 'E: Folder %s is no ftpsync repo' % dir
64
if path_exists(dir+ '.ignore'): ignore+=file(dir + '.ignore').read().split()
68
'''Run the status action'''
69
ignore=get_ignore(dir)
70
from ftpsynclib.changes import changes
71
print changes(dir, ignore).msg()
74
'''Write a new config file'''
75
from os import environ
78
conf = ftpsynclib.conf(dname + '.ftpsync')
79
conf['author'] = 'My name'
80
conf['email'] = 'user@localhost'
81
conf['host'] = 'localhost'
82
conf['user'] = 'anonymous'
84
conf['passwd'] = 'pass'
85
conf.read(ndname(environ['HOME']) + '.ftpsync')
87
new_conf['author'] = raw_input('Name [%s]:' % conf['author'])
88
new_conf['email'] = raw_input('E-Mail [%s]:' % conf['email'])
89
new_conf['host'] = raw_input('FTP host [%s]:' % conf['host'])
90
new_conf['path'] = raw_input('FTP path [%s]:' % conf['path'])
91
new_conf['user'] = raw_input('FTP user [%s]:' % conf['user'])
92
new_conf['passwd'] = raw_input('FTP pass [%s]:' % conf['passwd'])
97
def cmd_commit(dir, index=True, clean=False):
98
'''Run the commit action'''
99
ignore=get_ignore(dir)
100
from ftpsynclib import conf, progressBar
101
c = conf(dir + '.ftpsync')
103
from ftpsynclib.html_index import html_index
104
html_index(dir, '/', True, ignore)
106
from ftpsynclib.changes import changes
107
a = changes(dir, ignore, clean)
109
if clean: a.rmfiles+= ['.rev.gz', '.jak.gz']
110
else: a.files+=['.rev.gz', '.jak.gz']
111
from ftpsynclib.upload import FTP
112
go = FTP(host=c['host'], user=c['user'], passwd=c['passwd'], path=c['path'])
113
for i in a.dirs: go.mkd(i)
114
for i in a.rmfiles: go.delete(i)
115
for i in a.rmdirs: go.rmd(i)
117
if len(a.cfiles + a.files):
118
from os.path import getsize as filesize
121
# Calculate the size of all files
122
for i in a.cfiles + a.files:
123
maxValue += filesize(dir + i)
124
# Initialize the progress bar
125
myBar = progressBar(maxValue = maxValue)
127
for i in a.cfiles + a.files:
128
go.upload(file=dir + i, target=i, bar=myBar)
131
if len(sys.argv) > 2:
132
dir = ndname(sys.argv[2])
137
if not len(sys.argv) in [2,3]:
138
print 'ftpsync %s, %s' % (__version__, __copyright__)
139
print 'usage: ftpsync [command] [folder]'
142
print ' init Initialize a ftpsync repo'
143
print ' clean Remove all files'
144
print ' commit Upload all Changes'
145
print ' status Show the current status'
146
print ' log Display Log'
148
print 'To configure the default settings for your account, run'
149
print '"ftpsync init" in your home folder'
151
elif sys.argv[1] in ['init', 'initialize']:
153
elif sys.argv[1] in ['log', 'l']:
155
elif not path_exists(dir + '.ftpsync'):
156
print 'E: Folder %s is no ftpsync repo' % dir
158
elif sys.argv[1] in ['clean']:
159
cmd_commit(dir, False, True)
160
elif sys.argv[1] in ['ci', 'commit', 'apply']:
162
elif sys.argv[1] in ['status', 'stat']:
166
print "E: ", sys.argv[1] , ": This option is not supported"