ssgetpy icon indicating copy to clipboard operation
ssgetpy copied to clipboard

Dry-run option

Open jpfairbanks opened this issue 10 years ago • 6 comments

Thanks for making this and sharing it. PyUFGet was easy to install and easy to use. One feature I would like is to enable a dry run where the program lists which matrices it will download, but does not actually download them. I would use this feature to make sure my query returns the desired matrices before incurring the cost of an accidental download.

Are you open to --dry-run as a command flag for the CLI?

jpfairbanks avatar Aug 19 '15 14:08 jpfairbanks

Yes, absolutely, it should be fairly easy. I'll try and get it done right away.

Thanks,

Sudarshan On Aug 19, 2015 10:34 AM, "James" [email protected] wrote:

Thanks for making this and sharing it. PyUFGet was easy to install and easy to use. One feature I would like is to enable a dry run where the program lists which matrices it will download, but does not actually download them. I would use this feature to make sure my query returns the desired matrices before incurring the cost of an accidental download.

Are you open to --dry-run as a command flag for the CLI?

— Reply to this email directly or view it on GitHub https://github.com/drdarshan/PyUFGet/issues/1.

drdarshan avatar Aug 19 '15 16:08 drdarshan

Hello, I've pushed a new version to the repo containing the --dry-run option: https://github.com/drdarshan/PyUFGet/blob/master/dist/PyUFGet-0.91.zip

Please give it a shot and let me know if it works as you expected.

Thanks much, Sudarshan

On 19 August 2015 at 12:01, Sudarshan Raghunathan [email protected] wrote:

Yes, absolutely, it should be fairly easy. I'll try and get it done right away.

Thanks,

Sudarshan On Aug 19, 2015 10:34 AM, "James" [email protected] wrote:

Thanks for making this and sharing it. PyUFGet was easy to install and easy to use. One feature I would like is to enable a dry run where the program lists which matrices it will download, but does not actually download them. I would use this feature to make sure my query returns the desired matrices before incurring the cost of an accidental download.

Are you open to --dry-run as a command flag for the CLI?

— Reply to this email directly or view it on GitHub https://github.com/drdarshan/PyUFGet/issues/1.

drdarshan avatar Aug 21 '15 14:08 drdarshan

I don't think that the command flag is getting passed to the function

i have this diff, I think you need to also add dry_run to the optdict parameter on line 97 of query.py

>git diff 1eb24dbeb1ed70b6302420c7bf595d8a94eb3887
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..cf9e932
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.pyc
+*.py~
\ No newline at end of file
diff --git a/PyUFGet/query.py b/PyUFGet/query.py
index 4dc7545..3c653a6 100644
--- a/PyUFGet/query.py
+++ b/PyUFGet/query.py
@@ -22,7 +22,7 @@ def search(name_or_id = None, **kwargs):
     from dbinstance import instance
     return instance.search(**kwargs)

-def fetch(name_or_id = None, format = 'MM', location = None, **kwargs):
+def fetch(name_or_id = None, format = 'MM', location = None, dry_run = False, **kwargs):
     import logging
     matrices = search(name_or_id, **kwargs)
     if len(matrices) > 0:
@@ -30,7 +30,8 @@ def fetch(name_or_id = None, format = 'MM', location = None, **kwargs):
         for matrix in matrices:
             logging.info("Downloading %s/%s to %s" % \
                              (matrix.group, matrix.name, matrix.localpath(format, location, extract = True)[0]))
-            matrix.download(format, location, extract = True)
+            if not dry_run:
+                matrix.download(format, location, extract = True)
     return matrices

 def cli(argv):
@@ -50,7 +51,8 @@ def cli(argv):
     parser.add_option("-l", "--limit", action="store", type="int", dest="limit", help="The maximum number of matrices to be downloaded. Defaults to 10.")
     parser.add_option("-o", "--outdir", action="store", type="string", dest="location", \
                       help="The directory in the local machine where matrices will be downloaded to. Defaults to " + UF_DIR)
-
+    parser.add_option("--dry-run", action="store_true", default=False, help="If True, only print the matrices that will be downloaded but do not actually download them.")
+    
     g = OptionGroup(parser, "Size and Non-zero filters", "These options may be used to restrict the shape or number of non-zero elements of the matrices to be downloaded")

     g.add_option("--min-rows", action="store", type="int", dest="min_rows", help="The minimum number of rows in the matrix/matrices.")
diff --git a/dist/PyUFGet-0.91.zip b/dist/PyUFGet-0.91.zip
new file mode 100644
index 0000000..adc0ed3
Binary files /dev/null and b/dist/PyUFGet-0.91.zip differ
diff --git a/setup.py b/setup.py
index b4b4c87..749eb31 100644
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,7 @@
 from distutils.core import setup

 setup(name="PyUFGet",
-      version="0.9",
+      version="0.91",
       description="A Python interface to the University of Florida Sparse Matrix Collection",
       author="Sudarshan Raghunathan",
       author_email="[email protected]",

jpfairbanks avatar Aug 21 '15 16:08 jpfairbanks

This fixed it for me

diff --git a/PyUFGet/query.py b/PyUFGet/query.py
index 3c653a6..77d8959 100644
--- a/PyUFGet/query.py
+++ b/PyUFGet/query.py
@@ -94,7 +94,8 @@ def cli(argv):
                        colbounds = (options.min_cols, options.max_cols),\
                        nzbounds  = (options.min_nnzs, options.max_nnzs),\
                        dtype     = options.dtype,\
-                       isspd     = options.isspd)
+                       isspd     = options.isspd,\
+                       dry_run  = options.dry_run)
     if options.limit:
         optdict["limit"] = options.limit

Easier to post 3 line patch than to fork and PR.

jpfairbanks avatar Aug 21 '15 16:08 jpfairbanks

Agreed, I'll fix, sorry about that.

Thanks!

On 21 August 2015 at 12:56, James [email protected] wrote:

This fixed it for me

diff --git a/PyUFGet/query.py b/PyUFGet/query.py index 3c653a6..77d8959 100644--- a/PyUFGet/query.py+++ b/PyUFGet/query.py@@ -94,7 +94,8 @@ def cli(argv): colbounds = (options.min_cols, options.max_cols),
nzbounds = (options.min_nnzs, options.max_nnzs),
dtype = options.dtype,- isspd = options.isspd)+ isspd = options.isspd,+ dry_run = options.dry_run) if options.limit: optdict["limit"] = options.limit

Easier to post 3 line patch than to fork and PR.

— Reply to this email directly or view it on GitHub https://github.com/drdarshan/PyUFGet/issues/1#issuecomment-133493778.

drdarshan avatar Aug 21 '15 17:08 drdarshan

Apologies for the trouble, please try the latest version (0.92) - it has the fix as you pointed out.

Thanks again

On 21 August 2015 at 13:13, Sudarshan Raghunathan [email protected] wrote:

Agreed, I'll fix, sorry about that.

Thanks!

On 21 August 2015 at 12:56, James [email protected] wrote:

This fixed it for me

diff --git a/PyUFGet/query.py b/PyUFGet/query.py index 3c653a6..77d8959 100644--- a/PyUFGet/query.py+++ b/PyUFGet/query.py@@ -94,7 +94,8 @@ def cli(argv): colbounds = (options.min_cols, options.max_cols),
nzbounds = (options.min_nnzs, options.max_nnzs),
dtype = options.dtype,- isspd = options.isspd)+ isspd = options.isspd,+ dry_run = options.dry_run) if options.limit: optdict["limit"] = options.limit

Easier to post 3 line patch than to fork and PR.

— Reply to this email directly or view it on GitHub https://github.com/drdarshan/PyUFGet/issues/1#issuecomment-133493778.

drdarshan avatar Aug 21 '15 17:08 drdarshan