Ejemplo n.º 1
0
	def attach(self, args):
		""" Attach a file to a bug given a filename. """
		filename = args.filename
		content_type = args.content_type
		bugid = args.bugid
		summary = args.summary
		is_patch = args.is_patch
		comment = args.comment

		if not os.path.exists(filename):
			raise BugzError('File not found: %s' % filename)

		if content_type is None:
			content_type = get_content_type(filename)

		if comment is None:
			comment = block_edit('Enter optional long description of attachment')

		if summary is None:
			summary = os.path.basename(filename)

		params = {}
		params['ids'] = [bugid]

		fd = open(filename, 'rb')
		params['data'] = xmlrpclib.Binary(fd.read())
		fd.close()

		params['file_name'] = os.path.basename(filename)
		params['summary'] = summary
		if not is_patch:
			params['content_type'] = content_type;
		params['comment'] = comment
		params['is_patch'] = is_patch
		result =  self.bzcall(self.bz.Bug.add_attachment, params)
		self.log("'%s' has been attached to bug %s" % (filename, bugid))
Ejemplo n.º 2
0
def main(parameters, arguments):
    """Main entry point.

    :param parameters: Command line parameters.
    :param arguments: Command line arguments.
    """
    address = "%s://%s:%s@%s:%s%s" % (PROTOCOL, parameters.username,
                                      parameters.password, parameters.server,
                                      parameters.port, ENDPOINT)
    print "Connecting to: %s" % hide_password(address)

    server = xmlrpclib.ServerProxy(address, verbose=VERBOSE)

    try:
        plugin_id, version_id = server.plugin.upload(
            xmlrpclib.Binary(open(arguments[0]).read()))
        print "Plugin ID: %s" % plugin_id
        print "Version ID: %s" % version_id
    except xmlrpclib.ProtocolError, err:
        print "A protocol error occurred"
        print "URL: %s" % hide_password(err.url, 0)
        print "HTTP/HTTPS headers: %s" % err.headers
        print "Error code: %d" % err.errcode
        print "Error message: %s" % err.errmsg
Ejemplo n.º 3
0
    def flush(self):
        '''
        Writes out the latest metadata information stored in memory
        to the metadata file.
        '''
        try:
            self.acquire_lock()

            # Write out to the local metadata storage.
            client = riak.RiakClient(host=self._config.get('metadata_server'))
            bucket = client.bucket(UKAI_METADATA_BUCKET)
            metadata_riak = bucket.new(self.name, data=self._metadata)
            metadata_riak.store()

            # Send the latest metadata information to all the
            # hypervisors listed in the hypervisor list of the metadata
            # information.
            for hv in self.hypervisors.keys():
                if UKAIIsLocalNode(hv):
                    continue
                try:
                    remote = xmlrpclib.ServerProxy(
                        'http://%s:%d/' % (hv, self._config.get('proxy_port')))
                    self._set_hypervisor_sync_status(hv, UKAI_IN_SYNC)
                    remote.proxy_update_metadata(
                        self.name,
                        xmlrpclib.Binary(
                            zlib.compress(json.dumps(self._metadata))))
                except (IOError, xmlrpclib.Error), e:
                    print e.__class__
                    print 'Failed to update metadata at %s.  You cannot migrate a virtual machine to %s' % (
                        hv, hv)
                    self._set_hypervisor_sync_status(hv, UKAI_OUT_OF_SYNC)

        finally:
            self.release_lock()
Ejemplo n.º 4
0
    def create_account(self, account_name, amount):
        """Create account with account_name starting amount

        Args:
            account_name(string): name for account
            amount(string): initial balance

        Returns:
            Returns random uuid (string) on Success.
                    False on Failure.

        """
        card_id = str(uuid.uuid4())
        try:
            amount = int(amount)
        except ValueError:
            logging.info('amount must be a integer')
            return False

        if self.db_obj.admin_create_account(account_name, card_id, amount):
            logging.info('admin create account success')
            return xmlrpclib.Binary(card_id)
        logging.info('admin create account failed')
        return False
Ejemplo n.º 5
0
    def get_pipeline_device_config(self, device_hostname):
        """
        Name
        ----
        `get_pipeline_device_config` (`device_hostname`)

        Description
        -----------
        Get the pipeline device configuration for given device hostname.

        Arguments
        ---------
        `device_hostname`: string
            Device hostname for which the configuration is required.

        Return value
        ------------
        This function returns an XML-RPC binary data of output file.
        """
        if not device_hostname:
            raise xmlrpclib.Fault(400, "Bad request: Device hostname was not "
                                  "specified.")

        element = DeviceDictionary.get(device_hostname)
        if element is None:
            raise xmlrpclib.Fault(404, "Specified device not found.")

        data = devicedictionary_to_jinja2(element.parameters,
                                          element.parameters['extends'])
        template = prepare_jinja_template(device_hostname, data, system_path=True)
        device_configuration = template.render()

        # validate against the device schema
        validate_device(yaml.load(device_configuration))

        return xmlrpclib.Binary(device_configuration.encode('UTF-8'))
Ejemplo n.º 6
0
    def get_wallet(self):
        """
        Return the xmlrpclib.Binary object with current wallet.
        For 'parity' it is gzipped tar archive of 'keys' directory.
        """
        try:
            res = check_output("tar czf /secrets/wallet.tgz *",
                               cwd='/secrets/keys',
                               stderr=STDOUT,
                               shell=True)
        except CalledProcessError as e:
            self.payload['status'] = 'Error'
            self.payload['data'] = 'RC {}: {}'.format(e.returncode, e.output)
            return self.payload

        try:
            with open('/secrets/wallet.tgz', 'rb') as w_bak:
                self.payload['data'] = xmlrpclib.Binary(w_bak.read())
            self.payload['file_type'] = 'tgz'
            self.payload['status'] = 'OK'
        except IOError:
            self.payload['data'] = 'Can not read /secrets/wallet.tgz'
            self.payload['status'] = 'Error'
        return self.payload
Ejemplo n.º 7
0
 def test_default(self):
     t = xmlrpclib.Binary()
     self.assertEqual(str(t), '')
Ejemplo n.º 8
0
 def _decodeData(self, data):
     """ Decode data. """
     binary_decoder = xmlrpclib.Binary()
     binary_decoder.decode(data)
     return binary_decoder.data
Ejemplo n.º 9
0
    def start_analysis(self, options):
        """Start analysis.
        @param options: options.
        @return: operation status.
        """
        log.info("Starting analysis on guest (id=%s, ip=%s)", self.id, self.ip)

        # TODO: deal with unicode URLs.
        if options["category"] == "file":
            options["file_name"] = sanitize_filename(options["file_name"])

        # If the analysis timeout is higher than the critical timeout,
        # automatically increase the critical timeout by one minute.
        if options["timeout"] > self.timeout:
            log.debug("Automatically increased critical timeout to %s",
                      self.timeout)
            self.timeout = options["timeout"] + 60

        # Get and set dynamically generated resultserver port.
        options["port"] = str(ResultServer().port)

        try:
            # Wait for the agent to respond. This is done to check the
            # availability of the agent and verify that it's ready to receive
            # data.
            if self.platform == "android_device":
                self._fm = FridaManager(self.ip, options)

            self.wait(CUCKOO_GUEST_INIT)

            # Invoke the upload of the analyzer to the guest.
            self.upload_analyzer()

            # Give the analysis options to the guest, so it can generate the
            # analysis.conf inside the guest.
            try:
                self.server.add_config(options)
            except:
                raise CuckooGuestError("{0}: unable to upload config to "
                                       "analysis machine".format(self.id))

            # If the target of the analysis is a file, upload it to the guest.
            if options["category"] == "file":
                try:
                    file_data = open(options["target"], "rb").read()
                except (IOError, OSError) as e:
                    raise CuckooGuestError("Unable to read {0}, error: "
                                           "{1}".format(options["target"], e))

                data = xmlrpclib.Binary(file_data)

                try:
                    self.server.add_malware(data, options["file_name"])
                except Exception as e:
                    raise CuckooGuestError("{0}: unable to upload malware to "
                                           "analysis machine: {1}".format(
                                               self.id, e))

            # Launch the analyzer.
            if self._fm:
                self._fm.init()
                self._fm.start()
                self._fm.wait_for_startup()

            pid = self.server.execute()
            log.debug("%s: analyzer started with PID %d", self.id, pid)

        # If something goes wrong when establishing the connection, raise an
        # exception and abort the analysis.
        except (socket.timeout, socket.error):
            raise CuckooGuestError("{0}: guest communication timeout, check "
                                   "networking or try to increase "
                                   "timeout".format(self.id))
Ejemplo n.º 10
0
import xmlrpclib

proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
image_data = xmlrpclib.Binary(open('test_image.jpg').read())
# url = "http://mmbiz.qpic.cn/mmbiz_jpg/YnnndYgX6CibQ8kgxLcNDmakc2WAyRdw9ye6vrWVCFZZMAwNylOFgF4gV1BKCLoT5hdugS7KvjcsElnic7zVIiclg/0"

print "3 is even: %s" % str(proxy.get_score(image_data))
Ejemplo n.º 11
0
 def passwords_getitem(self, key):
     newkey, buf = PAW2_Buffer.pack(self.storage.passwords[key])
     return xmlrpclib.Binary(buf)
Ejemplo n.º 12
0
#!/usr/bin/python

from __future__ import with_statement
import sys, string, xmlrpclib, re, os

if len(sys.argv) < 5:
    exit("Usage: " + sys.argv[0] + " spacekey pagetitle contentType filename")

spacekey = sys.argv[1]
pagetitle = sys.argv[2]
contentType = sys.argv[3]
filename = sys.argv[4]

with open(filename, 'rb') as f:
    data = f.read()
    # slurp all the data

server = xmlrpclib.ServerProxy('https://your-url/confluence/rpc/xmlrpc')
token = server.confluence2.login('your-login', 'your-password')
page = server.confluence2.getPage(token, spacekey, pagetitle)
if page is None:
    exit("Could not find page " + spacekey + ":" + pagetitle)

attachment = {}
attachment['fileName'] = os.path.basename(filename)
attachment['contentType'] = contentType

server.confluence2.addAttachment(token, page['id'], attachment,
                                 xmlrpclib.Binary(data))
Ejemplo n.º 13
0
 def _handle_binary(self, arg):
     try:
         arg = str(arg)
     except UnicodeError:
         raise ValueError('Cannot represent %r as binary.' % arg)
     return xmlrpclib.Binary(arg)
Ejemplo n.º 14
0
def upload_file():
    with open(filepath, "rb") as handle:
        binary_data = xmlrpclib.Binary(handle.read())
    proxy.server_receive_file(filename, binary_data)
Ejemplo n.º 15
0
    def installWindows(self, version, build, arch):
        self.windows = True

        if not os.path.exists(
                "%s/%s/%s/autoinstall-%s.zip" %
            (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch)):
            if not os.path.exists(
                    "%s/%s/%s/autoinstall-%s.tar" %
                (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch)):
                raise xenrt.XRTError("No install files found for %s build %s" %
                                     (version, build))

        if version == "longhorn" or version[0:7] == "vistaee":
            method = "longhorn"
        else:
            method = "normal"
        self.distro = version

        xenrt.TEC().progress("Preparing TFTP...")
        tftp = "%s/xenrt/native" % (xenrt.TEC().lookup("TFTP_BASE"))
        if not os.path.exists(tftp):
            xenrt.sudo("mkdir -p %s" % (tftp))
        xenrt.getTestTarball("native", extract=True)
        xenrt.sudo("rsync -avxl %s/winpe32.wim %s/winpe.wim" %
                   (xenrt.TEC().lookup("IMAGES_ROOT"), tftp))

        # Get a PXE directory to put boot files in.
        xenrt.TEC().progress("Preparing PXE...")
        serport = xenrt.TEC().lookup("SERIAL_CONSOLE_PORT", "0")
        serbaud = xenrt.TEC().lookup("SERIAL_CONSOLE_BAUD", "115200")
        pxe = xenrt.PXEBoot()
        pxe.copyIn("%s/native/pxe/pxeboot.0" % (xenrt.TEC().getWorkdir()))
        xenrt.sudo("rsync -avxl %s/native/pxe/32/BCD %s/BCD" %
                   (xenrt.TEC().getWorkdir(), tftp))
        xenrt.sudo("rsync -avxl %s/native/pxe/boot.sdi %s/boot.sdi" %
                   (xenrt.TEC().getWorkdir(), tftp))
        xenrt.sudo("rsync -avxl %s/native/pxe/bootmgr.exe %s/bootmgr.exe" %
                   (xenrt.TEC().getWorkdir(), tftp))

        # Set the boot files and options for PXE
        pxe.setSerial(serport, serbaud)
        pxe.addEntry("local", boot="local")
        pxecfg = pxe.addEntry("winpe", default=1, boot="linux")
        pxecfg.linuxSetKernel("pxeboot.0")

        xenrt.TEC().progress("Preparing web directory")
        w = xenrt.WebDirectory()

        f = file("%s/native/pe/perun.cmd" % (xenrt.TEC().getWorkdir()), "r")
        perun = f.read()
        f.close()

        if method == "longhorn":
            t = xenrt.TempDirectory()

            xenrt.command("tar xf %s/%s/%s/autoinstall-%s.tar -C %s" %
                          (xenrt.TEC().lookup("IMAGES_ROOT"), version, build,
                           arch, t.path()))

            w.copyIn("%s/install/unattend.xml" % (t.path()))
            perun += "wget %FILES%/unattend.xml\n"

            # Count the number of install.wim fragments.
            catcmd = "cat "
            partpath = "%s/install/install.part" % (t.path())
            numparts = len(glob.glob("%s*" % (partpath)))
            for i in range(1, numparts + 1):
                # Download install.wim fragment.
                perun += "wget %%FILES%%/%s%d\n" % (os.path.basename(partpath),
                                                    i)
                # Make sure fragments get recombined.
                catcmd += "%s%d " % (os.path.basename(partpath), i)
                # Make fragment available over the network.
                w.copyIn("%s%d" % (partpath, i))
            catcmd += "> c:\\win\\sources\\install.wim\n"
            perun += catcmd
            w.copyIn("%s/install/install.zip" % (t.path()), target="win.zip")

            t.remove()

            # 32-bit installs just require the one stage.
            if arch == "x86-32":
                perun += "c:\\win\\sources\\setup.exe /unattend:c:\\unattend.xml"
        else:
            t = xenrt.TempDirectory()

            xenrt.command(
                "unzip %s/%s/%s/autoinstall-%s.zip unattend.txt -d %s" %
                (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch,
                 t.path()))
            try:
                xenrt.command(
                    "unzip %s/%s/%s/autoinstall-%s.zip runonce.cmd -d %s" %
                    (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch,
                     t.path()))
            except:
                try:
                    xenrt.command(
                        "unzip %s/%s/%s/autoinstall-%s.zip win/i386/runonce.cmd -d %s"
                        % (xenrt.TEC().lookup("IMAGES_ROOT"), version, build,
                           arch, t.path()))
                except:
                    xenrt.command(
                        "unzip %s/%s/%s/autoinstall-%s.zip win/I386/runonce.cmd -d %s"
                        % (xenrt.TEC().lookup("IMAGES_ROOT"), version, build,
                           arch, t.path()))
                xenrt.command("mv %s/win/?386/runonce.cmd %s/runonce.cmd" %
                              (t.path(), t.path()))
            xenrt.command("chmod a+rwx %s/runonce.cmd" % (t.path()))

            perun += """
wget %FILES%/runonce.cmd
wget %FILES%/unattend.txt
bootsect /nt52 c: /force
c:\win\i386\winnt32.exe /makelocalsource /syspart:c: /s:c:\win\i386 /unattend:c:\unattend.txt /cmd:c:\runonce.cmd
wpeutil reboot
"""
            f = file("%s/runonce.cmd" % (t.path()), "r")
            data = f.read()
            f.close()
            # HACK to support Broadcom NICs on those machines that have them.
            if xenrt.TEC().lookup("BROADCOM_POSTINSTALL", False, boolean=True):
                data = string.replace(data, "EXIT", "")
                data = data + 'REG ADD %KEY%\\050 /VE /D "Broadcom Driver" /f\n'
                data = data + 'REG ADD %KEY%\\050 /V 1 /D ' \
                       '"%systemdrive%\\win\\post\\Broadcom\\setup.exe ' \
                       '/s /v/qn" /f\n'
                data = data + "EXIT\n"

            xenrt.TEC().copyToLogDir("%s/runonce.cmd" % (t.path()))
            f = file("%s/runonce.cmd" % (t.path()), "w")
            f.write(data)
            f.close()
            w.copyIn("%s/unattend.txt" % (t.path()))
            w.copyIn("%s/runonce.cmd" % (t.path()))
            w.copyIn("%s/%s/%s/autoinstall-%s.zip" %
                     (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch),
                     target="win.zip")
            t.remove()

        # Copy common files.
        w.copyIn("%s/native/pe/makepart.txt" % (xenrt.TEC().getWorkdir()))

        perun_dir = os.path.dirname(xenrt.TEC().lookup("WINPE_START_FILE"))
        if not os.path.exists(perun_dir):
            xenrt.sudo("mkdir -p %s" % (perun_dir))
        # Replace variables in perun.cmd.
        perun = string.replace(perun, "%FILES%", "%s" % (w.getURL("/")))
        f = file("%s/perun.cmd" % (xenrt.TEC().getWorkdir()), "w")
        f.write(perun)
        f.close()
        xenrt.TEC().copyToLogDir("%s/perun.cmd" % (xenrt.TEC().getWorkdir()))
        # Put perun.cmd where WinPE expects it.
        lock = xenrt.resources.CentralResource()
        for i in range(10):
            try:
                lock.acquire("WINPE_START_FILE")
                break
            except:
                if i == 9:
                    raise xenrt.XRTError("Couldn't get lock on WINPE "
                                         "bootstrap file.")
                xenrt.sleep(60)
        xenrt.sudo(
            "cp %s/perun.cmd %s" %
            (xenrt.TEC().getWorkdir(), xenrt.TEC().lookup("WINPE_START_FILE")))

        # Start install.
        xenrt.TEC().progress("Starting installation")
        pxefile = pxe.writeOut(self.machine)
        pfname = os.path.basename(pxefile)
        xenrt.TEC().copyToLogDir(pxefile, target="%s.pxe.txt" % (pfname))
        self.machine.powerctl.cycle()
        xenrt.TEC().progress("Rebooted host to start installation.")

        xenrt.sleep(120)

        lock.release()

        # 64-bit requires a two-stage installation.
        if arch == "x86-64":
            # Wait for first stage to complete.
            xenrt.sleep(360)
            xenrt.TEC().progress("Preparing TFTP for second stage.")
            xenrt.sudo("rsync -avxl %s/native/pxe/64/ %s/" %
                       (xenrt.TEC().getWorkdir(), tftp))
            xenrt.sudo("rsync -avxl %s/winpe64.wim %s/winpe.wim" %
                       (xenrt.TEC().lookup("IMAGES_ROOT"), tftp))
            self.machine.powerctl.cycle()
            xenrt.TEC().progress(
                "Rebooted host into second installation stage.")

        # Wait for PXE boot.
        xenrt.sleep(120)
        pxe.setDefault("local")
        pxe.writeOut(self.machine)

        # Wait for Windows to boot.
        xenrt.TEC().progress("Waiting for host to boot")
        self.waitforxmlrpc(7200)

        w.remove()

        if method == "longhorn":
            self.winRegAdd(
                "HKLM", "SYSTEM\\CurrentControlSet\\Control\\Terminal Server",
                "fDenyTSConnections", "DWORD", 0)
            self.winRegAdd("HKLM", "SYSTEM\\CurrentControlSet\\Control\\Lsa",
                           "LMCompatibilityLevel", "DWORD", 1)

        if not method == "longhorn":
            bootini = self.xmlrpcReadFile("c:\\boot.ini").strip()
            if self.memory:
                bootini += " /MAXMEM=%d" % (self.memory)
            if self.vcpus:
                bootini += " /NUMPROC=%d" % (self.vcpus)
            self.xmlrpcRemoveFile("c:\\boot.ini")
            self.xmlrpcCreateFile("c:\\boot.ini", xmlrpclib.Binary(bootini))
            self.xmlrpcReboot()
            xenrt.sleep(180)
            self.waitforxmlrpc(300)

            self.tailor()
Ejemplo n.º 16
0
# -*- coding:utf-8 -*-
# /usr/bin/env/python

import xmlrpclib

server = xmlrpclib.ServerProxy('http://localhost:9000')
s = 'This is a string with control characters' + '\0'
print 'Local string:', s

data = xmlrpclib.Binary(s)
print 'As binary:', server.send_back_binary(data)

try:
    print 'As string:', server.show_type(s)
except xmlrpclib.Fault as err:
    print '\nERROR:', err
Ejemplo n.º 17
0
            # TODO: use the xmlrpc-c type indicators instead / additionally
            if arg and arg[0] in "+-":
                try:
                    arg = int(arg, 10)
                except (ValueError, TypeError), exc:
                    self.LOG.warn("Not a valid number: %r (%s)" % (arg, exc))
            elif arg.startswith('[['):  # escaping, not a list
                arg = arg[1:]
            elif arg == '[]':
                arg = []
            elif arg.startswith('['):
                arg = arg[1:].split(',')
                if all(i.isdigit() for i in arg):
                    arg = [int(i, 10) for i in arg]
            elif arg.startswith('@'):
                arg = xmlrpclib.Binary(read_blob(arg))
            args.append(arg)

        return args


    def execute(self, proxy, method, args):
        """Execute given XMLRPC call."""
        try:
            result = getattr(proxy, method)(raw_xml=self.options.xml, *tuple(args))
        except xmlrpc.ERRORS as exc:
            self.LOG.error("While calling %s(%s): %s" % (method, ", ".join(repr(i) for i in args), exc))
            self.return_code = error.EX_NOINPUT if "not find" in getattr(exc, "faultString", "") else error.EX_DATAERR
        else:
            if not self.options.quiet:
                if self.options.repr:
Ejemplo n.º 18
0
 def wrapAndCompress(self, stringDoc):
     import bz2
     return xmlrpclib.Binary(bz2.compress(stringDoc))
Ejemplo n.º 19
0
        """
        buf = self.cli.essids.getitem(essid, key)
        if buf:
            results = PYR2_Buffer(buf.data)
            if results.essid != essid:
                raise StorageError("Invalid ESSID in result-collection")
            return results
        else:
            raise KeyError

    @handle_xmlfault()
    def __setitem__(self, (essid, key), results):
        """Store a iterable of (password,PMK)-tuples under the given
           ESSID and key.
        """
        b = xmlrpclib.Binary(PYR2_Buffer.pack(essid, results))
        self.cli.essids.setitem(essid, key, b)

    @handle_xmlfault()
    def __len__(self):
        """Return the number of ESSIDs currently stored."""
        return self.cli.essids.len()

    @handle_xmlfault()
    def __iter__(self):
        """Iterate over all essids currently stored."""
        return self.cli.essids.essids().__iter__()

    @handle_xmlfault()
    def __contains__(self, essid):
        """Return True if the given ESSID is currently stored."""
    def get_lights_and_image(self):
        self.lock.acquire()
        result = (copy.deepcopy(self.tracker.state()), xmlrpclib.Binary(self.im.tostring()))
        self.lock.release()

        return result
Ejemplo n.º 21
0
 def commit_job(self, cmdline):
     """When finished with a job
     Usage: commitjob [email] [sourceListId] [package]
     
     note: package should archive with zip, with the following structure
     sourcename.zip
         --sourcename.xml                                         
         --sourcename.png                                           //this is logo file
         --webForumConfiguration.xml(forum)                         
         --sourcename-url.xq & sourcename-thread.xq(forum))
         --finished.xml(forum)
         --sourcename.xq(blog)
         --config.xml(blog)
         --comment.txt
     
         --sourcename.xml sample:
             <meta>
                 <name>istofsports.co.uk</name>
                 <link>http://istofsports.co.uk</link>
                 <gmt>3</gmt>
             </meta>
     """
     
     arg = mu.get_second_arg(cmdline)
     args = cmdline.strip().split();
     
     if len(args) != 4:
         print "Command not valid, see 'man commitjob' for more info."
         return False
     
     email = args[1]
     source_id = args[2];
     pack_path = args[3]
     
     print "Be patient, I hate to wait either!"
     try:
         file = open(pack_path , "rb")
         r , p = self._proxy.upload_file(os.path.basename(pack_path) , xmlrpclib.Binary(file.read()))
         self._print_result(r, p)
     except:
         print "Failed upload package to server, Check whether package is correct?"
         print "Needs commit again"
         return False
     
     is_prioritized, p2 = self._proxy.is_prioritized(arg)                            
     r, p = self._proxy.commit_job(email , source_id , os.path.basename(pack_path))    
             
     if not r:
         self._print_result(r, p)
         return
     
     # rest so assignjob will give the correct message
     self._sourcelist_id = -1
     
     
     if is_prioritized:
         print "#" * 30
         print "# The source you just committed is flagged as a high-priority."
         print "# Please send the transformation to:"
         print "# \t'*****@*****.**'"
         print "# as SOON as possible."
         print "#" * 30            
     
     self._print_result(r, p)
Ejemplo n.º 22
0
def readFile(filename):
    data = xmlrpclib.Binary()
    f = file(filename, "rb")
    data.data = f.read()
    f.close()
    return data
Ejemplo n.º 23
0
        whatnot['gamespot_review'] = gamespot_review
        whatnot['user_reviews'] = user_reviews

        return metadata, gamespot_review, user_reviews

    except Exception as e:
        traceback.print_exc()
        gmail.send("exception!", "*****@*****.**")
        ipdb.set_trace()


#metadata, gamespot_review, user_reviews = get_metadata_and_reviews(href)

#gamespot = "http://www.gamespot.com/"

# this is going to run on the client
import xmlrpclib
proxy = xmlrpclib.ServerProxy("http://research.seanneilan.com:80/")

global_password = "******"

next_url = proxy.get_a_url(global_password)  # loop and a half! hooray!
while next_url != False:
    print "Next url is: " + next_url
    whatnot = get_metadata_and_reviews(next_url)
    p = pickle.dumps(whatnot)
    b = xmlrpclib.Binary(p)
    proxy.commit_data(global_password, next_url, b)
    print "Completed " + next_url
    next_url = proxy.get_a_url(global_password)
Ejemplo n.º 24
0
 def newflush():
     oldflush()
     self.proxy.set_contents(path, xmlrpclib.Binary(f.getvalue()))
Ejemplo n.º 25
0
    def run(self, arglist):

        duration = 7200
        threads = 2

        guest = self.getLocation()
        self.storedguest = guest
        self.getLogsFrom(guest.host)

        if not guest.windows:
            xenrt.TEC().skip("Not running on windows.")
            return

        guest.xmlrpcCreateEmptyFile("c:\\mappedfile.dat", 1024)
        f = file(
            "%s/progs/mappedfiletest.exe" %
            (self.tec.lookup("LOCAL_SCRIPTDIR")), "rb")
        mfte = f.read()
        f.close()
        guest.xmlrpcCreateFile("c:\\mappedfiletest.exe",
                               xmlrpclib.Binary(mfte))

        readers = []
        writers = []

        for i in range(threads):
            readers.append(None)
            writers.append(None)

        started = xenrt.timenow()
        w = 0
        r = 0
        f = 0
        stop = False
        xenrt.TEC().logverbose("Starting main loop")
        while True:
            time.sleep(15)
            now = xenrt.timenow()
            if now > (started + duration):
                stop = True

            # Check the status of the threads
            any = False
            for i in range(threads):
                if not readers[i] and not stop:
                    readers[i] = guest.xmlrpcStart("c:\\mappedfiletest.exe "
                                                   "READ c:\\mappedfile.dat")
                if not writers[i] and not stop:

                    writers[i] = guest.xmlrpcStart("c:\\mappedfiletest.exe "
                                                   "WRITE 1024")
                try:
                    if readers[i] and guest.xmlrpcPoll(readers[i], retries=3):
                        ref = readers[i]
                        self.tec.log(guest.xmlrpcLog(ref))
                        readers[i] = None
                        r = r + 1
                        if guest.xmlrpcReturnCode(ref) != 0:
                            f = f + 1
                except socket.error:
                    pass
                try:
                    if writers[i] and guest.xmlrpcPoll(writers[i], retries=3):
                        ref = writers[i]
                        self.tec.log(guest.xmlrpcLog(ref))
                        writers[i] = None
                        w = w + 1
                        if guest.xmlrpcReturnCode(ref) != 0:
                            f = f + 1
                except socket.error:
                    pass
                if readers[i]:
                    any = True
                if writers[i]:
                    any = True
            if stop and not any:
                break

        self.tec.comment("%u writers and %u readers completed" % (w, r))
        if f > 0:
            self.tec.warning("One or more operations returned an error")
Ejemplo n.º 26
0
    def open(self,
             path,
             mode='r',
             buffering=-1,
             encoding=None,
             errors=None,
             newline=None,
             line_buffering=False,
             **kwargs):
        # TODO: chunked transport of large files
        epath = self.encode_path(path)
        if "w" in mode:
            self.proxy.set_contents(epath, xmlrpclib.Binary(b("")))
        if "r" in mode or "a" in mode or "+" in mode:
            try:
                data = self.proxy.get_contents(epath, "rb").data
            except IOError:
                if "w" not in mode and "a" not in mode:
                    raise ResourceNotFoundError(path)
                if not self.isdir(dirname(path)):
                    raise ParentDirectoryMissingError(path)
                self.proxy.set_contents(path, xmlrpclib.Binary(b("")))
        else:
            data = b("")
        f = StringIO(data)
        if "a" not in mode:
            f.seek(0, 0)
        else:
            f.seek(0, 2)
        oldflush = f.flush
        oldclose = f.close
        oldtruncate = f.truncate

        def newflush():
            self._lock.acquire()
            try:
                oldflush()
                self.proxy.set_contents(epath, xmlrpclib.Binary(f.getvalue()))
            finally:
                self._lock.release()

        def newclose():
            self._lock.acquire()
            try:
                f.flush()
                oldclose()
            finally:
                self._lock.release()

        def newtruncate(size=None):
            self._lock.acquire()
            try:
                oldtruncate(size)
                f.flush()
            finally:
                self._lock.release()

        f.flush = newflush
        f.close = newclose
        f.truncate = newtruncate
        return f
Ejemplo n.º 27
0
except ImportError:
    threading = None

try:
    unicode
except NameError:
    have_unicode = False
else:
    have_unicode = True

alist = [{'astring': '*****@*****.**',
          'afloat': 7283.43,
          'anint': 2**20,
          'ashortlong': 2L,
          'anotherlist': ['.zyx.41'],
          'abase64': xmlrpclib.Binary("my dog has fleas"),
          'boolean': xmlrpclib.False,
          'unicode': u'\u4000\u6000\u8000',
          u'ukey\u4000': 'regular value',
          'datetime1': xmlrpclib.DateTime('20050210T11:41:23'),
          'datetime2': xmlrpclib.DateTime(
                        (2005, 02, 10, 11, 41, 23, 0, 1, -1)),
          'datetime3': xmlrpclib.DateTime(
                        datetime.datetime(2005, 02, 10, 11, 41, 23)),
          }]

class XMLRPCTestCase(unittest.TestCase):

    def test_dump_load(self):
        self.assertEqual(alist,
                         xmlrpclib.loads(xmlrpclib.dumps((alist,)))[0][0])
Ejemplo n.º 28
0
 def set_binary_exr(self, path):
     with open(path, 'rb') as f:
         b = xmlrpclib.Binary(f.read())
         rospy.set_param(self._server_node_name + "/p2g", b)
Ejemplo n.º 29
0
 def test_string(self):
     d = '\x01\x02\x03abc123\xff\xfe'
     t = xmlrpclib.Binary(d)
     self.assertEqual(str(t), d)
Ejemplo n.º 30
0
 def _handle_bytes(self, arg):
     # http://bugs.jython.org/issue2429
     if IRONPYTHON or JYTHON:
         arg = str(arg)
     return xmlrpclib.Binary(arg)