Example #1
0
 def test_spin(self):
     output = StringIO()
     progress = ConsoleProgress('some name', output)
     progress.write_spin()
     progress.write_spin()
     expected = ''
     expected += '|' + (60 * '-') + '|\r'
     expected += '|' + (60 * '+') + '|\r'
     self.assert_equals_long(repr(expected), repr(output.getvalue()))
Example #2
0
 def test_spin(self):
     output = StringIO()
     progress = ConsoleProgress('some name', output)
     progress.write_spin()
     progress.write_spin()
     expected = ''
     expected += '|' + (60 * '-') + '|\r'
     expected += '|' + (60 * '+') + '|\r'
     self.assert_equals_long(repr(expected), repr(output.getvalue()))
Example #3
0
def get_remote_file_as_string(remote_url, progress=None):
    '''Returns the contents of a remote file as a string.'''
    result = StringIO()
    curl = pycurl.Curl()
    curl.setopt(curl.URL, remote_url)
    curl.setopt(curl.USERAGENT, 'pdk')
    curl.setopt(curl.FOLLOWLOCATION, True)
    curl.setopt(curl.MAXREDIRS, 5)
    curl.setopt(curl.AUTOREFERER, True)
    curl.setopt(curl.WRITEFUNCTION, result.write)
    curl.setopt(curl.NOPROGRESS, False)
    curl.setopt(curl.FAILONERROR, True)
    if not progress:
        progress = ConsoleProgress(remote_url)
    adapter = CurlAdapter(progress)
    curl.setopt(curl.PROGRESSFUNCTION, adapter.callback)
    curl_set_ssl(curl)
    curl_set_netrc(curl)

    try:
        progress.start()
        curl.perform()
        progress.done()
        curl.close()
    except pycurl.error, e:
        raise SemanticError, str(e)
Example #4
0
File: util.py Project: djibi2/pdk
def get_remote_file(remote_url, local_filename, trust_timestamp = False,
                    progress = None):
    '''Obtain a remote file via url.

    Copies the file to local_filename and attempts to set the last
    modified time.
    '''
    if os.path.exists(local_filename):
        mtime = os.stat(local_filename)[stat.ST_MTIME]
    else:
        mtime = None

    handle = LazyWriter(local_filename)

    curl = pycurl.Curl()
    curl.setopt(curl.URL, remote_url)
    curl.setopt(curl.USERAGENT, 'pdk')
    curl.setopt(curl.WRITEFUNCTION, handle.write)
    curl.setopt(curl.NOPROGRESS, False)
    curl.setopt(curl.FAILONERROR, True)
    curl.setopt(curl.OPT_FILETIME, True)
    if mtime is not None and trust_timestamp:
        curl.setopt(curl.TIMEVALUE, mtime)
        curl.setopt(curl.TIMECONDITION, curl.TIMECONDITION_IFMODSINCE)
    if not progress:
        progress = ConsoleProgress(remote_url)
    adapter = CurlAdapter(progress)
    curl.setopt(curl.PROGRESSFUNCTION, adapter.callback)
    curl_set_ssl(curl)
    curl_set_netrc(curl)

    progress.start()
    curl.perform()
    progress.done()
    handle.close()
    mtime = curl.getinfo(curl.INFO_FILETIME)
    curl.close()
    if mtime != -1:
        os.utime(local_filename, (mtime, mtime))
Example #5
0
File: util.py Project: djibi2/pdk
def get_remote_file_as_string(remote_url, progress = None):
    '''Returns the contents of a remote file as a string.'''
    result = StringIO()
    curl = pycurl.Curl()
    curl.setopt(curl.URL, remote_url)
    curl.setopt(curl.USERAGENT, 'pdk')
    curl.setopt(curl.WRITEFUNCTION, result.write)
    curl.setopt(curl.NOPROGRESS, False)
    curl.setopt(curl.FAILONERROR, True)
    if not progress:
        progress = ConsoleProgress(remote_url)
    adapter = CurlAdapter(progress)
    curl.setopt(curl.PROGRESSFUNCTION, adapter.callback)
    curl_set_ssl(curl)
    curl_set_netrc(curl)

    try:
        progress.start()
        curl.perform()
        progress.done()
        curl.close()
    except pycurl.error, e:
        raise SemanticError, str(e)
Example #6
0
def get_remote_file(remote_url,
                    local_filename,
                    trust_timestamp=False,
                    progress=None):
    '''Obtain a remote file via url.

    Copies the file to local_filename and attempts to set the last
    modified time.
    '''
    if os.path.exists(local_filename):
        mtime = os.stat(local_filename)[stat.ST_MTIME]
    else:
        mtime = None

    handle = LazyWriter(local_filename)

    curl = pycurl.Curl()
    curl.setopt(curl.URL, remote_url)
    curl.setopt(curl.USERAGENT, 'pdk')
    curl.setopt(curl.FOLLOWLOCATION, True)
    curl.setopt(curl.MAXREDIRS, 5)
    curl.setopt(curl.AUTOREFERER, True)
    curl.setopt(curl.WRITEFUNCTION, handle.write)
    curl.setopt(curl.NOPROGRESS, False)
    curl.setopt(curl.FAILONERROR, True)
    curl.setopt(curl.OPT_FILETIME, True)
    if mtime is not None and trust_timestamp:
        curl.setopt(curl.TIMEVALUE, mtime)
        curl.setopt(curl.TIMECONDITION, curl.TIMECONDITION_IFMODSINCE)
    if not progress:
        progress = ConsoleProgress(remote_url)
    adapter = CurlAdapter(progress)
    curl.setopt(curl.PROGRESSFUNCTION, adapter.callback)
    curl_set_ssl(curl)
    curl_set_netrc(curl)

    progress.start()
    curl.perform()
    progress.done()
    handle.close()
    mtime = curl.getinfo(curl.INFO_FILETIME)
    curl.close()
    if mtime != -1:
        os.utime(local_filename, (mtime, mtime))
Example #7
0
 def test_no_name(self):
     output = StringIO()
     progress = ConsoleProgress(None, output)
     progress.start()
     expected = ''
     self.assert_equals_long(repr(expected), repr(output.getvalue()))
Example #8
0
 def test_start(self):
     output = StringIO()
     progress = ConsoleProgress('some name', output)
     progress.start()
     expected = 'some name\n'
     self.assert_equals_long(repr(expected), repr(output.getvalue()))
Example #9
0
 def test_overflow(self):
     output = StringIO()
     progress = ConsoleProgress('some name', output)
     progress.write_bar(2, 4)
     expected = '|' + (60 * '=') + '|\r'
     self.assert_equals_long(repr(expected), repr(output.getvalue()))
Example #10
0
 def test_start(self):
     output = StringIO()
     progress = ConsoleProgress('some name', output)
     progress.start()
     expected = 'some name\n'
     self.assert_equals_long(repr(expected), repr(output.getvalue()))
Example #11
0
 def test_overflow(self):
     output = StringIO()
     progress = ConsoleProgress('some name', output)
     progress.write_bar(2, 4)
     expected = '|' + (60 * '=') + '|\r'
     self.assert_equals_long(repr(expected), repr(output.getvalue()))
Example #12
0
 def test_no_name(self):
     output = StringIO()
     progress = ConsoleProgress(None, output)
     progress.start()
     expected = ''
     self.assert_equals_long(repr(expected), repr(output.getvalue()))