Пример #1
0
def upload_pixbuf(pb):
    if pb is not None:
        ftmp = tempfile.NamedTemporaryFile(suffix='.png', prefix='', delete=False)
        pb.save_to_callback(ftmp.write, 'png')
        ftmp.flush()
        ftmp.close()
        image = ftmp.name
    else:
        return

    config = lookitconfig.LookitConfig()
    try:
        config.read(common.CONFIG_FILE)
    except:
        print 'An error occurred reading the configuration file'

    proto = config.get('Upload', 'type')

    if proto == 'SSH':
        common.show_notification('Uploading image', 'Uploading image to {0}'.format(config.get('Upload', 'hostname')))
        success, data = upload_file_sftp(image,
                    config.get('Upload', 'hostname'),
                    int(config.get('Upload', 'port')),
                    config.get('Upload', 'username'),
                    config.get('Upload', 'password'),
                    config.get('Upload', 'directory'),
                    config.get('Upload', 'url'),
                    )
    elif proto == 'FTP':
        common.show_notification('Uploading image', 'Uploading image to {0}'.format(config.get('Upload', 'hostname')))
        success, data = upload_file_ftp(image,
                    config.get('Upload', 'hostname'),
                    int(config.get('Upload', 'port')),
                    config.get('Upload', 'username'),
                    config.get('Upload', 'password'),
                    config.get('Upload', 'directory'),
                    config.get('Upload', 'url'),
                    )
    elif proto == 'Omploader':
        common.show_notification('Uploading image', 'Uploading image to Omploader')
        success, data = upload_file_omploader(image)
        try:
            f = open(common.LOG_FILE, 'ab')
            f.write(time.ctime() + ' Uploaded screenshot to Omploader: ' + data['original_image'] + '\n')
        except IOError, e:
            pass
        finally:
Пример #2
0
                 config.get('Upload', 'password'),
                 config.get('Upload', 'directory'),
                 config.get('Upload', 'url'),
                 )
 elif proto == 'Omploader':
     common.show_notification('Uploading image', 'Uploading image to Omploader')
     success, data = upload_file_omploader(image)
     try:
         f = open(common.LOG_FILE, 'ab')
         f.write(time.ctime() + ' Uploaded screenshot to Omploader: ' + data['original_image'] + '\n')
     except IOError, e:
         pass
     finally:
         f.close()
 elif proto == 'Imgur':
     common.show_notification('Uploading image', 'Uploading image to Imgur')
     success, data = upload_file_imgur(image)
     try:
         f = open(common.LOG_FILE, 'ab')
         f.write(time.ctime() + ' Uploaded screenshot to Imgur: ' + data['original_image'] + '\n')
         f.write('Delete url: ' + data['delete_page'] + '\n')
     except IOError, e:
         pass
     finally:
         f.close()
 elif proto == 'None':
     success = True
     data = False
 else:
     success = False
     data = "Error: no such protocol: {0}".format(proto)