Browse Source

remove useless ftp stuff

pull/9/merge
Simon 15 years ago
parent
commit
5fd0c545a9
  1. 3
      README
  2. 9
      sigal.conf
  3. 23
      sigal.py
  4. 108
      sigal/ftp.py

3
README

@ -3,7 +3,7 @@ sigal - simple gallery generator
This python script prepares a gallery of images for [Piwigo]() gallery script.
It resizes images, creates thumbnails with some options (rename images,
squared thumbs, ...), and upload images to a FTP server.
squared thumbs, ...).
[Piwigo]: http://www.piwigo.org/
@ -36,7 +36,6 @@ Adapt setting to your needs in the configuration file (`sigal.conf`):
- Size of images and thumbnails
- JPG quality
- Thumbnails prefix
- FTP parameters
Options
-------

9
sigal.conf

@ -20,15 +20,6 @@ exif=1
# add a copyright text on the image
copyright=1
## FTP settings
# FTP server
host=ftp.example.org
# FTP login
user=login
# piwigo directory inside FTP server
piwigo_dir=piwigo
## core settings
thumb_dir=thumbnail

23
sigal.py

@ -20,19 +20,18 @@
"""Prepare and upload a gallery of images for Piwigo
This script resize images, create thumbnails with some options
(rename images, squared thumbs, ...), and upload images to a FTP server.
(rename images, squared thumbs, ...).
"""
__author__ = "Saimon (contact at saimon dot org)"
__version__ = "0.8"
__date__ = "20100722"
__copyright__ = "Copyright (C) 2009 - saimon.org"
__version__ = "0.1-dev"
__date__ = "20110411"
__copyright__ = "Copyright (C) 2009-2011 - saimon.org"
__license__ = "GPL"
import os
import sys
from optparse import OptionParser
from sigal.ftp import FtpUpload
from sigal.image import Gallery
from sigal.params import read_params
@ -47,8 +46,6 @@ def main():
parser.add_option("-c", "--config", dest="config",
help="specify an alternative config file")
parser.add_option("-f", "--ftp-upload", dest="ftp_upload",
help="upload file using ftp")
(options, args) = parser.parse_args()
@ -78,18 +75,6 @@ def main():
gallery = Gallery(params)
out_filelist = gallery.create_gallery(input_dir, output_dir)
# upload
if options.ftp_upload:
galleryname = raw_input("Enter directory name :")
ftp = FtpUpload(params["host"], params["user"], \
params["piwigo_dir"] + '/galleries')
if params["bigimg"]:
ftp.upload(out_filelist, galleryname, params["thumb_dir"],
params["bigimg_dir"])
else:
ftp.upload(out_filelist, galleryname, params["thumb_dir"])
ftp.close()
return 0

108
sigal/ftp.py

@ -1,108 +0,0 @@
#! /usr/bin/env python2
# -*- coding:utf-8 -*-
# sigal - Piwigo gallery generator
# Copyright (C) 2009, 2011 - saimon.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see http://www.gnu.org/licenses/
"""Upload images by FTP
"""
import os
import getpass
import ftplib
class FtpUpload:
"Upload a list of files by FTP"
# files excluded when listing directories' content
FILE_EXCLUDE = ["index.php", ".cvsignore"]
def __init__(self, host, user, basedir):
print "Connect to %s ..." % host
password = getpass.getpass()
self.ftp = ftplib.FTP(host, user, password)
self.ftp.cwd(basedir)
# FIXME: galname
def upload(self, imgfilelist, galname, thumb_dir, bigimg_dir=None):
"Upload images to a FTP server"
print "\nChoose the category in which your gallery will be uploaded:"
print "- enter a number to go in a sub-category"
print "- choose '.' for uploading in the current directory"
# choose upload dir
while 1:
i = 1
ftpdir = [f for f in self.ftp.nlst() if f not in self.FILE_EXCLUDE]
print "\n"
for ldir in ftpdir:
print "%i: %s" % (i, ldir)
i += 1
try:
choice = int(raw_input("Enter directory number: ")) - 1
if ftpdir[choice] == '.':
break
self.ftp.cwd(ftpdir[choice])
except:
print "Error: invalid choice"
print "Upload files to %s directory:" % galname
try:
self.ftp.mkd(galname)
except:
choice = raw_input("Directory exist, continue ? (y/[n]) ")
if choice != 'y':
return
# upload images
self.ftp.cwd(galname)
self.upload_files(imgfilelist[0])
# upload thumbnails
try:
self.ftp.mkd(thumb_dir)
except:
pass
self.ftp.cwd(thumb_dir)
self.upload_files(imgfilelist[1])
# upload big images
if bigimg_dir:
self.ftp.cwd('..')
try:
self.ftp.mkd(bigimg_dir)
except:
pass
self.ftp.cwd(bigimg_dir)
self.upload_files(imgfilelist[2])
def upload_files(self, imgfilelist):
"Upload list of files in the current working directory of ftp"
for i in imgfilelist:
print "Upload %s ..." % os.path.basename(i)
ofile = open(i, 'rb')
try:
self.ftp.storbinary('STOR '+os.path.basename(i), ofile)
except:
print "Tranfer error !"
ofile.close()
def close(self):
"Close FTP connection"
self.ftp.quit()
Loading…
Cancel
Save