IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Browse Source

Added ability to untag

tags/0.92
parent
commit
9554a7313a
3 changed files with 16 additions and 6 deletions
  1. +6
    -1
      focker.py
  2. +3
    -0
      image.py
  3. +7
    -5
      zfs.py

+ 6
- 1
focker.py View File

@@ -2,7 +2,8 @@ from argparse import ArgumentParser
import yaml import yaml
import os import os
# from weir import zfs, process # from weir import zfs, process
from .image import command_image_build
from .image import command_image_build, \
command_image_untag
import sys import sys
from .zfs import zfs_init from .zfs import zfs_init
@@ -17,6 +18,10 @@ def create_parser():
parser.add_argument('focker_dir', type=str) parser.add_argument('focker_dir', type=str)
parser.add_argument('--tag', '-t', type=str, nargs='+', default=[]) parser.add_argument('--tag', '-t', type=str, nargs='+', default=[])
parser = subparsers.add_parser('untag')
parser.set_defaults(func=command_image_untag)
parser.add_argument('tags', type=str, nargs='+', default=[])
return parser_top return parser_top


+ 3
- 0
image.py View File

@@ -70,3 +70,6 @@ def command_image_build(args):
image, image_sha256 = build(spec) image, image_sha256 = build(spec)
zfs_untag(args.tag) zfs_untag(args.tag)
zfs_tag(image.split('@')[0], args.tag) zfs_tag(image.split('@')[0], args.tag)
def command_image_untag(args):
zfs_untag(args.tags)

+ 7
- 5
zfs.py View File

@@ -72,11 +72,12 @@ def zfs_snapshot_by_sha256(sha256):
return lst[0][1] return lst[0][1]
def zfs_tag(name, tags):
def zfs_tag(name, tags, replace=False):
lst = zfs_parse_output(['zfs', 'list', '-o', 'focker:tags', '-H', name]) lst = zfs_parse_output(['zfs', 'list', '-o', 'focker:tags', '-H', name])
tags = list(tags)
tags.extend(lst[0][0].split(' '))
tags = list(set(tags))
if not replace:
tags = list(tags)
tags.extend(lst[0][0].split(' '))
tags = list(set(tags))
if len(tags) > 0: if len(tags) > 0:
zfs_run(['zfs', 'set', 'focker:tags=' + ' '.join(tags), name]) zfs_run(['zfs', 'set', 'focker:tags=' + ' '.join(tags), name])
else: else:
@@ -84,6 +85,7 @@ def zfs_tag(name, tags):
def zfs_untag(tags): def zfs_untag(tags):
# print('zfs_untag(), tags:', tags)
lst = zfs_parse_output(['zfs', 'list', '-o', 'name,focker:tags', '-H']) lst = zfs_parse_output(['zfs', 'list', '-o', 'name,focker:tags', '-H'])
lst = filter(lambda a: any([b in a[1].split(' ') for b in tags]), lst) lst = filter(lambda a: any([b in a[1].split(' ') for b in tags]), lst)
for row in lst: for row in lst:
@@ -91,7 +93,7 @@ def zfs_untag(tags):
for t in tags: for t in tags:
if t in cur_tags: if t in cur_tags:
cur_tags.remove(t) cur_tags.remove(t)
zfs_tag(row[0], cur_tags)
zfs_tag(row[0], cur_tags, replace=True)
def zfs_init(): def zfs_init():


Loading…
Cancel
Save