# Path: srs/models.py
# class SrsTiming(object):
#     def __init__(self):
#         self.times = dict()
#         self.counter = 0
# 
#     def start(self, name):
#         self.times[name] = (self.counter, datetime.datetime.now(), name)
#         self.counter += 1
# 
#     def stop(self, name):
#         self.times[name] = (
#             self.times[name][0],
#             datetime.datetime.now() - self.times[name][1],
#             name,
#         )
# 
#     @property
#     def sorted_list(self):
#         return sorted(self.times.values(), key=operator.itemgetter(0))
# 
#     def __str__(self):
#         return "\n".join([f"{t[2]}: {t[1].seconds}.{int(t[1].microseconds / 10000)}" for t in self.sorted_list])
# 
# Path: srs/upload.py
# class UploadError(Exception):
# class AlreadyExistsError(UploadError):
#     def __init__(self, demofile, *args, **kwargs):
#     def __init__(self, demofile, replay, *args, **kwargs):
# def xmlrpc_upload(username, password, filename, demofile, subject, comment, tags, owner):
# def parse_uploaded_file(path, timer, tags, subject, comment, owner_ac, move=True, reparse_if_exists=True):
# def save_uploaded_file(ufile, filename):
# def store_demofile_data(demofile, tags, path, short, long_text, user):
#     def truncate_option(k, v):
# def upload_platform_stats(demofile):
# def rate_match(replay):
# def rate_matches(replays):
# def set_accountid(player):
# def save_tags(replay, tags):
# def set_autotag(replay):
# def save_desc(replay, short, long_text, autotag):
# def clamp(val, low, high):
# def floats2rgbhex(floats):
# def del_replay(replay):
# def reparse(replay, path=None, tags=None, subject=None, comment=None, owner_ac=None):


import os.path
from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand, CommandError
from srs.models import SrsTiming
from srs.upload import parse_uploaded_file, timer as timer_
# This file is part of the "spring relay site / srs" program. It is published
# under the GPLv3.
#
# Copyright (C) 2018 Daniel Troeder (daniel #at# admin-box #dot# com)
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""
Django manage.py command to upload a sdf.
"""




timer = timer_


class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument("demofile", type=str, help="Path to demofile.")

    def handle(self, *args, **options):
        global timer

        path = options["demofile"]
        if not os.path.exists(path):
            raise CommandError("File {!r} does not exist.".format(path))

        if not timer:

# Path: srs/models.py
# class SrsTiming(object):
#     def __init__(self):
#         self.times = dict()
#         self.counter = 0
# 
#     def start(self, name):
#         self.times[name] = (self.counter, datetime.datetime.now(), name)
#         self.counter += 1
# 
#     def stop(self, name):
#         self.times[name] = (
#             self.times[name][0],
#             datetime.datetime.now() - self.times[name][1],
#             name,
#         )
# 
#     @property
#     def sorted_list(self):
#         return sorted(self.times.values(), key=operator.itemgetter(0))
# 
#     def __str__(self):
#         return "\n".join([f"{t[2]}: {t[1].seconds}.{int(t[1].microseconds / 10000)}" for t in self.sorted_list])
# 
# Path: srs/upload.py
# class UploadError(Exception):
# class AlreadyExistsError(UploadError):
#     def __init__(self, demofile, *args, **kwargs):
#     def __init__(self, demofile, replay, *args, **kwargs):
# def xmlrpc_upload(username, password, filename, demofile, subject, comment, tags, owner):
# def parse_uploaded_file(path, timer, tags, subject, comment, owner_ac, move=True, reparse_if_exists=True):
# def save_uploaded_file(ufile, filename):
# def store_demofile_data(demofile, tags, path, short, long_text, user):
#     def truncate_option(k, v):
# def upload_platform_stats(demofile):
# def rate_match(replay):
# def rate_matches(replays):
# def set_accountid(player):
# def save_tags(replay, tags):
# def set_autotag(replay):
# def save_desc(replay, short, long_text, autotag):
# def clamp(val, low, high):
# def floats2rgbhex(floats):
# def del_replay(replay):
# def reparse(replay, path=None, tags=None, subject=None, comment=None, owner_ac=None):


# Path: srs/management/commands/upload_replay.py
import os.path
from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand, CommandError
from srs.models import SrsTiming
from srs.upload import parse_uploaded_file, timer as timer_

# This file is part of the "spring relay site / srs" program. It is published
# under the GPLv3.
#
# Copyright (C) 2018 Daniel Troeder (daniel #at# admin-box #dot# com)
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""
Django manage.py command to upload a sdf.
"""




timer = timer_


class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument("demofile", type=str, help="Path to demofile.")

    def handle(self, *args, **options):
        global timer

        path = options["demofile"]
        if not os.path.exists(path):
            raise CommandError("File {!r} does not exist.".format(path))

        if not timer:

            timer = SrsTiming()