~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to bin/ivle-cloneworksheets

  • Committer: Matt Giuca
  • Date: 2009-04-23 07:51:29 UTC
  • Revision ID: matt.giuca@gmail.com-20090423075129-94mf4vlwllpew0xn
ivle.svn: Added revision_is_dir (like os.path.isdir for revision history).
ivle.fileservice_lib.listing: Refactored such that the SVN revision is found
    in the top-level handler, and passed down into the individual handlers.
    This is done so that the revision information can be used to make the
    decisions (which will be required to fix the revision history browsing).
    This doesn't yet change the behaviour.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# IVLE - Informatics Virtual Learning Environment
 
3
# Copyright (C) 2007-2009 The University of Melbourne
 
4
#
 
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.
 
9
#
 
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.
 
14
#
 
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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 
 
19
# Author: Will Grant
 
20
 
 
21
import os
 
22
import sys
 
23
 
 
24
from ivle.database import get_store, Subject, Semester, Offering, Worksheet
 
25
import ivle.worksheet.utils
 
26
 
 
27
def die(error):
 
28
    print >> sys.stderr, '%s: %s' % (os.path.basename(sys.argv[0]), error)
 
29
    sys.exit(1)
 
30
 
 
31
if len(sys.argv) != 7:
 
32
    print >> sys.stderr, "usage: %s <oldsubjectcode> <oldyear> <oldsemester> "\
 
33
                         "<newsubjectcode> <newyear> <newsemester>" \
 
34
                         % os.path.basename(sys.argv[0])
 
35
    sys.exit()
 
36
 
 
37
store = get_store()
 
38
 
 
39
src = store.find(Offering,
 
40
                 Subject.code == unicode(sys.argv[1]),
 
41
                 Semester.year == unicode(sys.argv[2]),
 
42
                 Semester.semester == unicode(sys.argv[3]),
 
43
                 Offering.subject_id == Subject.id,
 
44
                 Offering.semester_id == Semester.id).one()
 
45
 
 
46
dst = store.find(Offering,
 
47
                 Subject.code == unicode(sys.argv[4]),
 
48
                 Semester.year == unicode(sys.argv[5]),
 
49
                 Semester.semester == unicode(sys.argv[6]),
 
50
                 Offering.subject_id == Subject.id,
 
51
                 Offering.semester_id == Semester.id).one()
 
52
 
 
53
if dst.worksheets.count() > 0:
 
54
    die('%r already has worksheets - doing nothing' % dst)
 
55
 
 
56
for oldws in src.worksheets:
 
57
    newws = Worksheet()
 
58
    newws.seq_no = oldws.seq_no
 
59
    newws.identifier = oldws.identifier
 
60
    newws.name = oldws.name
 
61
    newws.assessable = oldws.assessable
 
62
    newws.data = oldws.data
 
63
    newws.format = oldws.format
 
64
    newws.offering = dst
 
65
    store.add(newws)
 
66
    ivle.worksheet.utils.update_exerciselist(newws)
 
67
 
 
68
print >> sys.stderr, 'copied %d worksheets from %r to %r' \
 
69
                     % (dst.worksheets.count(), src, dst)
 
70
store.commit()