5 Incheckningar c7fd0ab02c ... 82560352ea

Upphovsman SHA1 Meddelande Datum
  zlg 82560352ea setup.py: bump to 0.3beta7 for PyPI 3 år sedan
  zlg 269aecb447 vgstash_cli: 'export' with no filename prints to stdout 3 år sedan
  zlg e23f6da1fb vgstash: Support 'member' ownership status 3 år sedan
  zlg 3295720fa2 tox.ini: update to use Python 3.9 for virtualenv 3 år sedan
  zlg 0bc7201fb6 helpers.sh: improve vgmulti 3 år sedan
6 ändrade filer med 76 tillägg och 25 borttagningar
  1. 2 10
      scripts/helpers.sh
  2. 1 1
      setup.py
  3. 4 2
      src/vgstash/__init__.py
  4. 19 11
      src/vgstash_cli.py
  5. 49 0
      tests/test_vgstash_cli.py
  6. 1 1
      tox.ini

+ 2 - 10
scripts/helpers.sh

@@ -35,17 +35,9 @@ function vgub() {
 	vgstash list done -w 80 | sed -e '1,2d' | sort | uniq -w50 | sort -b -t'|' -k 2,2
 }
 
-# Shows you the games that have more than one entry (by title) in vgstash.
-# Helpful for seeing games you own or have owned more than one copy of.
+# Shows you the titles of games that you own on more than one system.
 function vgmulti() {
-	# TODO: improve
-	if [ -n $1 ]; then
-		local filter="$1"
-	else
-		local filter="allgames"
-	fi
-	vgstash list -w 80 | head -n 2
-	vgstash list $filter -w 80 | sort | uniq -D -w50
+	vgstash list owned -w 80 | sed -e '1,2d' | sort -b -t'|' -k 1,1 | uniq -d -w50 | cut -d'|' -f 1
 }
 
 # Prints the title and system of a random game that you need to beat.

+ 1 - 1
setup.py

@@ -10,7 +10,7 @@ with open('README.md') as f:
 
 setup(
     name='vgstash',
-    version='0.3-beta6',
+    version='0.3-beta7',
     description='a video game collection management module, backed by SQLite',
     long_description=readme,
     long_description_content_type="text/markdown; variant=CommonMark",

+ 4 - 2
src/vgstash/__init__.py

@@ -23,7 +23,8 @@ OWNERSHIP = {
     'unowned': 0,
     'physical': 1,
     'digital': 2,
-    'both': 3
+    'both': 3,
+    'member': 4
 }
 
 DEFAULT_CONFIG = {
@@ -40,9 +41,10 @@ FILTERS = {
     'digital': "SELECT * FROM games WHERE ownership = 2 ORDER BY system, title ASC",
     'done': "SELECT * FROM games WHERE progress > 2 ORDER BY system, title ASC",
     'incomplete': "SELECT * FROM games WHERE progress = 3 AND ownership > 0 ORDER BY system, title ASC",
+    'members': "SELECT * FROM games WHERE ownership = 4 ORDER BY system, title ASC",
     'new': "SELECT * FROM games WHERE progress = 1 ORDER BY system, title ASC",
     'notes': "SELECT * FROM games WHERE notes NOT LIKE '' ORDER BY system, title ASC",
-    'owned': "SELECT * FROM games WHERE ownership > 0 ORDER BY system, title ASC",
+    'owned': "SELECT * FROM games WHERE ownership > 0 AND ownership < 4 ORDER BY system, title ASC",
     'physical': "SELECT * FROM games WHERE ownership = 1 ORDER BY system, title ASC",
     'playlog': "SELECT * FROM games WHERE ownership > 0 AND progress = 2 ORDER BY system, title ASC",
     'unowned': "SELECT * FROM games WHERE ownership = 0 ORDER BY system, title ASC",

+ 19 - 11
src/vgstash_cli.py

@@ -58,7 +58,7 @@ def row_format(row, width, header):
     titlestr = "{: <{w}s}".format(row['title'][:twidth], w=twidth)
     systemstr = "{: ^8s}".format(row['system'][:8])
     # unowned, physical, digital, both
-    ownltr = [' ', 'P', '  D', 'P D']
+    ownltr = [' ', 'P', '  D', 'P D', ' M']
     ownstr = "{: <3s}".format(ownltr[row['ownership']])
     progltr = {
         0: '',
@@ -83,10 +83,11 @@ def add(title, system, ownership, progress, notes):
     try:
         db.add_game(game, update=False)
         own_clause = (
-            "do not own",
-            "physically own",
-            "digitally own",
-            "digitally and physically own",
+            "do not own it",
+            "physically own it",
+            "digitally own it",
+            "digitally and physically own it",
+            "own it in a collection"
         )
         progress_clause = (
             "cannot beat",
@@ -96,7 +97,7 @@ def add(title, system, ownership, progress, notes):
             "have completed",
         )
         note_clause = "" if len(game.notes) == 0 else " It also has notes."
-        click.echo("Added {} for {}. You {} it and {} it.{}".format(
+        click.echo("Added {} for {}. You {} and {} it.{}".format(
             game.title,
             game.system,
             own_clause[game.ownership],
@@ -293,7 +294,6 @@ def import_file(format, filepath, update):
                     resolve_path=True,
                     dir_okay=False,
                     file_okay=True),
-                default=sys.stdout,
                 required=False,
                 )
 def export_file(format, filepath):
@@ -316,14 +316,22 @@ def export_file(format, filepath):
         for field in game.keys():
             g.update({field: game[field]})
         game_set.append(g)
-    with open(filepath, "w") as fp:
+    if not filepath:
         if format == "yaml":
-            yaml.dump(game_set, fp, default_flow_style=False,
+            yaml.dump(game_set, sys.stdout, default_flow_style=False,
                              indent=4, allow_unicode=True)
         if format == "json":
-            json.dump(game_set, fp, allow_nan=False, indent=1, skipkeys=True, sort_keys=True)
+            json.dump(game_set, sys.stdout, allow_nan=False, indent=1, skipkeys=True, sort_keys=True)
+    else:
+        with open(filepath, "w") as fp:
+            if format == "yaml":
+                yaml.dump(game_set, fp, default_flow_style=False,
+                                 indent=4, allow_unicode=True)
+            if format == "json":
+                json.dump(game_set, fp, allow_nan=False, indent=1, skipkeys=True, sort_keys=True)
     if len(game_set) > 0:
-        click.echo("Successfully exported {} games to {}.".format(len(game_set), filepath))
+        if filepath:
+            click.echo("Successfully exported {} games to {}.".format(len(game_set), filepath))
     else:
         click.echo("Could not export any games; have you made sure your collection has games in it?")
 

+ 49 - 0
tests/test_vgstash_cli.py

@@ -342,6 +342,55 @@ def test_import_file_yaml_update():
         print(list_result.output)
     assert list_result.exit_code == 0
 
+def test_export_no_file():
+    runner = CliRunner()
+    result = runner.invoke(vgstash_cli.cli, ["export"])
+    if verbose:
+        print(result.output)
+    assert result.exit_code == 0
+    assert result.output == """-   notes: ''
+    ownership: 2
+    progress: 4
+    system: 3DS
+    title: The Legend of Zelda
+-   notes: ''
+    ownership: 1
+    progress: 3
+    system: GBA
+    title: Fire Emblem
+-   notes: ''
+    ownership: 0
+    progress: 3
+    system: Genesis
+    title: Sonic the Hedgehog 2
+-   notes: 'beep
+
+        boop'
+    ownership: 1
+    progress: 2
+    system: Genesis
+    title: Vectorman 2
+-   notes: ''
+    ownership: 1
+    progress: 3
+    system: NES
+    title: Super Mario Bros.
+-   notes: ''
+    ownership: 2
+    progress: 2
+    system: NES
+    title: The Legend of Zelda
+-   notes: ''
+    ownership: 2
+    progress: 4
+    system: Switch
+    title: Puyo Puyo Tetris
+-   notes: ''
+    ownership: 2
+    progress: 3
+    system: WiiU
+    title: Super Smash Bros for WiiU
+"""
 
 def test_export_file_json():
     runner = CliRunner()

+ 1 - 1
tox.ini

@@ -4,7 +4,7 @@
 # and then run "tox" from this directory.
 
 [tox]
-envlist = py36
+envlist = py39
 
 [testenv]
 deps =