import os
import sys
import re
from optparse import OptionParser
from Album import *

class Itemizer:
    
    OPTIONS = [
        ("-d", "destination", "destination directory", "DIR", "./"),
        ("-i", "index", "item index", "INT"),
        ("-f", "file_path", "input file", "PATH"),
        ("-s", "silent", "suppress messages", None, False, "store_true"),
        ("-v", "verbose", "verbose output", None, False, "store_true"),
        ("--delimiter", "delimiter", "field delimiter", "CHAR", "_"),
        ("--copy", "copy", "copy files", None, False, "store_true"),
        ("--deitemize", "deitemize", "deitemize", None, False, "store_true"),
        ("--sim", "simulate", "simulate itemization", None, False,
         "store_true"),
        ("--regroup", "regroup", "order items consecutively", None, False,
         "store_true"),
        ("--no-name", "no_name", "rename file to only item number", None, False,
         "store_true"),
        ]
    USAGE_MESSAGE = "Usage: %prog [options] PATH_1..PATH_n"

    def __init__(self):
        self.init_input()
        if len(sys.argv) > 1:
            self.add_file_contents_to_item_list()
            self.album = Album(self.options.destination, self.options.delimiter,
                               self.options.copy, self.options.simulate,
                               self.verbosity, self.options.regroup,
                               self.options.no_name)
            if self.options.deitemize:
                self.album.remove(self.item_paths)
            else:
                self.album.add_items(self.item_paths, self.options.index)
            self.album.commit()
        else:
            self.parser.print_help()

    def init_input(self):
        self.parser = OptionParser(self.USAGE_MESSAGE)
        self.parse_arguments()

    def parse_arguments(self):
        for option in self.OPTIONS:
            default = option[4] if len(option) > 4 else None
            action = option[5] if len(option) > 5 else None
            self.parser.add_option(
                option[0], dest=option[1], help=option[2],
                metavar=option[3], default=default, action=action)
        self.options, self.item_paths = self.parser.parse_args()
        self.set_verbosity(self.options.silent, self.options.verbose)

    def set_verbosity(self, silent, verbose):
        if verbose:
            self.verbosity = 2
        elif silent:
            self.verbosity = 0
        else:
            self.verbosity = 1

    def add_file_contents_to_item_list(self):
        if self.options.file_path != None:
            for line in file(self.options.file_path):
                line = line.rstrip()
                line = line.strip("\"")
                if line[0] != "#":
                    self.item_paths.append(line)

    @staticmethod
    def is_item(path):
        if os.path.isfile(path):
            file_name = os.path.basename(path)
            if re.match("^[0-9]+.*", file_name):
                return True
        return False

    @staticmethod
    def extract_item_number(path):
        file_name = os.path.basename(path)
        match = re.match("^([0-9]+).*", file_name)
        if match:
            return int(match.group(1))
        return None
#!/usr/bin/python

from Itemizer import *

if __name__ == "__main__":
    Itemizer()
import os
import Itemizer
from Item import *

class Album:

    def __init__(self, directory_path, delimiter, copy, simulate, verbosity,
                 regroup, no_name):
        self.set_options(delimiter, copy, simulate, verbosity, regroup, no_name)
        self.set_directory_path(directory_path)
        self.initialize_item_list()

    def set_options(self, delimiter, copy, simulate, verbosity, regroup,
                    no_name):
        self.delimiter = delimiter
        self.copy = copy
        self.simulate = simulate
        self.verbosity = verbosity
        self.regroup = regroup
        self.no_name = no_name

    def set_directory_path(self, directory_path):
        if not os.path.isdir(directory_path):
            print "Directory not found:", directory_path
            directory_path = None
        else:
            directory_path = os.path.join(directory_path, "")
        self.directory_path = directory_path

    def initialize_item_list(self):
        self.items = None
        if self.directory_path != None:
            for file_name in os.listdir(self.directory_path):
                path = self.directory_path + file_name
                if Itemizer.Itemizer.is_item(path):
                    number = Itemizer.Itemizer.extract_item_number(path)
                    self.add_items(path, number)

    def add_items(self, paths, index=None):
        if type(paths) == str:
            paths = [paths]
        current_index = self.build_index(index)
        for path in paths:
            if not os.path.isfile(path):
                print "File not found:", path
            else:
                if self.items == None:
                    self.add_first_item(path, current_index)
                else:
                    self.items = self.items.remove_path(path)
                    if self.items == None:
                        self.add_first_item(path, current_index)
                    else:
                        self.items = self.items.insert(path, current_index)
                if current_index:
                    current_index += 1
                if self.verbosity > 1:
                    print "Added file to list:", path

    def build_index(self, index):
        if type(index) == str:
            index = int(index)
        return index

    def add_first_item(self, path, index):
        if index == None:
            index = 1
        self.items = Item(path, index, self.no_name)

    def remove(self, paths):
        current = self.items
        while current != None:
            path = self.find_path_in_list(current.path, paths)
            if path:
                outgoing = current
                self.items = self.items.remove_path(outgoing.path)
                outgoing.erase_index()
                outgoing.save(
                    self.directory_path, None, self.delimiter, self.copy,
                    self.simulate, self.verbosity)
                paths.remove(path)
            current = current.next

    def find_path_in_list(self, key, paths):
        for path in paths:
            if os.path.samefile(key, path):
                return path

    def commit(self):
        if self.directory_path != None and self.items != None:
            if self.regroup:
                self.items.bunch()
            current = self.items
            prefix_length = self.determine_prefix_length()
            while current != None:
                current.save(
                    self.directory_path, prefix_length, self.delimiter,
                    self.copy, self.simulate, self.verbosity)
                current = current.next

    def print_items(self):
        current = self.items
        while current != None:
            print current
            current = current.next

    def determine_prefix_length(self):
        largest_index = self.items.get_largest_index()
        return len(str(largest_index))
216.73.216.184
216.73.216.184
216.73.216.184
 
July 18, 2022


A new era ‼

Our infrastructure has recently upgraded ‼

Nugget Communications Bureau 👍

You've never emailed like this before ‼

Roundcube

Webmail software for reading and sending email from @nugget.fun and @shampoo.ooo addresses.

Mailman3

Email discussion lists, modernized with likes and emojis. It can be used for announcements and newsletters in addition to discussions. See lists for Picture Processing or Scrapeboard. Nowadays, people use Discord, but you really don't have to!

FreshRSS

With this hidden in plain sight, old technology, even regular people like you and me can start our own newspaper or social media feed.

Nugget Streaming Media 👍

The content you crave ‼

HLS

A live streaming, video format based on M3U playlists that can be played with HTML5.

RTMP

A plugin for Nginx can receive streaming video from ffmpeg or OBS and forward it as an RTMP stream to sites like Youtube and Twitch or directly to VLC.


Professional ‼

Nugget Productivity Suite 👍

Unleash your potential ‼

Kanboard

Virtual index cards you can use to gamify your daily grind.

Gitea

Grab whatever game code you want, share your edits, and report bugs.

Nugget Security 👍

The real Turing test ‼

Fail2ban

Banning is even more fun when it's automated.

Spamassassin

The documentation explains, "an email which mentions rolex watches, Viagra, porn, and debt all in one" will probably be considered spam.

GoAccess

Display HTTP requests in real time, so you can watch bots try to break into WordPress.

Nugget Entertainment Software 👍

The best in gaming entertainment ‼

Emoticon vs. Rainbow

With everything upgraded to the bleeding edge, this HTML4 game is running better than ever.


Zoom ‼

The game engine I've been working on, SPACE BOX, is now able to export to web, so I'm planning on turning nugget.fun into a games portal by releasing my games on it and adding an accounts system. The upgraded server and software will make it easier to create and maintain. I'm also thinking of using advertising and subscriptions to support the portal, so some of these services, like webmail or the RSS reader, may be offered to accounts that upgrade to a paid subscription.