Ejemplo n.º 1
0
    def handle(self, *args, **options):
        cal = Calendar()
        cal.add("prodid", "-//My calendar product//mxm.dk//")
        cal.add("version", "2.0")

        cursor = DatabaseWrapper(
            settings_dict={"NAME": options["inputfile"], "CONN_MAX_AGE": None, "OPTIONS": [], "AUTOCOMMIT": False}
        ).cursor()

        cursor.execute(
            "SELECT Z_PK, cast(ZWHEN as integer), ZDURATIONMINUTES, ZNAME FROM ZPOMODOROS ORDER BY ZWHEN DESC LIMIT %s",
            [options["limit"]],
        )

        for zpk, zwhen, zminutes, zname in cursor.fetchall():
            seconds = zminutes * 60
            start = datetime.datetime.fromtimestamp(zwhen + NSTIMEINTERVAL - seconds, pytz.utc)
            end = datetime.datetime.fromtimestamp(zwhen + NSTIMEINTERVAL, pytz.utc)

            event = Event()
            event.add("summary", u"{0}".format(zname, zminutes))
            event.add("dtstart", start)
            event.add("dtend", end)
            event["uid"] = zpk
            cal.add_component(event)
        print cal.to_ical()
Ejemplo n.º 2
0
 def test_memory_db_test_name(self):
     """A named in-memory db should be allowed where supported."""
     from django.db.backends.sqlite3.base import DatabaseWrapper
     settings_dict = {
         'TEST': {
             'NAME': 'file:memorydb_test?mode=memory&cache=shared',
         }
     }
     creation = DatabaseWrapper(settings_dict).creation
     self.assertEqual(creation._get_test_db_name(), creation.connection.settings_dict['TEST']['NAME'])
Ejemplo n.º 3
0
 def test_memory_db_test_name(self):
     """A named in-memory db should be allowed where supported."""
     from django.db.backends.sqlite3.base import DatabaseWrapper
     settings_dict = {
         'TEST': {
             'NAME': 'file:memorydb_test?mode=memory&cache=shared',
         }
     }
     creation = DatabaseWrapper(settings_dict).creation
     self.assertEqual(creation._get_test_db_name(), creation.connection.settings_dict['TEST']['NAME'])
Ejemplo n.º 4
0
    def handle(self, *args, **options):
        tags = {}
        if options['tagfile']:
            with open(options['tagfile']) as fp:
                for line in fp:
                    key, value = line.strip().split('=')
                    tags[key] = value

        user = User.objects.get(username=options['user'])
        pomodoros = Pomodoro.objects.filter(owner=user)
        if options['no_input'] is False:
            while len(pomodoros):
                self.stdout.write('Delete %d pomodoros for %s' % (len(pomodoros), user))
                if input('Confirm yes/no ').lower() == 'yes':
                    break
        pomodoros.delete()
        self.stdout.write('Importing Pomodoros')

        cursor = DatabaseWrapper(settings_dict={
            'NAME': options['inputfile'],
            'CONN_MAX_AGE': None,
            'OPTIONS': [],
            'AUTOCOMMIT': False,
        }).cursor()
        cursor.execute('SELECT cast(ZWHEN as integer), ZDURATIONMINUTES, ZNAME FROM ZPOMODOROS ')
        for zwhen, zminutes, zname in cursor.fetchall():
            seconds = zminutes * 60

            p = Pomodoro()
            p.title = zname
            p.owner = user
            #  p.start = datetime.datetime.fromtimestamp(zwhen + NSTIMEINTERVAL - seconds, pytz.utc)
            #  p.end = datetime.datetime.fromtimestamp(zwhen + NSTIMEINTERVAL, pytz.utc)
            p.created = datetime.datetime.fromtimestamp(zwhen + NSTIMEINTERVAL - seconds, pytz.utc)

            for word in p.title.split():
                if word.startswith('#'):
                    p.category = word.strip('#')
                    break

            if not p.category:
                for search, tag in tags.items():
                    if search in p.title:
                        p.category = tag
                        break

            p.duration = zminutes
            p.save()
            self.stdout.write('Added %s' % p)
Ejemplo n.º 5
0
    def close(self):
        global pool

        if self.connection is None:
            return

        # print "Pool enabled: %s Connection closing: %s" % \
        #    (self.pool_enabled, id(self.connection))

        if not self.pool_enabled and self.settings_dict["NAME"] != ":memory:":
            BaseDatabaseWrapper.close(self)
            return

        pool.putconn(self.connection)
        self.connection = None
Ejemplo n.º 6
0
 def execute(self, *args, **options):
     settings = connections['default'].settings_dict.copy()
     settings['ENGINE'] = 'sqlite3'
     if 'application_name' in settings['OPTIONS']:
         del settings['OPTIONS']['application_name']
     connections['default'] = DatabaseWrapper(settings)
     return MakeMigrations().execute(*args, **options)
Ejemplo n.º 7
0
 def test_memory_db_test_name(self):
     """A named in-memory db should be allowed where supported."""
     from django.db.backends.sqlite3.base import DatabaseWrapper
     settings_dict = {
         'TEST': {
             'NAME': 'file:memorydb_test?mode=memory&cache=shared',
         }
     }
     wrapper = DatabaseWrapper(settings_dict)
     creation = wrapper.creation
     if creation.connection.features.can_share_in_memory_db:
         expected = creation.connection.settings_dict['TEST']['NAME']
         self.assertEqual(creation._get_test_db_name(), expected)
     else:
         msg = ("Using a shared memory database with `mode=memory` in the "
                "database name is not supported in your environment, "
                "use `:memory:` instead.")
         with self.assertRaisesMessage(ImproperlyConfigured, msg):
             creation._get_test_db_name()
 def execute(self, *args, **options):
     settings = connections['default'].settings_dict.copy()
     settings['ENGINE'] = 'sqlite3'
     connections['default'] = DatabaseWrapper(settings)
     return MakeMigrations().execute(*args, **options)