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

« back to all changes in this revision

Viewing changes to lib/fileservice_lib/action.py

  • Committer: mattgiuca
  • Date: 2008-02-06 03:08:52 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:431
Tested a little bit more thoroughly. Still not completely thoroughly, but
enouch, hopefully, and fixed, again, makeuser.py.

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
#               recursively.
120
120
#       logmsg: Text of the log message. Optional. There is a default log
121
121
#               message if unspecified.
122
 
# action=svncheckout: Checkout a file/directory from the repository.
123
 
#       path:   The [repository] path to the file or directory to be
124
 
#               checked out.
125
122
126
123
# TODO: Implement the following actions:
127
124
#   putfiles, svnrevert, svnupdate, svncommit
133
130
#   update if the path is not a directory).
134
131
 
135
132
import os
136
 
import cStringIO
137
133
import shutil
138
134
 
139
135
import pysvn
140
136
 
141
137
from common import (util, studpath, zip)
142
 
import conf
143
 
 
144
 
def get_login(_realm, _username, _may_save):
145
 
    """Return the subversion credentials for the user."""
146
 
    return (True, conf.login, conf.passwd, True)
147
138
 
148
139
# Make a Subversion client object
149
140
svnclient = pysvn.Client()
150
 
svnclient.callback_get_login = get_login
151
141
 
152
142
DEFAULT_LOGMESSAGE = "No log message supplied."
153
143
 
218
208
 
219
209
    Does not mutate req.
220
210
    """
221
 
    (_, _, r) = studpath.url_to_jailpaths(actionpath_to_urlpath(req, path))
 
211
    _, r = studpath.url_to_local(actionpath_to_urlpath(req, path))
222
212
    if r is None:
223
213
        raise ActionError("Invalid path")
224
214
    return r
306
296
    # Important: Data is "None" if the file submitted is empty.
307
297
    path = fields.getfirst('path')
308
298
    data = fields.getfirst('data')
309
 
    if path is None or data is None:
 
299
    if path is None:
310
300
        raise ActionError("Required field missing")
311
301
    path = actionpath_to_local(req, path)
312
 
 
313
302
    if data is not None:
314
 
        data = cStringIO.StringIO(data)
 
303
        data = data.file
315
304
 
316
305
    # Copy the contents of file object 'data' to the path 'path'
317
306
    try:
327
316
 
328
317
    Reads fields: 'path', 'data' (file upload, multiple), 'unpack'
329
318
    """
330
 
 
331
319
    # Important: Data is "None" if the file submitted is empty.
332
320
    path = fields.getfirst('path')
333
 
    data = fields['data']
334
 
    if type(data) != type([]):
335
 
        data = [data]
 
321
    data = fields.getlist('data')
336
322
    unpack = fields.getfirst('unpack')
337
323
    if unpack is None:
338
324
        unpack = False
343
329
    path = actionpath_to_urlpath(req, path)
344
330
    goterror = False
345
331
 
346
 
 
347
332
    for datum in data:
348
333
        # Each of the uploaded files
349
334
        filepath = os.path.join(path, datum.filename)
350
 
        filedata = datum.value
 
335
        filedata = datum.file
351
336
 
352
337
        if unpack and datum.filename.lower().endswith(".zip"):
353
338
            # A zip file - unpack it instead of just copying
360
345
                goterror = True
361
346
        else:
362
347
            # Not a zip file
363
 
            (_, _, filepath_local) = studpath.url_to_jailpaths(filepath)
 
348
            _, filepath_local = studpath.url_to_local(filepath)
364
349
            if filepath_local is None:
365
350
                raise ActionError("Invalid path")
366
351
 
368
353
            try:
369
354
                dest = open(filepath_local, 'wb')
370
355
                if data is not None:
371
 
                    shutil.copyfileobj(cStringIO.StringIO(filedata), dest)
 
356
                    shutil.copyfileobj(filedata, dest)
372
357
            except OSError:
373
358
                goterror = True
374
359
 
391
376
    # Note that we do not check for the existence of files here. That is done
392
377
    # in the paste operation.
393
378
    files = fields.getlist('path')
 
379
    files = map(lambda field: field.value, files)
394
380
    clipboard = { "mode" : mode, "base" : req.path, "files" : files }
395
381
    session = req.get_session()
396
382
    session['clipboard'] = clipboard
525
511
        for path in paths:
526
512
            # Note: Property value doesn't matter
527
513
            svnclient.propset("ivle:published", "", path, recurse=False)
528
 
    except pysvn.ClientError, e:
529
 
        raise ActionError("Directory could not be published")
 
514
    except pysvn.ClientError:
 
515
        raise ActionError("One or more files could not be updated")
530
516
 
531
517
def action_svnunpublish(req, fields):
532
518
    """Deletes svn property "ivle:published" on each file specified.
540
526
        for path in paths:
541
527
            svnclient.propdel("ivle:published", path, recurse=False)
542
528
    except pysvn.ClientError:
543
 
        raise ActionError("Directory could not be unpublished")
 
529
        raise ActionError("One or more files could not be updated")
544
530
 
545
531
def action_svncommit(req, fields):
546
532
    """Performs a "svn commit" to each file specified.
557
543
    except pysvn.ClientError:
558
544
        raise ActionError("One or more files could not be committed")
559
545
 
560
 
def action_svncheckout(req, fields):
561
 
    """Performs a "svn checkout" of each path specified.
562
 
 
563
 
    Reads fields: 'path'    (multiple)
564
 
    """
565
 
    paths = fields.getlist('path')
566
 
    if len(paths) != 2:
567
 
        raise ActionError("usage: svncheckout url local-path")
568
 
    url = conf.svn_addr + "/" + login + "/" + paths[0]
569
 
    local_path = actionpath_to_local(req, str(paths[1]))
570
 
    try:
571
 
        svnclient.callback_get_login = get_login
572
 
        svnclient.checkout(url, local_path, recurse=True)
573
 
    except pysvn.ClientError:
574
 
        raise ActionError("One or more files could not be checked out")
575
 
 
576
546
# Table of all action functions #
577
547
# Each function has the interface f(req, fields).
578
548
 
592
562
    "svnpublish" : action_svnpublish,
593
563
    "svnunpublish" : action_svnunpublish,
594
564
    "svncommit" : action_svncommit,
595
 
    "svncheckout" : action_svncheckout,
596
565
}