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

« back to all changes in this revision

Viewing changes to lib/fileservice_lib/action.py

  • Committer: dcoles
  • Date: 2008-02-13 04:10:55 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:443
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
#               will create a directory instead and unpack the ZIP file
63
63
#               into it.
64
64
#
65
 
# action=mkdir: Create a directory. The parent dir must exist.
66
 
#       path:   The path to a file which does not exist, but whose parent
67
 
#               does. The dir will be made with this name.
68
 
#
69
65
# The differences between putfile and putfiles are:
70
66
# * putfile can only accept a single file.
71
67
# * putfile can accept string data, doesn't have to be a file upload.
123
119
#               recursively.
124
120
#       logmsg: Text of the log message. Optional. There is a default log
125
121
#               message if unspecified.
126
 
# action=svncheckout: Checkout a file/directory from the repository.
127
 
#       path:   The [repository] path to the file or directory to be
128
 
#               checked out.
129
122
130
123
# TODO: Implement the following actions:
131
124
#   putfiles, svnrevert, svnupdate, svncommit
143
136
import pysvn
144
137
 
145
138
from common import (util, studpath, zip)
146
 
import conf
147
 
 
148
 
def get_login(_realm, _username, _may_save):
149
 
    """Return the subversion credentials for the user."""
150
 
    return (True, conf.login, conf.passwd, True)
151
139
 
152
140
# Make a Subversion client object
153
141
svnclient = pysvn.Client()
154
 
svnclient.callback_get_login = get_login
155
142
 
156
143
DEFAULT_LOGMESSAGE = "No log message supplied."
157
144
 
300
287
    topath = fields.getfirst('to')
301
288
    movefile(req, frompath, topath)
302
289
 
303
 
def action_mkdir(req, fields):
304
 
    """Creates a directory with the given path.
305
 
    Reads fields: 'path'
306
 
    """
307
 
    path = fields.getfirst('path')
308
 
    if path is None:
309
 
        raise ActionError("Required field missing")
310
 
    path = actionpath_to_local(req, path)
311
 
 
312
 
    # Create the directory
313
 
    try:
314
 
        os.mkdir(path)
315
 
    except OSError:
316
 
        raise ActionError("Could not create directory")
317
 
 
318
290
def action_putfile(req, fields):
319
291
    """Writes data to a file, overwriting it if it exists and creating it if
320
292
    it doesn't.
325
297
    # Important: Data is "None" if the file submitted is empty.
326
298
    path = fields.getfirst('path')
327
299
    data = fields.getfirst('data')
328
 
    if path is None:
 
300
    if path is None or data is None:
329
301
        raise ActionError("Required field missing")
330
 
    if data is None:
331
 
        # Workaround - field reader treats "" as None, so this is the only
332
 
        # way to allow blank file uploads
333
 
        data = ""
334
302
    path = actionpath_to_local(req, path)
335
303
 
336
304
    if data is not None:
414
382
    # Note that we do not check for the existence of files here. That is done
415
383
    # in the paste operation.
416
384
    files = fields.getlist('path')
 
385
    files = map(lambda field: field.value, files)
417
386
    clipboard = { "mode" : mode, "base" : req.path, "files" : files }
418
387
    session = req.get_session()
419
388
    session['clipboard'] = clipboard
542
511
    Reads fields: 'path'
543
512
    """
544
513
    paths = fields.getlist('path')
545
 
    if len(paths):
546
 
        paths = map(lambda path: actionpath_to_local(req, path), paths)
547
 
    else:
548
 
        paths = [studpath.url_to_jailpaths(req.path)[2]]
 
514
    paths = map(lambda path: actionpath_to_local(req, path), paths)
549
515
 
550
516
    try:
551
517
        for path in paths:
552
518
            # Note: Property value doesn't matter
553
519
            svnclient.propset("ivle:published", "", path, recurse=False)
554
 
    except pysvn.ClientError, e:
555
 
        raise ActionError("Directory could not be published")
 
520
    except pysvn.ClientError:
 
521
        raise ActionError("One or more files could not be updated")
556
522
 
557
523
def action_svnunpublish(req, fields):
558
524
    """Deletes svn property "ivle:published" on each file specified.
566
532
        for path in paths:
567
533
            svnclient.propdel("ivle:published", path, recurse=False)
568
534
    except pysvn.ClientError:
569
 
        raise ActionError("Directory could not be unpublished")
 
535
        raise ActionError("One or more files could not be updated")
570
536
 
571
537
def action_svncommit(req, fields):
572
538
    """Performs a "svn commit" to each file specified.
583
549
    except pysvn.ClientError:
584
550
        raise ActionError("One or more files could not be committed")
585
551
 
586
 
def action_svncheckout(req, fields):
587
 
    """Performs a "svn checkout" of each path specified.
588
 
 
589
 
    Reads fields: 'path'    (multiple)
590
 
    """
591
 
    paths = fields.getlist('path')
592
 
    if len(paths) != 2:
593
 
        raise ActionError("usage: svncheckout url local-path")
594
 
    url = conf.svn_addr + "/" + login + "/" + paths[0]
595
 
    local_path = actionpath_to_local(req, str(paths[1]))
596
 
    try:
597
 
        svnclient.callback_get_login = get_login
598
 
        svnclient.checkout(url, local_path, recurse=True)
599
 
    except pysvn.ClientError:
600
 
        raise ActionError("One or more files could not be checked out")
601
 
 
602
552
# Table of all action functions #
603
553
# Each function has the interface f(req, fields).
604
554
 
605
555
actions_table = {
606
556
    "remove" : action_remove,
607
557
    "move" : action_move,
608
 
    "mkdir" : action_mkdir,
609
558
    "putfile" : action_putfile,
610
559
    "putfiles" : action_putfiles,
611
560
 
619
568
    "svnpublish" : action_svnpublish,
620
569
    "svnunpublish" : action_svnunpublish,
621
570
    "svncommit" : action_svncommit,
622
 
    "svncheckout" : action_svncheckout,
623
571
}