"""Save our local NEXRAD level 3 RADARs to staging."""
import datetime
import os
import subprocess

from pyiem.util import logger

LOG = logger()
NEXRADS = "DMX DVN OAX ARX FSD MPX EAX ABR UDX".split()


def run(date):
    """Process this date please"""
    yyyymmdd = date.strftime("%Y%m%d")
    for nexrad in NEXRADS:
        mydir = "/mnt/nexrad3/nexrad/NIDS/%s" % (nexrad,)
        if not os.path.isdir(mydir):
            LOG.info("creating %s", mydir)
            os.makedirs(mydir)
        os.chdir(mydir)
        cmd = ("tar -czf /mesonet/tmp/%s_%s.tgz ???/???_%s_*") % (
            nexrad,
            yyyymmdd,
            yyyymmdd,
        )
        LOG.debug(cmd)
        subprocess.call(cmd, shell=True)

    rpath = "/stage/IowaNexrad3/%s" % (date.strftime("%Y/%m"),)
    cmd = (
        'rsync --remove-source-files -a --rsync-path "mkdir -p %s && rsync" '
        "/mesonet/tmp/???_%s.tgz meteor_ldm@metl60.agron.iastate.edu:%s"
    ) % (rpath, yyyymmdd, rpath)
    LOG.debug(cmd)
    subprocess.call(cmd, shell=True)


def main():
    """Go Main Go"""
    yesterday = datetime.date.today() - datetime.timedelta(days=1)
    run(yesterday)


if __name__ == "__main__":
    main()

@@ -677,16 +677,23 @@
 %0A       
+ proc =
  subproc
@@ -696,36 +696,448 @@
 process.
-call(cmd, shell=True
+Popen(%0A            cmd,%0A            shell=True,%0A            stderr=subprocess.PIPE,%0A            stdout=subprocess.PIPE,%0A        )%0A        (stdout, stderr) = proc.communicate()%0A        if stdout != b%22%22 or stderr != b%22%22:%0A            LOG.info(%0A                %22%25s resulted in%5Cnstdout: %25s%5Cnstderr: %25s%22,%0A                cmd,%0A                stdout.decode(%22ascii%22, %22ignore%22),%0A                stderr.decode(%22ascii%22, %22ignore%22),%0A            
 )%0A%0A    r

improve error reporting of tar command