Exemplo n.º 1
0
def op_remove(app, source):
    """
    Operation to remove files matching in filestructure.
    @param source Path object to file being removed.
    """

    if source.isdir():
        if not source.inroot():
            app.printer.warning("cannot remove directory (not in root):", source.path);
            return
        
        if not source.isempty():
            app.printer.warning("cannot remove directory (not empty):", source.relativepath());
            return;
        
        if app.lambdaenv.pretend:
            app.printer.notice("would remove empty dir:", source.relativepath());
            return;
        else:
            app.printer.action("removing directory:", source.relativepath());
            source.rmdir();
            return;
        
        return;
    
    elif source.isfile():
        if not source.meta:
            app.printer.warning("could not open metadata:", source.path);
            return;
        
        # this causes nice display of artist/album
        app.printer.focus(source.meta);
        
        # build target path
        target = db.build_target(app, source);
        
        if app.locker.islocked(target):
            app.printer.warning("locked:", target.relativepath());
            return;
        
        if app.locker.parentislocked(target):
            app.printer.warning("locked:", target.relativepath(), "(parent)");
            return;
        
        if not target.isfile():
            app.printer.warning("target file not found:", target.relativepath());
            return;
        
        if app.lambdaenv.pretend:
            app.printer.notice(     "would remove:", source.path);
            app.printer.blanknotice("          as:", target.relativepath());
        else:
            app.printer.action("removing file:", target.relativepath());
            db.remove(app, source, target);
        
        return;
    
    app.printer.warning("cannot handle file:", source.path);
Exemplo n.º 2
0
def op_add(app, source):
    """
    Operation to add files to filestructure.
    @param source Path object to file being added.
    """

    if source.isdir():
        app.printer.notice("ignoring directory:", source.path);
        return;
   
    if not source.isfile():
        app.printer.warning("not a file:", source.path);
        return;
    
    if not source.meta:
        app.printer.warning("could not open metadata:", source.path);
        return;
    
    # this causes nice display of artist/album
    app.printer.focus(source.meta);
    
    target = db.build_target(app, source);
    
    if app.locker.islocked(target):
        app.printer.warning("locked:", source.path);
        return

    if app.lambdaenv.pretend:
        app.printer.notice("would add:", source.path);
        app.printer.blanknotice("       as:", target.relativepath());
    else:
        app.printer.action("adding file:", target.relativepath());
        db.add(app, source, target);
    
    if app.lambdaenv.lock:
        op_lock(app, target);
Exemplo n.º 3
0
def op_fix(app, source):
    """
    Operation to fix files in filestructure.
    @param source Path object to file being fixed.
    """
    
    if not source.inroot():
        app.printer.warning("can only fix files in 'root'");
        return;
    
    if app.locker.islocked(source):
        app.printer.warning("locked:", source.relativepath());
        return;
    
    if app.locker.parentislocked(source):
        app.printer.warning("locked:", source.relativepath(), "(parent)");
        return;

    if not source.exists():
        app.printer.warning("path not found:", source.path);
        return;
    
    if source.isfile():
        if source.path == app.lambdaenv.lockdb():
            app.printer.action("ignoring lock-file");
            return;
        
        # try to open, if you cannot, remove the files
        if not source.meta:
            app.printer.action("removing", source.path);
            app.lambdaenv.rm(source.path);
	  
    target = None;
    if source.isfile():
        if not source.meta:
            app.printer.warning("could not open metadata:", source.path);
            return;

        # print nice focusing here aswell
        app.printer.focus(source.meta);
        
        target = db.build_target(app, source);
    else:
        target = source;
    
    def fix_file(app, s, t):
        if t.path == s.path:
            app.printer.notice("sane - " + t.relativepath());
            return;
        
        if not t.isfile() and not t.islink():
            if app.lambdaenv.pretend:
                app.printer.action("would add insane file - " + s.relativepath());
                app.printer.action("                   as - " + t.relativepath());
            else:
                app.printer.action("adding insane file - " + s.relativepath());
                app.printer.action("                as - " + t.relativepath());
                db.add(app, s, t);
                
                if s.isfile():
                    app.printer.action("removing insane file - " + s.relativepath());
                    app.lambdaenv.rm(s);
    
    def fix_dir(app, s):
        if s.isempty():
            if app.lambdaenv.pretend: 
                app.printer.action("would remove empty dir - " + s.relativepath());
            else:
                app.printer.action("removing empty dir - " + s.relativepath());
                s.rmdir();
            
            if app.lambdaenv.lock:
                op_lock(app, target);
        else:
            app.printer.notice("sane - " + s.relativepath());
    
    if source.isfile():   fix_file(app, source, target);
    elif source.isdir():  fix_dir(app, source);