Ejemplo n.º 1
0
 def test_basicsize(self):
     '''Test asizeof.basicsize()
     '''
     objects = [1, '', 'a', True, None]
     for o in objects:
         self.assertEqual(asizeof.basicsize(o), type(o).__basicsize__)
     objects = [[], (), {}]
     for o in objects:
         self.assertEqual(asizeof.basicsize(o) - asizeof._sizeof_CPyGC_Head,
             type(o).__basicsize__)
     l1 = [1,2,3,4]
     l2 = ["spam",2,3,4,"eggs",6,7,8]
     self.assertEqual(asizeof.basicsize(l1), asizeof.basicsize(l2))
Ejemplo n.º 2
0
 def test_basicsize(self):
     '''Test asizeof.basicsize()
     '''
     objects = [1, '', 'a', True, None]
     for o in objects:
         self.assertEqual(asizeof.basicsize(o), type(o).__basicsize__)
     objects = [[], (), {}]
     for o in objects:
         self.assertEqual(asizeof.basicsize(o) - asizeof._sizeof_CPyGC_Head,
             type(o).__basicsize__)
     l1 = [1,2,3,4]
     l2 = ["spam",2,3,4,"eggs",6,7,8]
     self.assertEqual(asizeof.basicsize(l1), asizeof.basicsize(l2))
Ejemplo n.º 3
0
 def _print_functions(self,
                      obj,
                      name=None,
                      align=8,
                      detail=MAX,
                      code=False,
                      limit=MAX,
                      opt='',
                      **unused):
     if name:
         self._printf('%sasizeof functions for %s ... %s', os.linesep, name,
                      opt)
     self._printf('%s(): %s', ' basicsize', asizeof.basicsize(obj))
     self._printf('%s(): %s', ' itemsize', asizeof.itemsize(obj))
     self._printf('%s(): %r', ' leng', asizeof.leng(obj))
     self._printf('%s(): %s', ' refs', _repr(asizeof.refs(obj)))
     self._printf('%s(): %s', ' flatsize',
                  asizeof.flatsize(obj, align=align))  # , code=code
     self._printf(
         '%s(): %s', ' asized',
         asizeof.asized(obj,
                        align=align,
                        detail=detail,
                        code=code,
                        limit=limit))
Ejemplo n.º 4
0
    def __init__(self,
                 instance: Any,
                 name: str,
                 resolution_level: int = 0,
                 trace: bool = False,
                 on_delete: Optional[Callable] = None):
        """
        Create a weak reference for 'instance' to observe an object but which
        won't prevent its deletion (which is monitored by the finalize
        callback). The size of the object is recorded in 'snapshots' as
        (timestamp, size) tuples.
        """
        self.ref = weakref_ref(instance, self.finalize)
        self.id = id(instance)
        self.repr = ''
        self.name = name
        self.birth = _get_time()
        self.death = None  # type: Optional[float]
        self._resolution_level = resolution_level
        self.trace = None  # type: Optional[List[Tuple]]

        if trace:
            self._save_trace()

        initial_size = asizeof.basicsize(instance) or 0
        size = asizeof.Asized(initial_size, initial_size)
        self.snapshots = [(self.birth, size)]
        self.on_delete = on_delete
Ejemplo n.º 5
0
    def solve_playlist(self, url=None):
        if url == None:
            url = list(self.playlists.keys())[-1]

        with open(url) as file:
            for line in file:
                line = line.strip()
                if line[0] == "#":
                    pass
                elif len(line) >= 1:
                    drctr, flnm = get_name(url)
                    # TODO: There needs to be a better way to deal with paths relative to the playlist file.
                    #song_url = "/".join([drctr, line])
                    # For now please only use absolute paths or it will assume a path relative to the Python script.
                    song_url = line

                    song = Song(song_url, self)
                    self.mem_taken += basicsize(song)

                    self.select_list.append(
                        song
                    )  # This one must correspond with the indexes of the Treeview ListStore model.
                    self.queue.append(
                        song
                    )  # This one will be shuffled and looped as the user asks to.

                    # ["Nr.", "Title", "Author", "Album", "Year", "Length", "Kudos"]
                    self.playlists[url].get_children()[0].get_model().append([
                        song.meta["number"], song.meta["title"],
                        song.meta["author"], song.meta["album"],
                        song.meta["year"], song.meta["genre"],
                        song.meta["duration"], "0"
                    ])
Ejemplo n.º 6
0
 def _print_functions(self, obj, name=None, align=8, detail=MAX, code=False, limit=MAX,
                           opt='', **unused):
     if name:
         self._printf('%sasizeof functions for %s ... %s', os.linesep, name, opt)
     self._printf('%s(): %s', ' basicsize', asizeof.basicsize(obj))
     self._printf('%s(): %s', ' itemsize',  asizeof.itemsize(obj))
     self._printf('%s(): %r', ' leng',      asizeof.leng(obj))
     self._printf('%s(): %s', ' refs',     _repr(asizeof.refs(obj)))
     self._printf('%s(): %s', ' flatsize',  asizeof.flatsize(obj, align=align))  # , code=code
     self._printf('%s(): %s', ' asized',           asizeof.asized(obj, align=align, detail=detail, code=code, limit=limit))
Ejemplo n.º 7
0
        def test_flatsize(self):
            '''Test asizeof.flatsize()
            '''
            l = ["spam", 2, 3, 4, "eggs", 6, 7, 8]
            for _type in (list, tuple, set, frozenset):
                data = _type(l)
                bsz = asizeof.basicsize(data)
                isz = asizeof.itemsize(data)
                lng = asizeof.leng(data)
                fsz = asizeof.flatsize(data)
                self.assertEqual(fsz, bsz + (lng * isz), (fsz, bsz, lng, isz))

            self.assertRaises(ValueError, asizeof.flatsize, l, **{'align': 3})
Ejemplo n.º 8
0
        def test_flatsize(self):
            '''Test asizeof.flatsize()
            '''
            l = ["spam", 2, 3, 4, "eggs", 6, 7, 8]
            for _type in (list, tuple, set, frozenset):
                data = _type(l)
                bsz = asizeof.basicsize(data)
                isz = asizeof.itemsize(data)
                lng = asizeof.leng(data)
                fsz = asizeof.flatsize(data)
                self.assertEqual(fsz, bsz + (lng * isz), (fsz, bsz, lng, isz))

            self.assertRaises(ValueError, asizeof.flatsize, l, **{'align': 3})
Ejemplo n.º 9
0
    def test_long(self):
        '''Test int and long examples'''
        try:
            _L5d  = long(1) << 64
            _L17d = long(1) << 256
            t = '<int>/<long>'
        except NameError:
            _L5d  = 1 << 64
            _L17d = 1 << 256
            t = '<int>'

        self._printf('%sasizeof(%s, align=%s, limit=%s) ... %s', os.linesep, t, 0, 0, '-int')
        for o in (1024, 1000000000,
                  1.0, 1.0e100, 1024, 1000000000,
                  self.MAX, 1 << 32, _L5d, -_L5d, _L17d, -_L17d):
            self._printf(" asizeof(%s) is %s (%s + %s * %s)", _repr(o), asizeof.asizeof(o, align=0, limit=0),
                                                         asizeof.basicsize(o), asizeof.leng(o), asizeof.itemsize(o))
Ejemplo n.º 10
0
    def test_long(self):
        '''Test int and long examples'''
        try:
            _L5d  = long(1) << 64
            _L17d = long(1) << 256
            t = '<int>/<long>'
        except NameError:
            _L5d  = 1 << 64
            _L17d = 1 << 256
            t = '<int>'

        self._printf('%sasizeof(%s, align=%s, limit=%s) ... %s', os.linesep, t, 0, 0, '-int')
        for o in (1024, 1000000000,
                  1.0, 1.0e100, 1024, 1000000000,
                  self.MAX, 1 << 32, _L5d, -_L5d, _L17d, -_L17d):
            self._printf(" asizeof(%s) is %s (%s + %s * %s)", _repr(o), asizeof.asizeof(o, align=0, limit=0),
                                                         asizeof.basicsize(o), asizeof.leng(o), asizeof.itemsize(o))
Ejemplo n.º 11
0
    def __init__(self, instance, resolution_level=0, trace=False):
        """
        Create a weak reference for 'instance' to observe an object but which
        won't prevent its deletion (which is monitored by the finalize
        callback). The size of the object is recorded in 'snapshots' as
        (timestamp, size) tuples.
        """
        self.ref = weakref_ref(instance, self.finalize)
        self.id = id(instance)
        self.repr = ''
        self.name = str(instance.__class__)
        self.birth = _get_time()
        self.death = None
        self._resolution_level = resolution_level
        self.trace = None

        if trace:
            self._save_trace()

        initial_size = asizeof.basicsize(instance) or 0
        size = asizeof.Asized(initial_size, initial_size)
        self.snapshots = [(self.birth, size)]
Ejemplo n.º 12
0
    def __init__(self, instance, resolution_level=0, trace=False):
        """
        Create a weak reference for 'instance' to observe an object but which
        won't prevent its deletion (which is monitored by the finalize
        callback). The size of the object is recorded in 'snapshots' as
        (timestamp, size) tuples.
        """
        self.ref = weakref_ref(instance, self.finalize)
        self.id = id(instance)
        self.repr = ''
        self.name = str(instance.__class__)
        self.birth = _get_time()
        self.death = None
        self._resolution_level = resolution_level
        self.trace = None

        if trace:
            self._save_trace()

        initial_size = asizeof.basicsize(instance) or 0
        size = asizeof.Asized(initial_size, initial_size)
        self.snapshots = [(self.birth, size)]
Ejemplo n.º 13
0
    def solve_from_dirs(self):
        # fold_list = g.ListStore(str,str)
        # dir_list = g.ListStore(str,str)
        pool_list = g.ListStore(str, str, str, str, str, str, str, str)

        # Get files and folders
        for tgt in self.song_dirs:
            for url, fldr, rsrc in fetch_dir(tgt):
                for r in rsrc:
                    i, ext = get_ext(r)

                    place = url + "/" + r

                    if ext[1:].upper() in formats:
                        song = Song(place, self)
                        self.mem_taken += basicsize(song)
                        self.number_songs += 1

                        pool_list.append([
                            song.meta["title"],
                            song.meta["author"],
                            song.meta["album"],
                            song.meta["year"],
                            song.meta["genre"],
                            song.meta["duration"],
                            "0",
                            place,
                        ])
                    if ext[1:].upper() == "M3U":
                        self.playlists[place] = g.ScrolledWindow()
                        self.playlists[place].add(
                            g.TreeView(
                                g.ListStore(str, str, str, str, str, str, str,
                                            str)))
                        tab_text = g.Label(i)
                        tab_text.set_max_width_chars(8)
                        self.playbook.prepend_page(self.playlists[place],
                                                   tab_text)
                        #self.playbook.set_tab_reorderable(tab_text, True)
                        #self.playlists[place].get_children()[0].set_reorderable(True)
                        self.playlists[place].get_children()[0].get_selection(
                        ).set_mode(g.SelectionMode.MULTIPLE)
                        self.playlists[place].get_children()[0].set_grid_lines(
                            g.TreeViewGridLines.VERTICAL)

                        self.playlists[place].get_children()[0].connect(
                            "cursor_changed", self.songSelect)
                        self.playlists[place].get_children()[0].connect(
                            "row_activated", self.songSet)

                        for i, col_title in enumerate([
                                "Nr.", "Title", "Author", "Album", "Year",
                                "Genre", "Length", "Kudos"
                        ]):
                            rend = g.CellRendererText()
                            col = g.TreeViewColumn(col_title, rend, text=i)
                            #col.set_sort_column_id(i)
                            col.set_reorderable(True)
                            col.set_resizable(True)
                            self.playlists[place].get_children(
                            )[0].append_column(col)

        pool_view = g.TreeView(pool_list)
        pool_view.set_enable_search(True)
        pool_view.set_grid_lines(g.TreeViewGridLines.VERTICAL)
        pool_view.get_selection().set_mode(g.SelectionMode.MULTIPLE)

        #pool_view.connect("clicked", self.on_close_clicked)
        pool_view.connect("button-press-event", self.onClick)

        for i, col_title in enumerate([
                "Title",
                "Author",
                "Album",
                "Year",
                "Genre",
                "Length",
                "Kudos",
                "Location",
        ]):
            rend = g.CellRendererText()
            col = g.TreeViewColumn(col_title, rend, text=i)
            col.set_sort_column_id(i)
            col.set_reorderable(True)
            col.set_resizable(True)
            pool_view.append_column(col)

        self.pool.add(pool_view)
Ejemplo n.º 14
0
    print "."
    print "Can't start network! Look at the logs in OZW_Log.log"
    quit(2)
print "------------------------------------------------------------"
print "Controller capabilities : %s" % network.controller.capabilities
print "Controller node capabilities : %s" % network.controller.node.capabilities
print "------------------------------------------------------------"
print "Driver statistics : %s" % network.controller.stats
print "------------------------------------------------------------"
print "Nodes in network : %s" % network.nodes_count
print "------------------------------------------------------------"
print "Memory use : "
print "------------------------------------------------------------"
print "Memory use for network %s : " %(network.home_id_str)
print "  asizeof   : %s bytes" %(asizeof(network))
print "  basicsize : %s bytes" %(basicsize(network))
print "  itemsize  : %s bytes" %(itemsize(network))
print "  flatsize  : %s bytes" %(flatsize(network))
print "------------------------------------------------------------"
manager = network.manager
print "Memory use for manager : "
print "  asizeof   : %s bytes" %(asizeof(manager))
print "  basicsize : %s bytes" %(basicsize(manager))
print "  itemsize  : %s bytes" %(itemsize(manager))
print "  flatsize  : %s bytes" %(flatsize(manager))
print "------------------------------------------------------------"
print "Memory use for controller : "
print "  asizeof   : %s bytes" %(asizeof(network.controller))
print "  basicsize : %s bytes" %(basicsize(network.controller))
print "  itemsize  : %s bytes" %(itemsize(network.controller))
print "  flatsize  : %s bytes" %(flatsize(network.controller))
Ejemplo n.º 15
0
    print(".")
    print("Can't start network! Look at the logs in OZW_Log.log")
    quit(2)
print("------------------------------------------------------------")
print("Controller capabilities : {}".format(network.controller.capabilities))
print("Controller node capabilities : {}".format(network.controller.node.capabilities))
print("------------------------------------------------------------")
print("Driver statistics : {}".format(network.controller.stats))
print("------------------------------------------------------------")
print("Nodes in network : {}".format(network.nodes_count))
print("------------------------------------------------------------")
print("Memory use : ")
print("------------------------------------------------------------")
print("Memory use for network {} : ".format(network.home_id_str))
print("  asizeof   : {} bytes".format(asizeof(network)))
print("  basicsize : {} bytes".format(basicsize(network)))
print("  itemsize  : {} bytes".format(itemsize(network)))
print("  flatsize  : {} bytes".format(flatsize(network)))
print("------------------------------------------------------------")
manager = network.manager
print("Memory use for manager : ")
print("  asizeof   : {} bytes".format(asizeof(manager)))
print("  basicsize : {} bytes".format(basicsize(manager)))
print("  itemsize  : {} bytes".format(itemsize(manager)))
print("  flatsize  : {} bytes".format(flatsize(manager)))
print("------------------------------------------------------------")
print("Memory use for controller : ")
print("  asizeof   : {} bytes".format(asizeof(network.controller)))
print("  basicsize : {} bytes".format(basicsize(network.controller)))
print("  itemsize  : {} bytes".format(itemsize(network.controller)))
print("  flatsize  : {} bytes".format(flatsize(network.controller)))
Ejemplo n.º 16
0
def get_memory_object(req):
    initial_size = asizeof.basicsize(req) or 0
    return asizeof.Asized(initial_size, initial_size)
Ejemplo n.º 17
0
    print("Can't start network! Look at the logs in OZW_Log.log")
    quit(2)
print("------------------------------------------------------------")
print("Controller capabilities : {}".format(network.controller.capabilities))
print("Controller node capabilities : {}".format(
    network.controller.node.capabilities))
print("------------------------------------------------------------")
print("Driver statistics : {}".format(network.controller.stats))
print("------------------------------------------------------------")
print("Nodes in network : {}".format(network.nodes_count))
print("------------------------------------------------------------")
print("Memory use : ")
print("------------------------------------------------------------")
print("Memory use for network {} : ".format(network.home_id_str))
print("  asizeof   : {} bytes".format(asizeof(network)))
print("  basicsize : {} bytes".format(basicsize(network)))
print("  itemsize  : {} bytes".format(itemsize(network)))
print("  flatsize  : {} bytes".format(flatsize(network)))
print("------------------------------------------------------------")
manager = network.manager
print("Memory use for manager : ")
print("  asizeof   : {} bytes".format(asizeof(manager)))
print("  basicsize : {} bytes".format(basicsize(manager)))
print("  itemsize  : {} bytes".format(itemsize(manager)))
print("  flatsize  : {} bytes".format(flatsize(manager)))
print("------------------------------------------------------------")
print("Memory use for controller : ")
print("  asizeof   : {} bytes".format(asizeof(network.controller)))
print("  basicsize : {} bytes".format(basicsize(network.controller)))
print("  itemsize  : {} bytes".format(itemsize(network.controller)))
print("  flatsize  : {} bytes".format(flatsize(network.controller)))
Ejemplo n.º 18
0
    print "."
    print "Can't start network! Look at the logs in OZW_Log.log"
    quit(2)
print "------------------------------------------------------------"
print "Controller capabilities : %s" % network.controller.capabilities
print "Controller node capabilities : %s" % network.controller.node.capabilities
print "------------------------------------------------------------"
print "Driver statistics : %s" % network.controller.stats
print "------------------------------------------------------------"
print "Nodes in network : %s" % network.nodes_count
print "------------------------------------------------------------"
print "Memory use : "
print "------------------------------------------------------------"
print "Memory use for network %s : " % (network.home_id_str)
print "  asizeof   : %s bytes" % (asizeof(network))
print "  basicsize : %s bytes" % (basicsize(network))
print "  itemsize  : %s bytes" % (itemsize(network))
print "  flatsize  : %s bytes" % (flatsize(network))
print "------------------------------------------------------------"
manager = network.manager
print "Memory use for manager : "
print "  asizeof   : %s bytes" % (asizeof(manager))
print "  basicsize : %s bytes" % (basicsize(manager))
print "  itemsize  : %s bytes" % (itemsize(manager))
print "  flatsize  : %s bytes" % (flatsize(manager))
print "------------------------------------------------------------"
print "Memory use for controller : "
print "  asizeof   : %s bytes" % (asizeof(network.controller))
print "  basicsize : %s bytes" % (basicsize(network.controller))
print "  itemsize  : %s bytes" % (itemsize(network.controller))
print "  flatsize  : %s bytes" % (flatsize(network.controller))