diff --git a/.pydevproject b/.pydevproject index cea05cb04a..7b15c0725e 100644 --- a/.pydevproject +++ b/.pydevproject @@ -8,5 +8,6 @@ /libprs500/devices /libprs500/libprs500.devices.prs500 /libprs500/prs500 +/libprs500/gui2 diff --git a/setup.py b/setup.py index e68447dd7b..25c3c6a922 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ if sys.argv[1] == 'py2exe': os.makedirs(dir) shutil.copy(file, dir) except ImportError: - print >>sys.stderr, 'Must be in Windows to run py2exe' + print >>sys.stderr, 'Failed to import py2exe' sys.exit(1) installer = \ r''' diff --git a/src/libprs500/library/database.py b/src/libprs500/library/database.py index 8d42609890..15cbd0f1ce 100644 --- a/src/libprs500/library/database.py +++ b/src/libprs500/library/database.py @@ -618,6 +618,9 @@ class LibraryDatabase(object): def rows(self): return len(self.data) if self.data else 0 + def id(self, index): + return self.data[index][0] + def title(self, index): return self.data[index][1] @@ -635,7 +638,65 @@ class LibraryDatabase(object): def max_size(self, index): return self.data[index][6] - + + def set(self, row, column, val): + ''' Convenience method for setting the title, authors, publisher or rating ''' + id = self.data[row][0] + cols = {'title' : 1, 'authors': 2, 'publisher': 3, 'rating':4} + col = cols[column] + self.data[row][col] = val + for item in self.cache: + if item[0] == id: + item[col] = val + break + if column == 'authors': + val = val.split('&,') + self.set_authors(id, val) + elif column == 'title': + self.set_title(id, val) + elif column == 'publisher': + self.set_publisher(id, val) + elif column == 'rating': + self.set_rating(id, val) + print row, col, val + + def set_authors(self, id, authors): + self.conn.execute('DELETE FROM books_authors_link WHERE book=?',(id,)) + for a in authors: + if not a: + continue + author = conn.execute('SELECT id from authors WHERE name=?', (a,)).fetchone() + if author: + aid = author[0] + else: + aid = conn.execute('INSERT INTO authors(name) VALUES (?)', (a,)).lastrowid + conn.execute('INSERT INTO books_authors_link(book, author) VALUES (?,?)', (id, aid)) + self.conn.commit() + + def set_title(self, id, title): + if not title: + return + self.conn.execute('UPDATE books SET title=? WHERE id=?', (title, id)) + self.conn.commit() + + def set_publisher(self, id, publisher): + if not publisher: + return + self.conn.execute('DELETE FROM books_publishers_link WHERE book=?',(id,)) + pub = conn.execute('SELECT id from publishers WHERE name=?', (publisher,)).fetchone() + if pub: + aid = pub[0] + else: + pub = conn.execute('INSERT INTO publishers(name) VALUES (?)', (publisher,)).lastrowid + conn.execute('INSERT INTO books_publishers_link(book, publisher) VALUES (?,?)', (id, aid)) + self.conn.commit() + + def set_rating(self, id, rating): + rating = int(rating) + self.conn.execute('DELETE FROM books_ratings_link WHERE book=?',(id,)) + rat = conn.execute('SELECT id FROM ratings WHERE rating=?', (rating,)).fetchone() + rat = rat[0] if rat else conn.execute('INSERT INTO ratings(rating) VALUES (?)', (rating,)).lastrowid + conn.execute('INSERT INTO books_ratings_link(book, rating) VALUES (?,?)', (id, rat)) if __name__ == '__main__': from IPython.Shell import IPShellEmbed diff --git a/upload b/upload index ef83ac39a5..237c86a1e3 100644 --- a/upload +++ b/upload @@ -1,28 +1,67 @@ -#!/bin/bash +#!/usr/bin/python +import sys, glob, os, subprocess +from pyvix.vix import * -# Script to upload libprs500 to pypi, the installer to libprs500.kovidgoyal.net and update the api documentation +files = glob.glob('dist/*.exe') +for file in files: + os.unlink(file) -PREFIX=/var/www/vhosts/kovidgoyal.net/subdomains/libprs500 -DOWNLOADS=$PREFIX/httpdocs/downloads -DOCS=$PREFIX/httpdocs/apidocs -exe=`cd dist && ls -1 libprs500-*.exe | tail -n1 && cd ..` -HTML2LRF=src/libprs500/ebooks/lrf/html/demo -echo "

The HTML

" > ${HTML2LRF}/demo_ext.html
-cat ${HTML2LRF}/demo.html >> ${HTML2LRF}/demo_ext.html
-echo '
' >> ${HTML2LRF}/demo_ext.html -html2lrf --title='Demonstration of html2lrf' --author='Kovid Goyal' --header --output=/tmp/html2lrf.lrf ${HTML2LRF}/demo.html -scp /tmp/html2lrf.lrf castalia:$DOWNLOADS/ +h = Host(hostType=VIX_SERVICEPROVIDER_VMWARE_WORKSTATION) +vm = h.openVM('/mnt/extra/vmware/Windows Vista/Windows Vista.vmx') +vm.powerOn() +if not vm.waitForToolsInGuest(): + print >>sys.stderr, 'Windows is not booting up' + sys.exit(1) -ssh castalia rm -f $DOWNLOADS/libprs500\*.exe -scp dist/$exe castalia:$DOWNLOADS/ -ssh castalia chmod a+r $DOWNLOADS/\* -ssh castalia /root/bin/update-installer-link $exe -epydoc --config epydoc.conf -scp -r docs/html castalia:$DOCS/ -epydoc -v --config epydoc-pdf.conf -scp docs/pdf/api.pdf castalia:$DOCS/ -python setup.py register sdist bdist_egg upload -rm -rf dist/* build/* +vm.loginInGuest('kovid', 'et tu brutus') +vm.loginInGuest(VIX_CONSOLE_USER_NAME, '') +vm.runProgramInGuest('C:\\Users\kovid\Desktop\libprs500.bat', '') +vm.runProgramInGuest('C:\Windows\system32\shutdown.exe', '/s') + +if not glob.glob('dist/*.exe'): + raise Exception('Windows build has failed') + + +PREFIX = "/var/www/vhosts/kovidgoyal.net/subdomains/libprs500" +DOWNLOADS = PREFIX+"/httpdocs/downloads" +DOCS = PREFIX+"/httpdocs/apidocs" +exe = os.path.basename(glob.glob('dist/*.exe')[0]) +HTML2LRF = "src/libprs500/ebooks/lrf/html/demo" + +f = open(os.path.join(HTML2LRF, 'demo_ext.html'), 'w') +f.write("

The HTML

\n")
+f.write(open(os.path.join(HTML2LRF, 'demo.html')).read())
+f.write('\n
') +f.close() + +def check_call(cmd): + try: + retcode = subprocess.call(cmd, shell=True) + if retcode < 0: + print >>sys.stderr, cmd, "was terminated by signal", -retcode + elif retcode > 0: + print >>sys.stderr, cmd, 'failed with retrun code:', retcode + if retcode != 0: + sys.exit(1) + except OSError, e: + print >>sys.stderr, "Execution of", cmd, "failed:", e + sys.exit(1) + +check_call('''html2lrf --title='Demonstration of html2lrf' --author='Kovid Goyal' --header --output=/tmp/html2lrf.lrf %s/demo.html'''%(HTML2LRF,)) +check_call('''scp /tmp/html2lrf.lrf castalia:%s/'''%(DOWNLOADS,)) +check_call('''python setup.py register sdist bdist_egg upload''') + +check_call('''ssh castalia rm -f %s/libprs500\*.exe'''%(DOWNLOADS,)) +check_call('''scp dist/%s castalia:%s/'''%(exe, DOWNLOADS)) +check_call('''ssh castalia chmod a+r %s/\*'''%(DOWNLOADS,)) +check_call('''ssh castalia /root/bin/update-installer-link %s'''%(exe,)) + +check_call('''epydoc --config epydoc.conf''') +check_call('''scp -r docs/html castalia:%s/'''%(DOCS,)) +check_call('''epydoc -v --config epydoc-pdf.conf''') +check_call('''scp docs/pdf/api.pdf castalia:%s/'''%(DOCS,)) + +check_call('''rm -rf dist/* build/*''')