From 80c58558cdb775c62df6977b77f2b514daaeffe3 Mon Sep 17 00:00:00 2001 From: andrfla Date: Sun, 6 Mar 2011 12:54:50 +0000 Subject: [PATCH] =?UTF-8?q?La=20til=20en=20funksjon=20som=20oppretter=20en?= =?UTF-8?q?=20midlertidig=20fil=20som=20man=20kan=20editere=20f=C3=B8r=20m?= =?UTF-8?q?an=20kj=C3=B8rer=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/web/library/models.py | 7 ++----- python/worblehat.py | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/python/web/library/models.py b/python/web/library/models.py index 7b22baa..e9f64e5 100644 --- a/python/web/library/models.py +++ b/python/web/library/models.py @@ -48,8 +48,7 @@ class Book(models.Model): def to_string(self, commit=False): scratch = '' if commit: - # generate commit string by sending self.to_dict to oysteini function - print self.to_dict() + # generate commit string by sending self.to_dict to fileformat function print fileformat.write_action(self.to_dict()) else: @@ -63,8 +62,6 @@ class Book(models.Model): scratch += format % (field[1], '') authors = ', '.join(map(unicode, self.get_authors())) scratch += format % ('Authors', authors) -# scratch += 'Authors'.ljust(15, ' ') + ':' -# scratch += authors.rjust(51, ' ') return scratch @@ -163,7 +160,7 @@ class Person(models.Model): def to_string(self, commit=False): if commit: #generate commit-string - print self.to_dict() + print fileformat.write_action(self.to_dict()) else: format = '%-10s: %50s \n' scratch = format % ('Name', ' '.join((self.first_name, self.last_name))) diff --git a/python/worblehat.py b/python/worblehat.py index 15affb4..7e50856 100755 --- a/python/worblehat.py +++ b/python/worblehat.py @@ -12,6 +12,7 @@ import sys import types import search import placement +import tempfile def show_book_or_person(ids, commit_format=False, tmp_file=False): objects = map(get_book_or_person, ids) @@ -27,9 +28,9 @@ def show_book_or_person(ids, commit_format=False, tmp_file=False): else: output = '\n'.join(objects) if tmp_file: - # TODO - #return write_tmpfile('-'.join(ids), output) - pass + filename = write_tmpfile('.'.join(ids), output) + print filename + return filename else: print output.strip() @@ -76,6 +77,7 @@ def commit(filename=None): # TODO def edit_book_or_person(ids): filename = show_book_or_person(ids, commit_format=True, tmp_file=True) + print filename # run_editor(filename) # TODO: må implementeres commit(filename) @@ -215,7 +217,13 @@ def run_editor(filename): else: exit("Error: %s: File does not exist!" % filename) - +def write_tmpfile(pfix='', content=''): + file = tempfile.NamedTemporaryFile(prefix=pfix, dir='/tmp', delete=False) + file.write(content) + name = file.name + file.close() + return name + cmdline_parsed = parse_cmdline(sys.argv[1:]) print 'command line parsed to:', cmdline_parsed