Repository: spack/spack

Issue:
spack md5: can't mix files and urls
`spack md5` allows you to calculate checksums of files, or download files from urls and get their checksums. You can specify multiple files or multiple urls, but you can't mix urls and files in the same command. Not a big deal, but certainly a bug.



Discussion:
This seems to be working now : 

```
$ spack md5 var/spack/cache/armadillo/armadillo-7.200.2.tar.xz var/spack/cache/ncurses/ncurses-6.0.tar.gz http://sourceforge.net/projects/arma/files/armadillo-7.200.1.tar.xz
==> Trying to fetch from http://sourceforge.net/projects/arma/files/armadillo-7.200.1.tar.xz
######################################################################## 100,0%
==> 3 MD5 checksums:
b21585372d67a8876117fd515d8cf0a2  var/spack/cache/armadillo/armadillo-7.200.2.tar.xz
ee13d052e1ead260d7c28071f46eefb1  var/spack/cache/ncurses/ncurses-6.0.tar.gz
ed86d6df0058979e107502e1fe3e469e  http://sourceforge.net/projects/arma/files/armadillo-7.200.1.tar.xz
```

If you confirm we may close the issue

So the plot thickens...

You can checksum a file and then a URL:

```
$ spack md5 var/spack/cache/bzip2/bzip2-1.0.6.tar.gz https://pypi.python.org/packages/source/f/flake8/flake8-2.5.4.tar.gz
==> Trying to fetch from https://pypi.python.org/packages/source/f/flake8/flake8-2.5.4.tar.gz
######################################################################## 100.0%
==> 2 MD5 checksums:
00b516f4704d4a7cb50a1d97e6e8e15b  var/spack/cache/bzip2/bzip2-1.0.6.tar.gz
a4585b3569b95c3f66acb8294a7f06ef  https://pypi.python.org/packages/source/f/flake8/flake8-2.5.4.tar.gz
```

But you can't checksum a URL and then a file:

```
$ spack md5 https://pypi.python.org/packages/source/f/flake8/flake8-2.5.4.tar.gz var/spack/cache/bzip2/bzip2-1.0.6.tar.gz
==> Trying to fetch from https://pypi.python.org/packages/source/f/flake8/flake8-2.5.4.tar.gz
######################################################################## 100.0%
==> Trying to fetch from var/spack/cache/bzip2/bzip2-1.0.6.tar.gz

curl: (6) Could not resolve host: var
==> Fetching from var/spack/cache/bzip2/bzip2-1.0.6.tar.gz failed.
==> Error: All fetchers failed for spack-stage-0wJvzs
```


Resolving patch:
diff --git a/lib/spack/spack/cmd/md5.py b/lib/spack/spack/cmd/md5.py
--- a/lib/spack/spack/cmd/md5.py
+++ b/lib/spack/spack/cmd/md5.py
@@ -25,6 +25,7 @@
 import argparse
 import hashlib
 import os
+from urlparse import urlparse
 
 import llnl.util.tty as tty
 import spack.util.crypto
@@ -49,13 +50,23 @@ def compute_md5_checksum(url):
     return value
 
 
+def normalized(files):
+    for p in files:
+        result = urlparse(p)
+        value = p
+        if not result.scheme:
+            value = os.path.abspath(p)
+        yield value
+
+
 def md5(parser, args):
     if not args.files:
         setup_parser.parser.print_help()
         return 1
 
+    urls = [x for x in normalized(args.files)]
     results = []
-    for url in args.files:
+    for url in urls:
         try:
             checksum = compute_md5_checksum(url)
             results.append((checksum, url))
@@ -70,4 +81,4 @@ def md5(parser, args):
     checksum = 'checksum' if len(results) == 1 else 'checksums'
     tty.msg("%d MD5 %s:" % (len(results), checksum))
     for checksum, url in results:
-        print "%s  %s" % (checksum, url)
+        print("{0}  {1}".format(checksum, url))


Test patch: