import os, sys, site

site.addsitedir('<%= @path %>')
os.environ['SENTRY_CONF'] = '<%= @path %>/sentry.conf'

# Check to see if the project exists on the team
from sentry.utils.runner import configure
configure()
from sentry.models import Project, ProjectKey

for project in Project.objects.all():
  doit = False
  if project.id and (not project.is_internal_project()):
    dsn_file = '<%= @path %>/dsn/' + project.name.lower()
    try:
      dsn = ProjectKey.objects.get(project_id=project.id).get_dsn()
    except:
      dsn = False

    if dsn:
      # we have a project ID and a DSN
      saved_dsn = False
      if os.path.isfile(dsn_file):
        # DSN file exists for this project.
        # make sure its value matches what we expect it to be
        with open(dsn_file, 'r') as f:
          saved_dsn = f.read()
        if saved_dsn != dsn:
          doit = True
      else:
        # the dsn_file does not exist for some reason
        doit = True

      if doit:
        new_dsn = open(dsn_file, 'a')
        new_dsn.write(dsn)
        new_dsn.close()


import os, sys, site

site.addsitedir('<%= @path %>')
os.environ['SENTRY_CONF'] = '<%= @path %>/sentry.conf'

# Check to see if the project exists on the team
from sentry.utils.runner import configure
configure()
from sentry.models import Project, ProjectKey

for project in Project.objects.all():
  doit = False
  if project.id and (not project.is_internal_project()):
    dsn_file = '<%= @path %>/dsn/' + project.name.lower()
    try:
      dsn = ProjectKey.objects.get(project_id=project.id).get_dsn()
    except:
      dsn = False

    if dsn:
      # we have a project ID and a DSN
      saved_dsn = False
      if os.path.isfile(dsn_file):
        # DSN file exists for this project.
        # make sure its value matches what we expect it to be
        with open(dsn_file, 'r') as f:
          saved_dsn = f.read()
        if saved_dsn != dsn:
          doit = True
      else:
        # the dsn_file does not exist for some reason
        doit = True

      if doit:
        new_dsn = open(dsn_file, 'w')
        new_dsn.write(dsn)
        new_dsn.close()


Use 'w' instead of 'a' when opening the DSN cache
Use 'w' instead of 'a' when opening the DSN cache

The use of 'a' to append to the DSN cache file is causing duplicate
entries to be inserted.  We should use 'w' to write to the file to
ensure that it is only one line.
