Пример #1
0
    def _put_data(self, localfile):
        """
        Uploads the given File object to Amazon S3 and returns its record
        identifier (Rid).

        @returns: Rid of uploaded file.
        """
        filename = localfile.get_relative_uri()
        key = Key(self.bucket)
        # the key's name is the LUID
        key.name = filename
        # add a bit of metadata to key
        # TODO store more metadata: file permissions and owner:group?
        key.set_metadata("size", str(localfile.get_size()))
        key.set_metadata(
            "mtime", str(Utils.datetime_get_timestamp(localfile.get_mtime())))

        # now upload the data
        key.set_contents_from_filename(localfile.get_local_uri())

        # return Rid of uploaded file
        return self._get_proxyfile(key).get_rid()
Пример #2
0
    def _put_data(self, localfile):
        """
        Uploads the given File object to Amazon S3 and returns its record
        identifier (Rid).

        @returns: Rid of uploaded file.
        """
        filename = localfile.get_relative_uri()
        key = Key(self.bucket)
        # the key's name is the LUID
        key.name = filename
        # add a bit of metadata to key
        # TODO store more metadata: file permissions and owner:group?
        key.set_metadata("size", str(localfile.get_size()))
        key.set_metadata(
            "mtime", str(Utils.datetime_get_timestamp(localfile.get_mtime())))

        # now upload the data
        key.set_contents_from_filename(localfile.get_local_uri())

        # return Rid of uploaded file
        return self._get_proxyfile(key).get_rid()
Пример #3
0
except:
    ok("datetime_from_timestamp only accepts numbers", True)


try:
    i = Utils.datetime_from_timestamp("Foo")
    ok("datetime_get_timestamp only accepts datetimes", False)
except:
    ok("datetime_get_timestamp only accepts datetimes", True)

#make another local file
local = Utils.new_tempfile(Utils.random_string())

#get timestamp and mtimes
dt = local.get_mtime()
ts = Utils.datetime_get_timestamp(dt)

#now get timestamp using os.stat
pts = os.stat(local.get_local_uri()).st_mtime
pdt = Utils.datetime_from_timestamp(pts)

ok("Timestamps are equal (%s)" % ts, ts == pts)
ok("Datetimes are equal (%s)" % dt, dt == pdt)

#Check that we ignore any microsecond timestamps
f = ts + 0.01234
fdt = Utils.datetime_from_timestamp(f)
fts = Utils.datetime_get_timestamp(fdt)
ok("Ignore fractional timestamps (%s -> %s -> %s)" % (f,fts,dt), dt == fdt and ts == fts)

finished()
Пример #4
0
ok("Random string: %s" % s, len(s) > 0 and type(s) == str)
s = Utils.md5_string('Foo')
ok("md5 string: %s" % s, len(s) > 0 and type(s) == str)
s = Utils.uuid_string()
ok("uuid string: %s" % s, len(s) > 0 and type(s) == str)
s = Utils.get_user_string()
ok("user string: %s" % s, len(s) > 0 and type(s) == str)

#test command line processing
ok("Cmd executed", len(Utils.exec_command_and_return_result("ls",".")) > 0)
ok("Cmd with wrong args", Utils.exec_command_and_return_result("ls","does-not-exist") == None) 
ok("Cmd that doesnt exist", Utils.exec_command_and_return_result("cmd-does-not-exist",".") == None)  

ts = 0
dt = Utils.datetime_from_timestamp(ts)
ok("Datetime to unix timestamp", Utils.datetime_get_timestamp(dt) == ts)
ok("Unix timestamp to datetime", Utils.datetime_from_timestamp(ts) == dt)

m = Memstats.Memstats()
VmSize,VmRSS,VmStack = m.calculate()
ok("Memstats: size:%s rss:%s stack:%s" % (VmSize,VmRSS,VmStack), VmSize > 0 and VmRSS > 0 and VmStack > 0)

# Test the shiny command line executer
conv = CommandLineConverter.CommandLineConverter()
conv.build_command("ls %s %s")
cmdok,output = conv.convert("/tmp","/dev/null",callback=None,save_output=True)

ok("Command executed ok", cmdok == True and len(output) > 0)

ok("Simple xml tag extractor", 
        Utils.xml_extract_value_from_tag("tag", "<tag>foo tag bar</tag>") == "foo tag bar")