From 3f4f7e7b0b30422a5824ced39f710c037b0f17f8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 8 Jan 2007 21:54:04 +0000 Subject: [PATCH] Various fixes for windows: Remove dependency checking for windows builds as it would be a miracle if automatic installation succeeded. Provide a default termwidth for the CLI on windows. Initial import of Perl script to edit PDF metadata --- setup.py | 21 +++++++++---- src/libprs500/__init__.py | 2 +- src/libprs500/cli/main.py | 5 +++ src/libprs500/metadata/__init__.py | 20 ++++++++++++ src/libprs500/metadata/pdf-meta.pl | 49 ++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 src/libprs500/metadata/__init__.py create mode 100644 src/libprs500/metadata/pdf-meta.pl diff --git a/setup.py b/setup.py index b505010c09..1b6ea082c0 100644 --- a/setup.py +++ b/setup.py @@ -25,8 +25,12 @@ try: try: import Image except ImportError: - print "Trying to install the Python Imaging Library" - easy_install(["-f", "http://www.pythonware.com/products/pil/", "Imaging"]) + if sys.platform not in ['win32', 'darwin']: + print "Trying to install the Python Imaging Library" + easy_install(["-f", "http://www.pythonware.com/products/pil/", "Imaging"]) + else: + raise Exception('Please install the Python Imaging library manually from '\ + 'http://www.pythonware.com/products/pil/') except Exception, e: print >> sys.stderr, e print >> sys.stderr, \ @@ -44,6 +48,10 @@ if sys.hexversion < 0x2050000: sys.exit(1) +install_requires=[] +if sys.platform not in ['win32', 'darwin']: + install_requires = ["pyusb>=0.3.5", "pyxml>=0.8.4"] + setup( name='libprs500', packages = find_packages('src'), @@ -54,7 +62,8 @@ setup( url = 'http://libprs500.kovidgoyal.net', package_data = { \ 'libprs500.gui' : ['*.ui'], \ - 'libprs500.lrf' : ['*.jar', '*.jpg'] \ + 'libprs500.lrf' : ['*.jar', '*.jpg'], \ + 'libprs500.metadata' : ['*.pl'] \ }, entry_points = { 'console_scripts': [ \ @@ -65,9 +74,9 @@ setup( 'gui_scripts' : [ 'prs500-gui = libprs500.gui.main:main'] }, zip_safe = True, - install_requires=["pyusb>=0.3.5", "pyxml>=0.8.4"], - dependency_links=["http://sourceforge.net/project/showfiles.php?group_id=6473", - "http://easynews.dl.sourceforge.net/sourceforge/pyusb/pyusb-0.3.5.tar.gz", + install_requires = install_requires, + dependency_links = ["http://sourceforge.net/project/showfiles.php?group_id=6473", + "http://easynews.dl.sourceforge.net/sourceforge/pyusb/pyusb-0.3.5.tar.gz", ], description = """ diff --git a/src/libprs500/__init__.py b/src/libprs500/__init__.py index ee2275a999..b6c5b2b629 100644 --- a/src/libprs500/__init__.py +++ b/src/libprs500/__init__.py @@ -37,6 +37,6 @@ the following rule in C{/etc/udev/rules.d/90-local.rules} :: You may have to adjust the GROUP and the location of the rules file to suit your distribution. """ -__version__ = "0.3.0b3" +__version__ = "0.3.0b4" __docformat__ = "epytext" __author__ = "Kovid Goyal " diff --git a/src/libprs500/cli/main.py b/src/libprs500/cli/main.py index 7029ca4d78..bec7e894bc 100755 --- a/src/libprs500/cli/main.py +++ b/src/libprs500/cli/main.py @@ -177,6 +177,8 @@ def ls(dev, path, term, recurse=False, color=False, human_readable_size=False, l def main(): term = TerminalController() cols = term.COLS + if not cols: # On windows terminal width is unknown + cols = 80 parser = OptionParser(usage="usage: %prog [options] command args\n\ncommand is one of: info, books, df, ls, cp, mkdir, touch, cat, rm\n\n"+ "For help on a particular command: %prog command", version="libprs500 version: " + VERSION) @@ -302,3 +304,6 @@ def main(): print >>sys.stderr, e return 1 return 0 + +if __name__ == '__main__': + main() diff --git a/src/libprs500/metadata/__init__.py b/src/libprs500/metadata/__init__.py new file mode 100644 index 0000000000..d3ff4ce1ef --- /dev/null +++ b/src/libprs500/metadata/__init__.py @@ -0,0 +1,20 @@ +## Copyright (C) 2006 Kovid Goyal kovid@kovidgoyal.net +## 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, write to the Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +""" +Provides metadata editing support for PDF and RTF files. For LRF metadata, use +the L{libprs500.lrf.meta} module. +""" +__docformat__ = "epytext" +__author__ = "Kovid Goyal " diff --git a/src/libprs500/metadata/pdf-meta.pl b/src/libprs500/metadata/pdf-meta.pl new file mode 100644 index 0000000000..991873045a --- /dev/null +++ b/src/libprs500/metadata/pdf-meta.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl +# Read/Write PDF meta data +# Based on pdf-meta from http://www.osresearch.net/wiki/index.php/Pdf-meta + +use warnings; +use strict; +use PDF::API2; +use Getopt::Long; +use Data::Dumper; + +my %new_info = (Creator => 'libprs500.metadata', CreationDate => scalar( localtime ),); + +GetOptions( + "c|creator=s" => \$new_info{Creator}, + "d|date=s" => \$new_info{CreationDate}, + "p|producer=s" => \$new_info{Producer}, + "a|author=s" => \$new_info{Author}, + "s|subject=s" => \$new_info{Subject}, + "k|keywords=s" => \$new_info{Keywords}, + "t|title=s" => \$new_info{Title}, +) or die "Usage: (no help yet!)\n"; + + + +for my $file (@ARGV) +{ + my $pdf = PDF::API2->open( $file ) + or warn "Unable to open $file: $!\n" + and next; + + my %info = $pdf->info; + for my $key (keys %info) + { + print $key.' = """'.$info{$key}.'"""'."\n"; + } + print "\n"; + + for my $key (keys %new_info) + { + my $new_value = $new_info{$key}; + next unless defined $new_value; + + $info{$key} = $new_value; + } + + $pdf->info( %info ); + $pdf->saveas( $file ); +} +