def test_by_selected_and_tag(imgdir): """Select by selected flag and tag. """ with photo.index.Index(idxfile=imgdir) as idx: idxfilter = photo.idxfilter.IdxFilter(select=True, tags="Tokyo") fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == ["dsc_4664.jpg"]
def test_by_not_selected(imgdir): """Select by not-selected flag. """ with photo.index.Index(idxfile=imgdir) as idx: idxfilter = photo.idxfilter.IdxFilter(select=False) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == ["dsc_4623.jpg", "dsc_4831.jpg", "dsc_5167.jpg"]
def test_by_single_tag(imgdir): """Select by one single tag. """ with photo.index.Index(idxfile=imgdir) as idx: idxfilter = photo.idxfilter.IdxFilter(tags="Shinto_shrine") fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == ["dsc_4664.jpg", "dsc_4831.jpg"]
def ls_bytag(imgdir, tag, qres, qwait): """List files by tag. """ with photo.index.Index(idxfile=imgdir) as idx: idxfilter = photo.idxfilter.IdxFilter(tags=tag) qres.put((tag, [str(i.filename) for i in idxfilter.filter(idx)])) qwait.get()
def test_by_selected(imgdir): """Select by selected flag. """ with photo.index.Index(idxfile=imgdir) as idx: idxfilter = photo.idxfilter.IdxFilter(select=True) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == ["dsc_4664.jpg", "dsc_5126.jpg"]
def test_by_not_selected(imgdir, argparser): """Select by not-selected flag. """ idx = photo.index.Index(idxfile=imgdir) args = argparser.parse_args(["--not-selected"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == ["dsc_4623.jpg", "dsc_4831.jpg", "dsc_5167.jpg"]
def test_single_date(): """Select by single date. """ with photo.index.Index(idxfile=indexfile) as idx: date = (datetime.datetime(2016, 2, 29), datetime.datetime(2016, 3, 1)) idxfilter = photo.idxfilter.IdxFilter(date=date) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == testimgs[1:4]
def lstags(args): with photo.index.Index(idxfile=args.directory) as idx: idxfilter = photo.idxfilter.IdxFilter.from_args(args) tags = set() for i in idxfilter.filter(idx): tags.update(i.tags) for t in sorted(tags): print(t)
def test_interval_date_date(argparser): """Select by an interval between two dates. """ with photo.index.Index(idxfile=indexfile) as idx: args = argparser.parse_args(["--date=2016-02-29--2016-03-06"]) idxfilter = photo.idxfilter.IdxFilter.from_args(args) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == testimgs[1:11]
def test_interval_date_date(): """Select by an interval between two dates. """ with photo.index.Index(idxfile=indexfile) as idx: date = (datetime.datetime(2016, 2, 29), datetime.datetime(2016, 3, 6)) idxfilter = photo.idxfilter.IdxFilter(date=date) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == testimgs[1:11]
def test_single_date(argparser): """Select by single date. """ idx = photo.index.Index(idxfile=indexfile) args = argparser.parse_args(["--date=2016-02-29"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == testimgs[1:4]
def test_interval_date_date(argparser): """Select by an interval between two dates. """ idx = photo.index.Index(idxfile=indexfile) args = argparser.parse_args(["--date=2016-02-29--2016-03-05"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == testimgs[1:11]
def test_interval_datetime_date(argparser): """Select by an interval between start date/time and end date. """ with photo.index.Index(idxfile=indexfile) as idx: args = argparser.parse_args(["--date=2016-03-03T11:21:40/2016-03-06"]) idxfilter = photo.idxfilter.IdxFilter.from_args(args) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == testimgs[6:11]
def lstags(args): idx = photo.index.Index(idxfile=args.directory) idxfilter = photo.idxfilter.IdxFilter(args) tags = set() for i in idxfilter.filter(idx): tags.update(i.tags) for t in sorted(tags): print(t)
def test_by_single_tag(imgdir, argparser): """Select by one single tag. """ idx = photo.index.Index(idxfile=imgdir) args = argparser.parse_args(["--tags=Shinto_shrine"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == ["dsc_4664.jpg", "dsc_4831.jpg"]
def test_by_selected_and_tag(imgdir, argparser): """Select by selected flag and tag. """ idx = photo.index.Index(idxfile=imgdir) args = argparser.parse_args(["--selected", "--tags=Tokyo"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == ["dsc_4664.jpg"]
def test_interval_datetime_date(argparser): """Select by an interval between start date/time and end date. """ idx = photo.index.Index(idxfile=indexfile) args = argparser.parse_args(["--date=2016-03-03T11:21:40/2016-03-05"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == testimgs[6:11]
def test_single_date(argparser): """Select by single date. """ with photo.index.Index(idxfile=indexfile) as idx: args = argparser.parse_args(["--date=2016-02-29"]) idxfilter = photo.idxfilter.IdxFilter.from_args(args) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == testimgs[1:4]
def test_by_files(imgdir): """Select by file names. """ with photo.index.Index(idxfile=imgdir) as idx: files = ["dsc_4664.jpg", "dsc_4831.jpg"] idxfilter = photo.idxfilter.IdxFilter(files=files) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == files
def test_by_gpspos(imgdir): """Select by GPS position. """ with photo.index.Index(idxfile=imgdir) as idx: pos = GeoPosition("35.6883 N, 139.7544 E") idxfilter = photo.idxfilter.IdxFilter(gpspos=pos, gpsradius=20.0) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == ["dsc_4623.jpg", "dsc_4664.jpg"]
def test_by_date(imgdir): """Select by date. """ with photo.index.Index(idxfile=imgdir) as idx: date = (datetime.datetime(2016, 3, 5), datetime.datetime(2016, 3, 6)) idxfilter = photo.idxfilter.IdxFilter(date=date) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == ["dsc_4831.jpg"]
def test_by_empty_tag(imgdir): """Select by empty tags. The empty string as tag selects images having no tag. """ with photo.index.Index(idxfile=imgdir) as idx: idxfilter = photo.idxfilter.IdxFilter(tags="") fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == ["dsc_5126.jpg", "dsc_5167.jpg"]
def test_interval_datetime_date(): """Select by an interval between start date/time and end date. """ with photo.index.Index(idxfile=indexfile) as idx: date = (datetime.datetime(2016, 3, 3, 11, 21, 40), datetime.datetime(2016, 3, 6)) idxfilter = photo.idxfilter.IdxFilter(date=date) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == testimgs[6:11]
def test_interval_datetime_datetime(argparser): """Select by an interval between two date/times. """ idx = photo.index.Index(idxfile=indexfile) args = argparser.parse_args(["--date=2016-03-03T11:21:41" "--2016-03-05T03:47:08"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == testimgs[7:9]
def test_by_files(imgdir, argparser): """Select by file names. """ idx = photo.index.Index(idxfile=imgdir) args = argparser.parse_args(["dsc_4664.jpg", "dsc_4831.jpg"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == ["dsc_4664.jpg", "dsc_4831.jpg"] idx.write()
def test_by_date(imgdir, argparser): """Select by date. """ idx = photo.index.Index(idxfile=imgdir) args = argparser.parse_args(["--date=2016-03-05"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == ["dsc_4831.jpg"] idx.write()
def test_single_datetime(argparser): """Select by single date/time. Probably not very useful in the praxis, but valid. """ with photo.index.Index(idxfile=indexfile) as idx: args = argparser.parse_args(["--date=2016-03-03T11:21:40"]) idxfilter = photo.idxfilter.IdxFilter.from_args(args) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == testimgs[6:7]
def test_by_mult_tags(imgdir): """Select by multiple tags. Combining multiple tags acts like an and, it selects only images having all the tags set. """ with photo.index.Index(idxfile=imgdir) as idx: idxfilter = photo.idxfilter.IdxFilter(tags="Tokyo,Shinto_shrine") fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == ["dsc_4664.jpg"]
def test_by_neg_tags(imgdir): """Select by negating tags. Prepending a tag by an exclamation mark selects the images having the tag not set. """ with photo.index.Index(idxfile=imgdir) as idx: idxfilter = photo.idxfilter.IdxFilter(tags="Tokyo,!Shinto_shrine") fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == ["dsc_4623.jpg"]
def test_single_datetime(argparser): """Select by single date/time. Probably not very useful in the praxis, but valid. """ idx = photo.index.Index(idxfile=indexfile) args = argparser.parse_args(["--date=2016-03-03T11:21:40"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == testimgs[6:7]
def test_interval_datetime_datetime(argparser): """Select by an interval between two date/times. """ with photo.index.Index(idxfile=indexfile) as idx: args = argparser.parse_args( ["--date=2016-03-03T11:21:41" "--2016-03-05T03:47:09"]) idxfilter = photo.idxfilter.IdxFilter.from_args(args) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == testimgs[7:9]
def test_by_gpspos(imgdir, argparser): """Select by GPS position. """ idx = photo.index.Index(idxfile=imgdir) args = argparser.parse_args(["--gpspos=35.6883 N, 139.7544 E", "--gpsradius=20.0"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == ["dsc_4623.jpg", "dsc_4664.jpg"] idx.write()
def test_by_empty_tag(imgdir, argparser): """Select by empty tags. The empty string as tag selects images having no tag. """ idx = photo.index.Index(idxfile=imgdir) args = argparser.parse_args(["--tags="]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == ["dsc_5126.jpg", "dsc_5167.jpg"]
def test_single_datetime(): """Select by single date/time. Probably not very useful in the praxis, but valid. """ with photo.index.Index(idxfile=indexfile) as idx: date = (datetime.datetime(2016, 3, 3, 11, 21, 40), datetime.datetime(2016, 3, 3, 11, 21, 41)) idxfilter = photo.idxfilter.IdxFilter(date=date) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == testimgs[6:7]
def test_by_neg_tags(imgdir, argparser): """Select by negating tags. Prepending a tag by an exclamation mark selects the images having the tag not set. """ idx = photo.index.Index(idxfile=imgdir) args = argparser.parse_args(["--tags=Tokyo,!Shinto_shrine"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == ["dsc_4623.jpg"]
def test_by_mult_tags(imgdir, argparser): """Select by multiple tags. Combining multiple tags acts like an and, it selects only images having all the tags set. """ idx = photo.index.Index(idxfile=imgdir) args = argparser.parse_args(["--tags=Tokyo,Shinto_shrine"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == ["dsc_4664.jpg"]
def test_by_date_and_tag(imgdir, argparser): """Select by date and tags. Multiple selection criteria, such as date and tags may be combined. """ idx = photo.index.Index(idxfile=imgdir) args = argparser.parse_args(["--tags=Tokyo", "--date=2016-02-28"]) idxfilter = photo.idxfilter.IdxFilter(args) fnames = [ i.filename for i in idxfilter.filter(idx) ] assert fnames == ["dsc_4623.jpg"]
def test_by_date_and_tag(imgdir): """Select by date and tags. Multiple selection criteria, such as date and tags may be combined. """ with photo.index.Index(idxfile=imgdir) as idx: date = (datetime.datetime(2016, 2, 28), datetime.datetime(2016, 2, 29)) idxfilter = photo.idxfilter.IdxFilter(tags="Tokyo", date=date) fnames = [str(i.filename) for i in idxfilter.filter(idx)] assert fnames == ["dsc_4623.jpg"]
def ls(args): idx = photo.index.Index(idxfile=args.directory) idxfilter = photo.idxfilter.IdxFilter(args) for i in idxfilter.filter(idx): if args.checksum: try: checksum = i.checksum[args.checksum] except KeyError: continue print("%s %s" % (checksum, i.filename)) else: print(i.filename)
def ls(args): with photo.index.Index(idxfile=args.directory) as idx: idxfilter = photo.idxfilter.IdxFilter.from_args(args) for i in idxfilter.filter(idx): if args.checksum: try: checksum = i.checksum[args.checksum] except KeyError: continue print("%s %s" % (checksum, i.filename)) else: print(i.filename)
def test_tag_ref(imgdir): idxfname = str(imgdir / ".index.yaml") reffname = str(imgdir / "index-ref.yaml") shutil.copy(gettestdata("index-create.yaml"), idxfname) with photo.index.Index(idxfile=imgdir) as idx: taglist = [ "Japan", "Tokyo", "Hakone", "Kyoto", "Ginza", "Shinto_shrine", "Geisha", "Ryoan-ji" ] for t in taglist: idxfilter = photo.idxfilter.IdxFilter(files=tags[t]) for i in idxfilter.filter(idx): i.tags.add(t) idx.write() shutil.copy(idxfname, reffname)
def test_tag_ref(imgdir, argparser): idxfname = os.path.join(imgdir, ".index.yaml") reffname = os.path.join(imgdir, "index-ref.yaml") shutil.copy(gettestdata("index-create.yaml"), idxfname) idx = photo.index.Index(idxfile=imgdir) taglist = [ "Japan", "Tokyo", "Hakone", "Kyoto", "Ginza", "Shinto_shrine", "Geisha", "Ryoan-ji" ] for t in taglist: args = argparser.parse_args(tags[t]) idxfilter = photo.idxfilter.IdxFilter(args) for i in idxfilter.filter(idx): i.tags.add(t) idx.write() shutil.copy(idxfname, reffname)
def test_tag_shuffle(imgdir): """Same as test_tag_ref(), only the order of setting the tags differ. """ idxfname = str(imgdir / ".index.yaml") reffname = str(imgdir / "index-ref.yaml") shutil.copy(gettestdata("index-create.yaml"), idxfname) with photo.index.Index(idxfile=imgdir) as idx: taglist = [ "Ginza", "Hakone", "Japan", "Geisha", "Shinto_shrine", "Tokyo", "Kyoto", "Ryoan-ji" ] for t in taglist: idxfilter = photo.idxfilter.IdxFilter(files=tags[t]) for i in idxfilter.filter(idx): i.tags.add(t) idx.write() assert filecmp.cmp(idxfname, reffname), "index file differs from reference"
def test_tag_shuffle(imgdir, argparser): """Same as test_tag_ref(), only the order of setting the tags differ. """ idxfname = os.path.join(imgdir, ".index.yaml") reffname = os.path.join(imgdir, "index-ref.yaml") shutil.copy(gettestdata("index-create.yaml"), idxfname) idx = photo.index.Index(idxfile=imgdir) taglist = [ "Ginza", "Hakone", "Japan", "Geisha", "Shinto_shrine", "Tokyo", "Kyoto", "Ryoan-ji" ] for t in taglist: args = argparser.parse_args(tags[t]) idxfilter = photo.idxfilter.IdxFilter(args) for i in idxfilter.filter(idx): i.tags.add(t) idx.write() assert filecmp.cmp(idxfname, reffname), "index file differs from reference"
def test_stats_filtered(imgdir): """Get statistics on a selection of images. """ with photo.index.Index(idxfile=imgdir) as idx: idxfilter = photo.idxfilter.IdxFilter(tags="Tokyo") stats = Stats(idxfilter.filter(idx)) assert stats.count == 2 assert stats.selected == 1 assert stats.oldest == datetime.datetime(2016, 2, 28, 17, 26, 39) assert stats.newest == datetime.datetime(2016, 2, 29, 11, 37, 51) assert stats.by_date == { datetime.date(2016, 2, 28).toordinal() : 1, datetime.date(2016, 2, 29).toordinal() : 1, } assert stats.by_tag == { "Shinto_shrine": 1, "Tokyo": 2, }
def test_tag_extra(imgdir): """Add a spurious extra tag first and remove it later. """ idxfname = str(imgdir / ".index.yaml") reffname = str(imgdir / "index-ref.yaml") shutil.copy(gettestdata("index-create.yaml"), idxfname) with photo.index.Index(idxfile=imgdir) as idx: taglist = [ "Japan", "Tokyo", "Hakone", "Kyoto", "Ginza", "Shinto_shrine", "Geisha", "Ryoan-ji" ] for i in idx: i.tags.add("extra") for t in taglist: idxfilter = photo.idxfilter.IdxFilter(files=tags[t]) for i in idxfilter.filter(idx): i.tags.add(t) for i in idx: i.tags.remove("extra") idx.write() assert filecmp.cmp(idxfname, reffname), "index file differs from reference"
def test_tag_extra(imgdir, argparser): """Add a spurious extra tag first and remove it later. """ idxfname = os.path.join(imgdir, ".index.yaml") reffname = os.path.join(imgdir, "index-ref.yaml") shutil.copy(gettestdata("index-create.yaml"), idxfname) idx = photo.index.Index(idxfile=imgdir) taglist = [ "Japan", "Tokyo", "Hakone", "Kyoto", "Ginza", "Shinto_shrine", "Geisha", "Ryoan-ji" ] for i in idx: i.tags.add("extra") for t in taglist: args = argparser.parse_args(tags[t]) idxfilter = photo.idxfilter.IdxFilter(args) for i in idxfilter.filter(idx): i.tags.add(t) for i in idx: i.tags.remove("extra") idx.write() assert filecmp.cmp(idxfname, reffname), "index file differs from reference"
def stats(args): with photo.index.Index(idxfile=args.directory) as idx: idxfilter = photo.idxfilter.IdxFilter.from_args(args) stats = Stats(idxfilter.filter(idx)) print(str(stats))
def deselect(args): with photo.index.Index(idxfile=args.directory) as idx: idxfilter = photo.idxfilter.IdxFilter.from_args(args) for i in idxfilter.filter(idx): i.selected = False idx.write()
def rmtag(args): with photo.index.Index(idxfile=args.directory) as idx: idxfilter = photo.idxfilter.IdxFilter.from_args(args) for i in idxfilter.filter(idx): i.tags.discard(args.tag) idx.write()
def rmtag(args): idx = photo.index.Index(idxfile=args.directory) idxfilter = photo.idxfilter.IdxFilter(args) for i in idxfilter.filter(idx): i.tags.discard(args.tag) idx.write()
def deselect(args): idx = photo.index.Index(idxfile=args.directory) idxfilter = photo.idxfilter.IdxFilter(args) for i in idxfilter.filter(idx): i.selected = False idx.write()