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

« back to all changes in this revision

Viewing changes to www/apps/fileservice/action.py

  • Committer: mattgiuca
  • Date: 2008-01-29 23:52:19 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:329
Converted Console from an "app" into a "plugin". It can now be plugged in to
any app.
Added "plugins" directory in www. Added "console" plugin. This contains all of
the functionality of what was previously the console app, but modularized so
it can be imported by another app.

apps/console: Removed most of the logic (moved to plugins/console). Replaced
with a simple import of the console plugin. Should behave exactly the same.
apps/tutorial: As proof of concept, imported the console plugin. It now
appears at the bottom of the page (yet to make it have "pop up" behaviour).

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
#               times.
103
103
#
104
104
# action=svnupdate: Bring a file up to date with the head revision.
105
 
#       path:   The path to the file to be updated. Can be specified multiple
106
 
#               times.
 
105
#       path:   The path to the file to be updated. Only one file may be
 
106
#               specified.
 
107
#
 
108
# action=svnpublish: Set the "published" flag on a file to True.
 
109
#       path:   The path to the file to be published. Can be specified
 
110
#               multiple times.
 
111
#
 
112
# action=svnunpublish: Set the "published" flag on a file to False.
 
113
#       path:   The path to the file to be unpublished. Can be specified
 
114
#               multiple times.
107
115
#
108
116
# action=svncommit: Commit a file(s) or directory(s) to the repository.
109
117
#       path:   The path to the file or directory to be committed. Can be
280
288
 
281
289
    Reads fields: 'path', 'data' (file upload)
282
290
    """
 
291
    # Important: Data is "None" if the file submitted is empty.
283
292
    path = fields.getfirst('path')
284
293
    data = fields.getfirst('data')
285
 
    if path is None or data is None:
 
294
    if path is None:
286
295
        raise ActionError("Required field missing")
287
296
    path = actionpath_to_local(req, path)
288
 
    data = data.file
 
297
    if data is not None:
 
298
        data = data.file
289
299
 
290
300
    # Copy the contents of file object 'data' to the path 'path'
291
301
    try:
292
302
        dest = open(path, 'wb')
293
 
        shutil.copyfileobj(data, dest)
 
303
        if data is not None:
 
304
            shutil.copyfileobj(data, dest)
294
305
    except OSError:
295
306
        raise ActionError("Could not write to target file")
296
307
 
427
438
    except pysvn.ClientError:
428
439
        raise ActionError("One or more files could not be reverted")
429
440
 
 
441
def action_svnpublish(req, fields):
 
442
    """Sets svn property "ivle:published" on each file specified.
 
443
    Should only be called on directories (only effective on directories
 
444
    anyway).
 
445
 
 
446
    Reads fields: 'path'
 
447
    """
 
448
    paths = fields.getlist('path')
 
449
    paths = map(lambda path: actionpath_to_local(req, path), paths)
 
450
 
 
451
    try:
 
452
        for path in paths:
 
453
            # Note: Property value doesn't matter
 
454
            svnclient.propset("ivle:published", "", path, recurse=False)
 
455
    except pysvn.ClientError:
 
456
        raise ActionError("One or more files could not be updated")
 
457
 
 
458
def action_svnunpublish(req, fields):
 
459
    """Deletes svn property "ivle:published" on each file specified.
 
460
 
 
461
    Reads fields: 'path'
 
462
    """
 
463
    paths = fields.getlist('path')
 
464
    paths = map(lambda path: actionpath_to_local(req, path), paths)
 
465
 
 
466
    try:
 
467
        for path in paths:
 
468
            svnclient.propdel("ivle:published", path, recurse=False)
 
469
    except pysvn.ClientError:
 
470
        raise ActionError("One or more files could not be updated")
 
471
 
430
472
def action_svncommit(req, fields):
431
473
    """Performs a "svn commit" to each file specified.
432
474
 
457
499
    "svnadd" : action_svnadd,
458
500
    "svnupdate" : action_svnupdate,
459
501
    "svnrevert" : action_svnrevert,
 
502
    "svnpublish" : action_svnpublish,
 
503
    "svnunpublish" : action_svnunpublish,
460
504
    "svncommit" : action_svncommit,
461
505
}