~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-04-14 03:52:13 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:731
Help: Wrote a small help document for the console app. Now one less glaring 
'TODO:' in IVLE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
443
443
    # XXX errorfiles contains a list of files that couldn't be pasted.
444
444
    # we currently do nothing with this.
445
445
 
 
446
def action_publish(req,fields):
 
447
    """Marks the folder as published by adding a '.published' file to the 
 
448
    directory and ensuring that the parent directory permissions are correct
 
449
 
 
450
    Reads fields: 'path'
 
451
    """
 
452
    paths = fields.getlist('path')
 
453
    user = studpath.url_to_local(req.path)[0]
 
454
    homedir = "/home/%s" % user
 
455
    if len(paths):
 
456
        paths = map(lambda path: actionpath_to_local(req, path), paths)
 
457
    else:
 
458
        paths = [studpath.url_to_jailpaths(req.path)[2]]
 
459
 
 
460
    # Set all the dirs in home dir world browsable (o+r,o+x)
 
461
    #FIXME: Should really only do those in the direct path not all of the 
 
462
    # folders in a students home directory
 
463
    for root,dirs,files in os.walk(homedir):
 
464
        os.chmod(root, os.stat(root).st_mode|0005)
 
465
 
 
466
    try:
 
467
        for path in paths:
 
468
            if os.path.isdir(path):
 
469
                pubfile = open(os.path.join(path,'.published'),'w')
 
470
                pubfile.write("This directory is published\n")
 
471
                pubfile.close()
 
472
            else:
 
473
                raise ActionError("Can only publish directories")
 
474
    except OSError, e:
 
475
        raise ActionError("Directory could not be published")
 
476
 
 
477
def action_unpublish(req,fields):
 
478
    """Marks the folder as unpublished by removing a '.published' file in the 
 
479
    directory (if it exits). It does not change the permissions of the parent 
 
480
    directories.
 
481
 
 
482
    Reads fields: 'path'
 
483
    """
 
484
    paths = fields.getlist('path')
 
485
    if len(paths):
 
486
        paths = map(lambda path: actionpath_to_local(req, path), paths)
 
487
    else:
 
488
        paths = [studpath.url_to_jailpaths(req.path)[2]]
 
489
 
 
490
    try:
 
491
        for path in paths:
 
492
            if os.path.isdir(path):
 
493
                pubfile = os.path.join(path,'.published')
 
494
                if os.path.isfile(pubfile):
 
495
                    os.remove(pubfile)
 
496
            else:
 
497
                raise ActionError("Can only unpublish directories")
 
498
    except OSError, e:
 
499
        raise ActionError("Directory could not be unpublished")
 
500
 
 
501
 
446
502
def action_svnadd(req, fields):
447
503
    """Performs a "svn add" to each file specified.
448
504
 
559
615
    "putfile" : action_putfile,
560
616
    "putfiles" : action_putfiles,
561
617
    "paste" : action_paste,
 
618
    "publish" : action_publish,
 
619
    "unpublish" : action_unpublish,
562
620
 
563
621
    "svnadd" : action_svnadd,
564
622
    "svnupdate" : action_svnupdate,