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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: David Coles
  • Date: 2010-07-20 08:24:32 UTC
  • Revision ID: coles.david@gmail.com-20100720082432-i48a9iz7s5ndfqcd
Fixes for the export command.

Use --username for svn export since in-url usernames don't work with 
subversion.
Export now explicitly sets the output filename to User or Groups short_name.
Clean up of some of the calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
231
231
        """Find a user in a store by login name."""
232
232
        return store.find(cls, cls.login == unicode(login)).one()
233
233
 
234
 
    def get_svn_url(self, config, req):
 
234
    def get_svn_url(self, config):
235
235
        """Get the subversion repository URL for this user or group."""
236
 
        login = req.user.login
237
 
        url = urlparse.urlsplit(config['urls']['svn_addr'])
238
 
        url = urlparse.urlunsplit(url[:1] + (login+'@'+url[1],) + url[2:])
 
236
        url = config['urls']['svn_addr']
239
237
        path = 'users/%s' % self.login
240
238
        return urlparse.urljoin(url, path)
241
239
 
735
733
            Semester.id == Offering.semester_id,
736
734
            (not active_only) or (Semester.state == u'current'))
737
735
 
738
 
    def get_svn_url(self, config, req):
 
736
    def get_svn_url(self, config):
739
737
        """Get the subversion repository URL for this user or group."""
740
 
        login = req.user.login
741
 
        url = urlparse.urlsplit(config['urls']['svn_addr'])
742
 
        url = urlparse.urlunsplit(url[:1] + (login+'@'+url[1],) + url[2:])
 
738
        url = config['urls']['svn_addr']
743
739
        path = 'groups/%s_%s_%s_%s' % (
744
740
                self.project_set.offering.subject.short_name,
745
741
                self.project_set.offering.semester.year,
912
908
        return "/files/%s/%s/%s?r=%d" % (user.login,
913
909
            self.assessed.checkout_location, submitpath, self.revision)
914
910
 
915
 
    def get_svn_url(self, req):
 
911
    def get_svn_url(self, config):
916
912
        """Get subversion URL for this submission"""
917
913
        princ = self.assessed.principal
918
 
        base = princ.get_svn_url(req.config, req)
 
914
        base = princ.get_svn_url(config)
919
915
        if self.path.startswith(os.sep):
920
916
            return os.path.join(base,
921
917
                    urllib.quote(self.path[1:].encode('utf-8')))
922
918
        else:
923
919
            return os.path.join(base, urllib.quote(self.path.encode('utf-8')))
924
920
 
925
 
    def get_svn_checkout_command(self, req):
926
 
        svn_url = self.get_svn_url(req)
927
 
        return "svn export -r%d '%s'"%(self.revision, svn_url)
 
921
    def get_svn_export_command(self, req):
 
922
        """Returns a Unix shell command to export a submission"""
 
923
        svn_url = self.get_svn_url(req.config)
 
924
        username = (req.user.login if req.user.login.isalnum() else
 
925
                "'%s'"%req.user.login)
 
926
        export_dir = self.assessed.principal.short_name
 
927
        return "svn export --username %s -r%d '%s' %s"%(req.user.login,
 
928
                self.revision, svn_url, export_dir)
928
929
 
929
930
    @staticmethod
930
931
    def test_and_normalise_path(path):