<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[139128] trunk/dports/science/uhd</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="https://trac.macports.org/changeset/139128">139128</a></dd>
<dt>Author</dt> <dd>michaelld@macports.org</dd>
<dt>Date</dt> <dd>2015-08-03 08:42:41 -0700 (Mon, 03 Aug 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>uhd:
+ update devel to 0c7d748b (20150730);
+ remove integrated patch;
+ add temporary patches to fix B2x0 USB access.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkdportsscienceuhdPortfile">trunk/dports/science/uhd/Portfile</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkdportsscienceuhdfilespatchb200fix_initial_loadingdiff">trunk/dports/science/uhd/files/patch-b200-fix_initial_loading.diff</a></li>
<li><a href="#trunkdportsscienceuhdfilespatchb200fixesLIBUSB_ERROR_PIPEonOSXdiff">trunk/dports/science/uhd/files/patch-b200-fixes-LIBUSB_ERROR_PIPE-on-OS-X.diff</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkdportsscienceuhdfilespatchhost_utils_uhd_images_downloaderpyindiff">trunk/dports/science/uhd/files/patch-host_utils_uhd_images_downloader.py.in.diff</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkdportsscienceuhdPortfile"></a>
<div class="modfile"><h4>Modified: trunk/dports/science/uhd/Portfile (139127 => 139128)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/dports/science/uhd/Portfile        2015-08-03 15:39:55 UTC (rev 139127)
+++ trunk/dports/science/uhd/Portfile        2015-08-03 15:42:41 UTC (rev 139128)
</span><span class="lines">@@ -47,11 +47,17 @@
</span><span class="cx"> 
</span><span class="cx">     name            uhd-devel
</span><span class="cx">     conflicts       uhd
</span><del>-    github.setup    EttusResearch uhd 012381d999c4a895593412aaf06e73432b458810
-    version         20150714
-    checksums       rmd160 450a9619d127533574f8848de6e7ce17beefb1cf \
-                    sha256 d3f26e8cfa7147df99f383a53f41340ff646bd202d748aa487da2a1befac0292
</del><ins>+    github.setup    EttusResearch uhd 0c7d748bbf6c282d3f1c759201e40f35f26133ca
+    version         20150730
+    checksums       rmd160 250ed5a0480f232d9ea07db82473345d20b3e0b2 \
+                    sha256 707ea2ff2fa49b5999d9693ba44049d6b60288137e6d6acf3fe2d5125e5329ad
</ins><span class="cx"> 
</span><ins>+    # temporary patch to fix startup USB errors
+
+    patchfiles-append \
+        patch-b200-fixes-LIBUSB_ERROR_PIPE-on-OS-X.diff \
+        patch-b200-fix_initial_loading.diff
+
</ins><span class="cx">     # overload the github livecheck URL with the maint branch,
</span><span class="cx">     # when it is more advanced; comment out for master.
</span><span class="cx"> 
</span><span class="lines">@@ -170,10 +176,6 @@
</span><span class="cx"> 
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-# patch the UHD images downloader to work with both Python 2.7 &amp; 3.4.
-
-patchfiles-append patch-host_utils_uhd_images_downloader.py.in.diff
-
</del><span class="cx"> set PythonVersionWithDot [join [split ${PythonVersionNoDot} &quot;&quot;] &quot;.&quot;]
</span><span class="cx"> 
</span><span class="cx"> # required Python
</span></span></pre></div>
<a id="trunkdportsscienceuhdfilespatchb200fix_initial_loadingdiff"></a>
<div class="addfile"><h4>Added: trunk/dports/science/uhd/files/patch-b200-fix_initial_loading.diff (0 => 139128)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/dports/science/uhd/files/patch-b200-fix_initial_loading.diff                                (rev 0)
+++ trunk/dports/science/uhd/files/patch-b200-fix_initial_loading.diff        2015-08-03 15:42:41 UTC (rev 139128)
</span><span class="lines">@@ -0,0 +1,21 @@
</span><ins>+--- host/lib/usrp/b200/b200_impl.cpp.orig
++++ host/lib/usrp/b200/b200_impl.cpp
+@@ -125,8 +125,7 @@ static device_addrs_t b200_find(const device_addr_t &amp;hint)
+     // so that re-enumeration after fw load can occur successfully.
+     // This requirement is a courtesy of libusb1.0 on windows.
+     size_t found = 0;
+-    std::vector&lt;usb_device_handle::sptr&gt; b200_device_handles = get_b200_device_handles(hint);
+-    BOOST_FOREACH(usb_device_handle::sptr handle, b200_device_handles) {
++    BOOST_FOREACH(usb_device_handle::sptr handle, get_b200_device_handles(hint)) {
+         //extract the firmware path for the b200
+         std::string b200_fw_image;
+         try{
+@@ -157,7 +156,7 @@ static device_addrs_t b200_find(const device_addr_t &amp;hint)
+     //search for the device until found or timeout
+     while (boost::get_system_time() &lt; timeout_time and b200_addrs.empty() and found != 0)
+     {
+-        BOOST_FOREACH(usb_device_handle::sptr handle, b200_device_handles)
++        BOOST_FOREACH(usb_device_handle::sptr handle, get_b200_device_handles(hint))
+         {
+             usb_control::sptr control;
+             try{control = usb_control::make(handle, 0);}
</ins></span></pre></div>
<a id="trunkdportsscienceuhdfilespatchb200fixesLIBUSB_ERROR_PIPEonOSXdiff"></a>
<div class="addfile"><h4>Added: trunk/dports/science/uhd/files/patch-b200-fixes-LIBUSB_ERROR_PIPE-on-OS-X.diff (0 => 139128)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/dports/science/uhd/files/patch-b200-fixes-LIBUSB_ERROR_PIPE-on-OS-X.diff                                (rev 0)
+++ trunk/dports/science/uhd/files/patch-b200-fixes-LIBUSB_ERROR_PIPE-on-OS-X.diff        2015-08-03 15:42:41 UTC (rev 139128)
</span><span class="lines">@@ -0,0 +1,273 @@
</span><ins>+--- host/include/uhd/exception.hpp.orig
++++ host/include/uhd/exception.hpp
+@@ -98,6 +98,14 @@ namespace uhd{
+         virtual void dynamic_throw(void) const;
+     };

++    struct UHD_API usb_error : runtime_error{
++        int _code;
++        usb_error(int code, const std::string &amp;what);
++        virtual unsigned code(void) const;
++        virtual usb_error *dynamic_clone(void) const;
++        virtual void dynamic_throw(void) const;
++    };
++
+     struct UHD_API not_implemented_error : runtime_error{
+         not_implemented_error(const std::string &amp;what);
+         virtual unsigned code(void) const;
+--- host/lib/exception.cpp.orig
++++ host/lib/exception.cpp
+@@ -38,8 +38,15 @@ make_exception_impl(&quot;KeyError&quot;,              key_error,               lookup_err
+ make_exception_impl(&quot;TypeError&quot;,             type_error,              exception)
+ make_exception_impl(&quot;ValueError&quot;,            value_error,             exception)
+ make_exception_impl(&quot;RuntimeError&quot;,          runtime_error,           exception)
++//make_exception_impl(&quot;USBError&quot;,              usb_error,           runtime_error)
+ make_exception_impl(&quot;NotImplementedError&quot;,   not_implemented_error,   runtime_error)
+ make_exception_impl(&quot;EnvironmentError&quot;,      environment_error,       exception)
+ make_exception_impl(&quot;IOError&quot;,               io_error,                environment_error)
+ make_exception_impl(&quot;OSError&quot;,               os_error,                environment_error)
+ make_exception_impl(&quot;SystemError&quot;,           system_error,            exception)
++
++usb_error::usb_error(int code, const std::string &amp;what):
++    runtime_error(str(boost::format(&quot;%s %d: %s&quot;) % &quot;USBError&quot; % code % what)){_code = code;}
++unsigned usb_error::code(void) const{return _code;} \
++usb_error *usb_error::dynamic_clone(void) const{return new usb_error(*this);} \
++void usb_error::dynamic_throw(void) const{throw *this;}
+--- host/lib/transport/libusb1_zero_copy.cpp.orig
++++ host/lib/transport/libusb1_zero_copy.cpp
+@@ -155,7 +155,7 @@ public:
+         result.is_recv = _is_recv;
+ #endif
+         const int ret = libusb_submit_transfer(_lut);
+-        if (ret != 0) throw uhd::runtime_error(str(boost::format(
++        if (ret != 0) throw uhd::usb_error(ret, str(boost::format(
+             &quot;usb %s submit failed: %s&quot;) % _name % libusb_error_name(ret)));
+     }

+@@ -266,17 +266,26 @@ public:
+             _all_luts.push_back(lut);
+         }

+-        //initial release for all buffers
+-        for (size_t i = 0; i &lt; get_num_frames(); i++)
++        size_t i = 0;
++        //try
+         {
+-            libusb_zero_copy_mb &amp;mb = *(_mb_pool[i]);
+-            if (is_recv) mb.release();
+-            else
++            //initial release for all buffers
++            for (; i &lt; get_num_frames(); i++)
+             {
+-                mb.result.completed = 1;
+-                _enqueued.push_back(&amp;mb);
++                //UHD_MSG(status) &lt;&lt; &quot;Releasing &quot; &lt;&lt; i &lt;&lt; std::endl;
++                libusb_zero_copy_mb &amp;mb = *(_mb_pool[i]);
++                if (is_recv) mb.release();
++                else
++                {
++                    mb.result.completed = 1;
++                    _enqueued.push_back(&amp;mb);
++                }
+             }
+         }
++        //catch (uhd::runtime_error&amp; e)
++        {
++        //    UHD_MSG(status) &lt;&lt; &quot;Releasing &quot; &lt;&lt; i &lt;&lt; &quot;:&quot; &lt;&lt; e.what() &lt;&lt; std::endl;
++        }
+     }

+     ~libusb_zero_copy_single(void)
+--- host/lib/usrp/b200/b200_impl.cpp.orig
++++ host/lib/usrp/b200/b200_impl.cpp
+@@ -37,6 +37,9 @@
+ #include &lt;ctime&gt;
+ #include &lt;cmath&gt;

++#include &lt;uhd/transport/usb_zero_copy.hpp&gt;
++#include &quot;../../transport/libusb1_base.hpp&quot;
++
+ using namespace uhd;
+ using namespace uhd::usrp;
+ using namespace uhd::transport;
+@@ -194,7 +197,44 @@ static device_addrs_t b200_find(const device_addr_t &amp;hint)
+  **********************************************************************/
+ static device::sptr b200_make(const device_addr_t &amp;device_addr)
+ {
+-    return device::sptr(new b200_impl(device_addr));
++    b200_impl* p = NULL;
++
++    for (int i = 0; i &lt; 2; ++i)
++    {
++        p = new b200_impl();
++        int ret;
++        
++        ret = p-&gt;make(device_addr);
++        if (ret == LIBUSB_SUCCESS)
++            break;
++
++        {
++            libusb::device_handle::sptr dev_handle(libusb::device_handle::get_cached_handle(
++                boost::static_pointer_cast&lt;libusb::special_handle&gt;(p-&gt;get_handle())-&gt;get_device()
++            ));
++
++            ret = libusb_clear_halt(dev_handle-&gt;get(), 8 | 0x80);
++            UHD_MSG(status) &lt;&lt; &quot;Ctrl Recv clear: &quot; &lt;&lt; libusb_error_name(ret) &lt;&lt; std::endl;
++            ret = libusb_clear_halt(dev_handle-&gt;get(), 4 | 0x00);
++            UHD_MSG(status) &lt;&lt; &quot;Ctrl Send clear: &quot; &lt;&lt; libusb_error_name(ret) &lt;&lt; std::endl;
++
++            ret = libusb_clear_halt(dev_handle-&gt;get(), 6 | 0x80);
++            UHD_MSG(status) &lt;&lt; &quot;Data Recv clear: &quot; &lt;&lt; libusb_error_name(ret) &lt;&lt; std::endl;
++            ret = libusb_clear_halt(dev_handle-&gt;get(), 2 | 0x00);
++            UHD_MSG(status) &lt;&lt; &quot;Data Send clear: &quot; &lt;&lt; libusb_error_name(ret) &lt;&lt; std::endl;
++
++            ret = libusb_reset_device(dev_handle-&gt;get());
++            UHD_MSG(status) &lt;&lt; &quot;Dev Reset: &quot; &lt;&lt; libusb_error_name(ret) &lt;&lt; std::endl;
++        }
++
++        delete p;
++        p = NULL;
++    }
++
++    if (p == NULL)
++        throw uhd::runtime_error(&quot;USB error&quot;);
++
++    return device::sptr(p);
+ }

+ UHD_STATIC_BLOCK(register_b200_device)
+@@ -205,10 +245,14 @@ UHD_STATIC_BLOCK(register_b200_device)
+ /***********************************************************************
+  * Structors
+  **********************************************************************/
+-b200_impl::b200_impl(const device_addr_t &amp;device_addr) :
++b200_impl::b200_impl(void) :
+     _revision(0),
+     _tick_rate(0.0) // Forces a clock initialization at startup
+ {
++}
++
++int b200_impl::make(const uhd::device_addr_t&amp; device_addr)
++{
+     _tree = property_tree::make();
+     _type = device::USRP;
+     const fs_path mb_path = &quot;/mboards/0&quot;;
+@@ -262,17 +306,17 @@ b200_impl::b200_impl(const device_addr_t &amp;device_addr) :
+     std::vector&lt;usb_device_handle::sptr&gt; device_list = usb_device_handle::get_device_list(vid_pid_pair_list);

+     //locate the matching handle in the device list
+-    usb_device_handle::sptr handle;
++    //usb_device_handle::sptr _handle;
+     BOOST_FOREACH(usb_device_handle::sptr dev_handle, device_list) {
+         if (dev_handle-&gt;get_serial() == device_addr[&quot;serial&quot;]){
+-            handle = dev_handle;
++            _handle = dev_handle;
+             break;
+         }
+     }
+-    UHD_ASSERT_THROW(handle.get() != NULL); //better be found
++    UHD_ASSERT_THROW(_handle.get() != NULL); //better be found

+     //create control objects
+-    usb_control::sptr control = usb_control::make(handle, 0);
++    usb_control::sptr control = usb_control::make(_handle, 0);
+     _iface = b200_iface::make(control);
+     this-&gt;check_fw_compat(); //check after making

+@@ -360,12 +404,22 @@ b200_impl::b200_impl(const device_addr_t &amp;device_addr) :
+     ctrl_xport_args[&quot;send_frame_size&quot;] = min_frame_size;
+     ctrl_xport_args[&quot;num_send_frames&quot;] = &quot;16&quot;;

+-    _ctrl_transport = usb_zero_copy::make(
+-        handle,
+-        4, 8, //interface, endpoint
+-        3, 4, //interface, endpoint
+-        ctrl_xport_args
+-    );
++    UHD_MSG(status) &lt;&lt; &quot;Creating ctrl transport...&quot; &lt;&lt; std::endl;
++    try
++    {
++        _ctrl_transport = usb_zero_copy::make(
++            _handle,
++            4, 8, //interface, endpoint
++            3, 4, //interface, endpoint
++            ctrl_xport_args
++        );
++    }
++    catch (const uhd::usb_error&amp; e)
++    {
++        UHD_MSG(status) &lt;&lt; e.what() &lt;&lt; std::endl;
++        return e.code();
++    }
++    UHD_MSG(status) &lt;&lt; &quot;Flusing ctrl recv buff...&quot; &lt;&lt; std::endl;
+     while (_ctrl_transport-&gt;get_recv_buff(0.0)){} //flush ctrl xport
+     _tree-&gt;create&lt;double&gt;(mb_path / &quot;link_max_rate&quot;).set((usb_speed == 3) ? B200_MAX_RATE_USB3 : B200_MAX_RATE_USB2);

+@@ -442,12 +496,22 @@ b200_impl::b200_impl(const device_addr_t &amp;device_addr) :
+     data_xport_args[&quot;send_frame_size&quot;] = device_addr.get(&quot;send_frame_size&quot;, &quot;8192&quot;);
+     data_xport_args[&quot;num_send_frames&quot;] = device_addr.get(&quot;num_send_frames&quot;, &quot;16&quot;);

+-    _data_transport = usb_zero_copy::make(
+-        handle,        // identifier
+-        2, 6,          // IN interface, endpoint
+-        1, 2,          // OUT interface, endpoint
+-        data_xport_args    // param hints
+-    );
++    UHD_MSG(status) &lt;&lt; &quot;Creating data transport...&quot; &lt;&lt; std::endl;
++    try
++    {
++        _data_transport = usb_zero_copy::make(
++            _handle,        // identifier
++            2, 6,          // IN interface, endpoint
++            1, 2,          // OUT interface, endpoint
++            data_xport_args    // param hints
++        );
++    }
++    catch (const uhd::usb_error&amp; e)
++    {
++        UHD_MSG(status) &lt;&lt; e.what() &lt;&lt; std::endl;
++        return e.code();
++    }
++    UHD_MSG(status) &lt;&lt; &quot;Flusing data recv buff...&quot; &lt;&lt; std::endl;
+     while (_data_transport-&gt;get_recv_buff(0.0)){} //flush ctrl xport
+     _demux = recv_packet_demuxer_3000::make(_data_transport);

+@@ -624,6 +688,9 @@ b200_impl::b200_impl(const device_addr_t &amp;device_addr) :
+         _tree-&gt;access&lt;std::string&gt;(mb_path / &quot;time_source/value&quot;).set(&quot;internal&quot;);
+     }

++    _handle.reset();
++
++    return LIBUSB_SUCCESS;
+ }

+ b200_impl::~b200_impl(void)
+--- host/lib/usrp/b200/b200_impl.hpp.orig
++++ host/lib/usrp/b200/b200_impl.hpp
+@@ -91,9 +91,13 @@ class b200_impl : public uhd::device
+ {
+ public:
+     //structors
+-    b200_impl(const uhd::device_addr_t &amp;);
++    b200_impl(void);
+     ~b200_impl(void);

++    int make(const uhd::device_addr_t &amp;);
++    uhd::transport::usb_device_handle::sptr get_handle(void) const
++    { return _handle; }
++
+     //the io interface
+     uhd::rx_streamer::sptr get_rx_stream(const uhd::stream_args_t &amp;args);
+     uhd::tx_streamer::sptr get_tx_stream(const uhd::stream_args_t &amp;args);
+@@ -107,6 +111,8 @@ public:
+     void check_streamer_args(const uhd::stream_args_t &amp;args, double tick_rate, const std::string &amp;direction = &quot;&quot;);

+ private:
++    uhd::transport::usb_device_handle::sptr _handle;
++
+     b200_type_t _b200_type;
+     size_t      _revision;

+-- 
+2.3.1
+
</ins></span></pre></div>
<a id="trunkdportsscienceuhdfilespatchhost_utils_uhd_images_downloaderpyindiff"></a>
<div class="delfile"><h4>Deleted: trunk/dports/science/uhd/files/patch-host_utils_uhd_images_downloader.py.in.diff (139127 => 139128)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/dports/science/uhd/files/patch-host_utils_uhd_images_downloader.py.in.diff        2015-08-03 15:39:55 UTC (rev 139127)
+++ trunk/dports/science/uhd/files/patch-host_utils_uhd_images_downloader.py.in.diff        2015-08-03 15:42:41 UTC (rev 139128)
</span><span class="lines">@@ -1,362 +0,0 @@
</span><del>---- host/utils/uhd_images_downloader.py.in.orig
-+++ host/utils/uhd_images_downloader.py.in
-@@ -1,6 +1,6 @@
- #!/usr/bin/env python
- #
--# Copyright 2012-2014 Ettus Research LLC
-+# Copyright 2012-2015 Ettus Research LLC
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
-@@ -23,7 +23,7 @@ import math
- import traceback
- import shutil
- import hashlib
--import urllib2
-+import requests
- import zipfile

- from optparse import OptionParser
-@@ -47,8 +47,8 @@ def md5Checksum(filePath):
-                     break
-                 m.update(data)
-             return m.hexdigest()
--    except Exception, e:
--        print &quot;Failed to calculated MD5 sum of: %s (%s)&quot; % (filePath, e)
-+    except Exception as e:
-+        print(&quot;Failed to calculated MD5 sum of: %s (%s)&quot; % (filePath, e))
-         raise e

- _checksum_fns = {
-@@ -60,16 +60,16 @@ class temporary_directory():
-         try:
-             self.name = tempfile.mkdtemp()
-             return self.name
--        except Exception, e:
--            print &quot;Failed to create a temporary directory (%s)&quot; % (e)
-+        except Exception as e:
-+            print(&quot;Failed to create a temporary directory (%s)&quot; % (e))
-             raise e

-     # Can return 'True' to suppress incoming exception
-     def __exit__(self, type, value, traceback):
-         try:
-             shutil.rmtree(self.name)
--        except Exception, e:
--            print &quot;Could not delete temporary directory: %s (%s)&quot; % (self.name, e)
-+        except Exception as e:
-+            print(&quot;Could not delete temporary directory: %s (%s)&quot; % (self.name, e))

- class uhd_images_downloader():
-     def __init__(self):
-@@ -77,25 +77,20 @@ class uhd_images_downloader():

-     def download(self, images_url, filename, buffer_size=_DEFAULT_BUFFER_SIZE, print_progress=False):
-         &quot;&quot;&quot; Run the download, show progress &quot;&quot;&quot;
--        opener = urllib2.build_opener()
--        opener.add_headers = [('User-Agent', 'UHD Images Downloader')]
--        u = opener.open(images_url)
--        meta = u.info()
--        filesize = float(meta.getheaders(&quot;Content-Length&quot;)[0])
-+        r = requests.get(images_url, stream=True, headers={'User-Agent': 'UHD Images Downloader'})
-+        filesize = float(r.headers['content-length'])
-         filesize_dl = 0
-         with open(filename, &quot;wb&quot;) as f:
--            while True:
--                buff = u.read(buffer_size)
--                if not buff:
--                    break
--                f.write(buff)
--                filesize_dl += len(buff)
-+            for buff in r.iter_content(chunk_size=buffer_size):
-+                if buff:
-+                    f.write(buff)
-+                    filesize_dl += len(buff)
-                 if print_progress:
-                     status = r&quot;%05d kB / %05d kB (%03d%%)&quot; % (int(math.ceil(filesize_dl/1000.)), int(math.ceil(filesize/1000.)), int(math.ceil(filesize_dl*100.)/filesize))
-                     status += chr(8)*(len(status)+1)
--                    print status,
-+                    sys.stdout.write(status)
-         if print_progress:
--            print
-+            print('')
-         return (filesize, filesize_dl)

-     def check_directories(self, dirs, print_progress=False):
-@@ -105,23 +100,23 @@ class uhd_images_downloader():

-         def _check_part(head, tail=None):
-             if print_progress:
--                print &quot;Checking: %s&quot; % (head)
-+                print(&quot;Checking: %s&quot; % (head))
-             if tail is not None and tail == &quot;&quot;:
-                 return True
-             if not os.path.exists(head):
-                 if print_progress:
--                    print &quot;Does not exist: %s&quot; % (head)
-+                    print(&quot;Does not exist: %s&quot; % (head))
-                 return _check_part(*os.path.split(head))
-             if not os.path.isdir(head):
-                 if print_progress:
--                    print &quot;Is not a directory: %s&quot; % (head)
-+                    print(&quot;Is not a directory: %s&quot; % (head))
-                 return (False, head)
-             if not os.access(head, os.W_OK):
-                 if print_progress:
--                    print &quot;Write permission denied on: %s&quot; % (head)
-+                    print(&quot;Write permission denied on: %s&quot; % (head))
-                 return (False, head)
-             if print_progress:
--                print &quot;Write permission granted on: %s&quot; % (head)
-+                print(&quot;Write permission granted on: %s&quot; % (head))
-             return (True, head)

-         return _check_part(dirs)
-@@ -137,34 +132,34 @@ class uhd_images_downloader():
-     def extract_images_archive(self, archive_path, destination=None, print_progress=False):
-         if not os.path.exists(archive_path):
-             if print_progress:
--                print &quot;Path does not exist: %s&quot; % (archive_path)
-+                print(&quot;Path does not exist: %s&quot; % (archive_path))
-             raise Exception(&quot;path does not exist: %s&quot; % (archive_path))
-         if print_progress:
--            print &quot;Archive path: %s&quot; % (archive_path)
-+            print(&quot;Archive path: %s&quot; % (archive_path))
-         (head, tail) = os.path.split(archive_path)

-         if not os.access(head, os.W_OK):
-             if print_progress:
--                print &quot;Write access denied on: %s&quot; % (head)
-+                print(&quot;Write access denied on: %s&quot; % (head))
-             raise Exception(&quot;write access denied on: %s&quot; % (head))

-         (root, ext) = os.path.splitext(tail)
-         temp_dir = os.path.join(head, root)

-         if print_progress:
--            print &quot;Temporary extraction location: %s&quot; % (temp_dir)
-+            print(&quot;Temporary extraction location: %s&quot; % (temp_dir))

-         if os.path.exists(temp_dir):
-             if print_progress:
--                print &quot;Deleting existing location: %s&quot; % (temp_dir)
-+                print(&quot;Deleting existing location: %s&quot; % (temp_dir))
-             shutil.rmtree(temp_dir)

-         if print_progress:
--            print &quot;Creating directory: %s&quot; % (temp_dir)
-+            print(&quot;Creating directory: %s&quot; % (temp_dir))
-         os.mkdir(temp_dir)

-         if print_progress:
--            print &quot;Extracting archive %s to %s&quot; % (archive_path, temp_dir)
-+            print(&quot;Extracting archive %s to %s&quot; % (archive_path, temp_dir))

-         images_zip = zipfile.ZipFile(archive_path)
-         images_zip.extractall(temp_dir)
-@@ -175,27 +170,27 @@ class uhd_images_downloader():
-     def install_images(self, source, dest, keep=False, print_progress=False):
-         if not os.path.exists(source):
-             if print_progress:
--                print &quot;Source path does not exist: %s&quot; % (source)
-+                print(&quot;Source path does not exist: %s&quot; % (source))
-             return

-         if keep:
-             if print_progress:
--                print &quot;Not wiping directory tree (existing files will be overwritten): %s&quot; % (dest)
-+                print(&quot;Not wiping directory tree (existing files will be overwritten): %s&quot; % (dest))
-         elif os.path.exists(dest):
-             if print_progress:
--                print &quot;Deleting directory tree: %s&quot; % (dest)
-+                print(&quot;Deleting directory tree: %s&quot; % (dest))
-             shutil.rmtree(dest)

-         (head, tail) = os.path.split(source)

-         if print_progress:
--            print &quot;Source install path: %s&quot; % (source)
-+            print(&quot;Source install path: %s&quot; % (source))

-         uhd_source = os.path.join(source, tail, *_BASE_DIR_STRUCTURE_PARTS)

-         if print_progress:
--            print &quot;Copying files from: %s&quot; % (uhd_source)
--            print &quot;Copying files to:   %s&quot; % (dest)
-+            print(&quot;Copying files from: %s&quot; % (uhd_source))
-+            print(&quot;Copying files to:   %s&quot; % (dest))

-         if keep:
-             # mgrant @ http://stackoverflow.com/questions/12683834/how-to-copy-directory-recursively-in-python-and-overwrite-all
-@@ -222,12 +217,12 @@ def main():
-     ### Set defaults from env variables
-     if os.environ.get(&quot;UHD_IMAGES_DIR&quot;) != None and os.environ.get(&quot;UHD_IMAGES_DIR&quot;) != &quot;&quot;:
-         default_images_dir = os.environ.get(&quot;UHD_IMAGES_DIR&quot;)
--        print &quot;UHD_IMAGES_DIR environment variable is set.\nDefault install location: {0}&quot;.format(default_images_dir)
-+        print(&quot;UHD_IMAGES_DIR environment variable is set.\nDefault install location: {0}&quot;.format(default_images_dir))
-     else:
-         default_images_dir = _DEFAULT_INSTALL_PATH
-     if os.environ.get(&quot;UHD_IMAGES_BASE_URL&quot;) != None and os.environ.get(&quot;UHD_IMAGES_BASE_URL&quot;) != &quot;&quot;:
-         default_base_url = os.environ.get(&quot;UHD_IMAGES_BASE_URL&quot;)
--        print &quot;UHD_IMAGES_BASE_URL environment variable is set.\nDefault base URL: {0}&quot;.format(default_base_url)
-+        print(&quot;UHD_IMAGES_BASE_URL environment variable is set.\nDefault base URL: {0}&quot;.format(default_base_url))
-     else:
-         default_base_url = _DEFAULT_BASE_URL

-@@ -244,22 +239,22 @@ def main():
-     parser.add_option(&quot;-c&quot;, &quot;--checksum&quot;,           type=&quot;string&quot;,          default=_AUTOGEN_IMAGES_CHECKSUM,
-                         help=&quot;Validate images archive against this checksum (blank to skip) [default=%default]&quot;)
-     parser.add_option(&quot;-t&quot;, &quot;--checksum-type&quot;,      type=&quot;string&quot;,          default=_IMAGES_CHECKSUM_TYPE,
--                        help=(&quot;Select checksum hash function (options: %s) [default=%%default]&quot; % (&quot;,&quot;.join(_checksum_fns.keys()))))
-+                        help=(&quot;Select checksum hash function (options: %s) [default=%%default]&quot; % (&quot;,&quot;.join(list(_checksum_fns.keys())))))
-     parser.add_option(&quot;-k&quot;, &quot;--keep&quot;,               action=&quot;store_true&quot;,    default=False,
-                         help=&quot;Do not clear images directory before extracting new files [default=%default]&quot;)
-     parser.add_option(&quot;-v&quot;, &quot;--verbose&quot;,            action=&quot;store_true&quot;,    default=False,
-                         help=&quot;Enable verbose output [default=%default]&quot;)
-     (options, args) = parser.parse_args()
-     if options.buffer_size &lt;= 0:
--        print &quot;Invalid buffer size: %s&quot; % (options.buffer_size)
-+        print(&quot;Invalid buffer size: %s&quot; % (options.buffer_size))
-         return 1

-     ### Select checksum algorithm (MD5)
-     checksum_fn = None
-     if options.checksum != &quot;&quot;:
-         options.checksum_type = options.checksum_type.lower()
--        if not _checksum_fns.has_key(options.checksum_type):
--            print &quot;Not a supported checksum function: %s&quot; % (options.checksum_type)
-+        if options.checksum_type not in _checksum_fns:
-+            print(&quot;Not a supported checksum function: %s&quot; % (options.checksum_type))
-             return 1
-         checksum_fn = _checksum_fns[options.checksum_type]

-@@ -275,30 +270,30 @@ def main():
-         base_url_is_local = True

-     if options.verbose:
--        print &quot;Requested install location: %s&quot; % (options.install_location)
--        print &quot;Images base URL:            %s&quot; % (options.base_url)
--        print &quot;Images filename:            %s&quot; % (options.filename)
--        print &quot;Images checksum:            %s (%s)&quot; % (options.checksum, _IMAGES_CHECKSUM_TYPE)
--        print &quot;Final install location:     %s&quot; % (images_dir)
--        print &quot;Copying locally:            {0}&quot;.format(&quot;Yes&quot; if base_url_is_local else &quot;No&quot;)
-+        print(&quot;Requested install location: %s&quot; % (options.install_location))
-+        print(&quot;Images base URL:            %s&quot; % (options.base_url))
-+        print(&quot;Images filename:            %s&quot; % (options.filename))
-+        print(&quot;Images checksum:            %s (%s)&quot; % (options.checksum, _IMAGES_CHECKSUM_TYPE))
-+        print(&quot;Final install location:     %s&quot; % (images_dir))
-+        print(&quot;Copying locally:            {0}&quot;.format(&quot;Yes&quot; if base_url_is_local else &quot;No&quot;))
-     else:
--        print &quot;Images destination:      %s&quot; % (images_dir)
-+        print(&quot;Images destination:      %s&quot; % (images_dir))

-     ### Download or copy
-     downloader = uhd_images_downloader()
-     try:
-         (access, last_path) = downloader.check_directories(images_dir, print_progress=options.verbose)
-         if not access:
--            print &quot;You do not have sufficient permissions to write to: %s&quot; % (last_path)
--            print &quot;Are you root?&quot;
-+            print(&quot;You do not have sufficient permissions to write to: %s&quot; % (last_path))
-+            print(&quot;Are you root?&quot;)
-             return 1
-         with temporary_directory() as temp_dir:
-             if options.verbose:
--                print &quot;Using temporary directory: %s&quot; % (temp_dir)
-+                print(&quot;Using temporary directory: %s&quot; % (temp_dir))
-             temp_images_dest = os.path.join(temp_dir, options.filename)
-             if not base_url_is_local:
--                print &quot;Downloading images from: {0}&quot;.format(images_url)
--                print &quot;Downloading images to:   {0}&quot;.format(temp_images_dest)
-+                print(&quot;Downloading images from: {0}&quot;.format(images_url))
-+                print(&quot;Downloading images to:   {0}&quot;.format(temp_images_dest))
-                 (reported_size, downloaded_size) = downloader.download(
-                         images_url=images_url,
-                         filename=temp_images_dest,
-@@ -306,12 +301,12 @@ def main():
-                         print_progress=True
-                 )
-                 if options.verbose:
--                    print &quot;Downloaded %d of %d bytes&quot; % (downloaded_size, reported_size)
-+                    print(&quot;Downloaded %d of %d bytes&quot; % (downloaded_size, reported_size))
-             else:
-                 local_images_pkg = os.path.join(options.base_url, options.filename)
--                print &quot;Copying images from:     {0}&quot;.format(local_images_pkg)
-+                print(&quot;Copying images from:     {0}&quot;.format(local_images_pkg))
-                 if not os.path.isfile(local_images_pkg):
--                    print &quot;[ERROR] No such file.&quot;
-+                    print(&quot;[ERROR] No such file.&quot;)
-                     return 1
-                 shutil.copyfile(local_images_pkg, temp_images_dest)
-             (checksum_match, calculated_checksum) = downloader.validate_checksum(
-@@ -321,48 +316,46 @@ def main():
-                     print_progress=options.verbose
-             )
-             if options.verbose:
--                print &quot;Calculated checksum: %s&quot; % (calculated_checksum)
-+                print(&quot;Calculated checksum: %s&quot; % (calculated_checksum))
-             if checksum_match:
-                 if options.verbose:
-                     if options.checksum == &quot;&quot;:
--                        print &quot;Ignoring checksum&quot;
-+                        print(&quot;Ignoring checksum&quot;)
-                     else:
--                        print &quot;Checksum OK&quot;
-+                        print(&quot;Checksum OK&quot;)
-                 try:
-                     extract_path = downloader.extract_images_archive(temp_images_dest, print_progress=options.verbose)
-                     if options.verbose:
--                        print &quot;Image archive extracted to: %s&quot; % (extract_path)
-+                        print(&quot;Image archive extracted to: %s&quot; % (extract_path))
-                     downloader.install_images(extract_path, images_dir, options.keep, print_progress=options.verbose)
-                     if options.verbose:
--                        print &quot;Cleaning up temp location: %s&quot; % (extract_path)
-+                        print(&quot;Cleaning up temp location: %s&quot; % (extract_path))
-                     shutil.rmtree(extract_path)
--                    print
--                    print &quot;Images successfully installed to: %s&quot; % (images_dir)
--                except Exception, e:
--                    print &quot;Failed to install image archive: %s&quot; % (e)
--                    print &quot;This is usually a permissions problem.&quot;
--                    print &quot;Please check your file system access rights and try again.&quot;
-+                    print(&quot;\nImages successfully installed to: %s&quot; % (images_dir))
-+                except Exception as e:
-+                    print(&quot;Failed to install image archive: %s&quot; % (e))
-+                    print(&quot;This is usually a permissions problem.&quot;)
-+                    print(&quot;Please check your file system access rights and try again.&quot;)
-                     if options.verbose:
-                         traceback.print_exc()
-                     else:
--                        print &quot;You can run this again with the '--verbose' flag to see more information&quot;
--                    print &quot;If the problem persists, please email the output to: %s&quot; % (_CONTACT)
-+                        print(&quot;You can run this again with the '--verbose' flag to see more information&quot;)
-+                    print(&quot;If the problem persists, please email the output to: %s&quot; % (_CONTACT))
-             else:
--                print &quot;Checksum of downloaded file is not correct (not installing - see options to override)&quot;
--                print &quot;Expected:   %s&quot; % (options.checksum)
--                print &quot;Calculated: %s&quot; % (calculated_checksum)
--                print &quot;Please try downloading again.&quot;
--                print &quot;If the problem persists, please email the output to: %s&quot; % (_CONTACT)
-+                print(&quot;Checksum of downloaded file is not correct (not installing - see options to override)&quot;)
-+                print(&quot;Expected:   %s&quot; % (options.checksum))
-+                print(&quot;Calculated: %s&quot; % (calculated_checksum))
-+                print(&quot;Please try downloading again.&quot;)
-+                print(&quot;If the problem persists, please email the output to: %s&quot; % (_CONTACT))
-     except KeyboardInterrupt:
--        print
--        print &quot;Cancelled at user request&quot;
--    except Exception, e:
--        print &quot;Downloader raised an unhandled exception: %s&quot; % (e)
-+        print(&quot;\nCancelled at user request&quot;)
-+    except Exception as e:
-+        print(&quot;Downloader raised an unhandled exception: %s&quot; % (e))
-         if options.verbose:
-             traceback.print_exc()
-         else:
--            print &quot;You can run this again with the '--verbose' flag to see more information&quot;
--        print &quot;If the problem persists, please email the output to: %s&quot; % (_CONTACT)
-+            print(&quot;You can run this again with the '--verbose' flag to see more information&quot;)
-+        print(&quot;If the problem persists, please email the output to: %s&quot; % (_CONTACT))
-         return 1
-     return 0

</del></span></pre>
</div>
</div>

</body>
</html>