Watson icon indicating copy to clipboard operation
Watson copied to clipboard

Possibility to remove the project

Open ladisone opened this issue 7 years ago • 16 comments

It would be good to delete the entire project.

ladisone avatar Feb 13 '18 06:02 ladisone

Hi @ladisone! You would like to remove a project and all related frames?

jmaupetit avatar Feb 13 '18 08:02 jmaupetit

@jmaupetit Yes and all related frames.

ladisone avatar Feb 13 '18 08:02 ladisone

+1

montrealks avatar Jun 04 '18 17:06 montrealks

I'll like to see this feature also. I can try to submit a PR to address this.

jnsebgosselin avatar Jun 04 '18 17:06 jnsebgosselin

Alternatively, or additionally - what about the ability to mark a project as "complete", so that it doesn't show up in the list of projects with watson projects?

NateV avatar Aug 08 '18 14:08 NateV

while you wait for the PR you can use this (add to your .bashrc or .zshrc):

# watson_rm_all <project|tag> <project_or_tag_name>
watson_rm_all () { watson log --$1 $2 | sed -n -E -e 's/^\s+([a-z0-9]+)\s.*/\1/p' | while read id; do watson remove -f "$id"; done }

3ynm avatar Nov 07 '18 14:11 3ynm

Nice snippet, thanks!

jmaupetit avatar Nov 08 '18 08:11 jmaupetit

while you wait for the PR you can use this (add to your .bashrc or .zshrc):

# watson_rm_all <project|tag> <project_or_tag_name>
watson_rm_all () { watson log --$1 $2 | sed -n -E -e 's/^\s+([a-z0-9]+)\s.*/\1/p' | while read id; do watson remove -f "$id"; done }

@hacktivista does this snippet still work for you? It doesn't work for me.

xilopaint avatar Jul 10 '19 10:07 xilopaint

it does for me, probably you want to delete items no longer listed by default? (1 month ago)

3ynm avatar Jul 10 '19 10:07 3ynm

@hacktivista maybe I'm doing something wrong? Look:

$ watson start apollo11 +reactor +module
Starting project apollo11 [reactor, module] at 21:52
$ watson stop
Stopping project apollo11 [reactor, module], started just now. (id: 6c68152)
$ watson_rm_all project apollo11
$ watson frames
6c68152

As you can see the frame is still there after running watson_rm_all. Am I missing anything?

xilopaint avatar Jul 11 '19 00:07 xilopaint

I've just tested it out with your example and it's working for me... Maybe it has something to do with your environment? I'm thinking it has to do with the sed implementation. I'm using GNU sed 4.7.

3ynm avatar Jul 11 '19 15:07 3ynm

I've just tested it out with your example and it's working for me... Maybe it has something to do with your environment? I'm thinking it has to do with the sed implementation. I'm using GNU sed 4.7.

That was the problem. The macOS sed version is not GNU sed. I've installed GNU sed and now it seems to work but not with projects that have spaces in the name. Is this an issue of your implementation?

xilopaint avatar Jul 12 '19 00:07 xilopaint

Yes

3ynm avatar Jul 12 '19 06:07 3ynm

Thanks, @hacktivista, for the shell snippet.

For anyone else looking for a way to delete old projects/tags, I suggest revising this as follows:

  • add the --all option to watson log so old frames for a project or tag will not be skipped
  • quote the project/tag name, possibly fixing handling of project/tag names with spaces (not tested)
# watson_rm_all <project|tag> <project_or_tag_name>
watson_rm_all () { watson log --all --$1 "$2" | sed -n -E -e 's/^\s+([a-z0-9]+)\s.*/\1/p' | while read id; do watson remove -f "$id"; done }

owenh000 avatar Mar 19 '23 22:03 owenh000

This is my python solution

Make this script in a dedicated folder for me it's ~/.local/scripts/watson_rm/watson_rm.py.

import subprocess
import json
import sys

def main():
    project_name = sys.argv[1]

    confirm = input(f"Confirming deletion of project: {project_name} (y/n): ")   

    if confirm.capitalize() != 'Y':
        print("Exiting...")
        sys.exit(0)

    command = [
        'watson',
        'log', 
        '--project',
        project_name,
        '--no-pager',
        '--json'
    ]
    
    command_str = ' '.join(command)
    watson_output = subprocess.run(command_str, 
                                   stdout=subprocess.PIPE, 
                                   text=True,
                                   shell=True)

    output = json.loads(watson_output.stdout)
    frames = [elem['id'] for elem in output]

    for frame in frames:
        subprocess.run(f'watson remove {frame} --force', shell=True)

if __name__ == '__main__':
    main()

Then put this in you're bash or zsh alias file:

alias watson_rm="python3 ~/.local/scripts/watson_rm/watson_rm.py"

NotJoeMartinez avatar Jan 24 '24 01:01 NotJoeMartinez