Skip to content

Commit

Permalink
Merge pull request #2 from ruuti/develop
Browse files Browse the repository at this point in the history
Version 0.2.1
  • Loading branch information
ruuti authored Nov 24, 2016
2 parents 19d63b2 + 18fce52 commit ef81c0f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 56 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ In addition to publishing updates via the appcast feed, Django-sparkle-project c

## Setup

1. `pip install https://github.com/ruuti/django-sparkle-project`
1. `pip install https://github.com/ruuti/django-sparkle-project/archive/master.zip`
2. Add `sparkle` to your installed apps
4. In `settings.py` add `SPARKLE_PRIVATE_KEY_PATH` which is the path to your private DSA key for signing your releases.
5. In `urls.py` include the sparkle URLs by adding something like `(r'^sparkle/', include('sparkle.urls'))`.
Expand Down
62 changes: 8 additions & 54 deletions sparkle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,73 +28,27 @@ class Version(models.Model):
release_notes = models.TextField(blank=True, null=True)
minimum_system_version = models.CharField(blank=True, null=True, max_length=10)
published = models.DateTimeField(auto_now_add=True)
update = models.FileField(upload_to='sparkle/')
update = models.FileField()
active = models.BooleanField(default=False)

def __unicode__(self):
return self.title

def save(self, *args, **kwargs):
super(Version, self).save(*args, **kwargs)

update = False
path = os.path.join(settings.MEDIA_ROOT, self.update.path)


# if there is no dsa signature and a private key is provided in the settings
if not self.dsa_signature and SPARKLE_PRIVATE_KEY_PATH and os.path.exists(SPARKLE_PRIVATE_KEY_PATH):
command = 'openssl dgst -sha1 -binary < "%s" | openssl dgst -dss1 -sign "%s" | openssl enc -base64' % (path, SPARKLE_PRIVATE_KEY_PATH)
process = os.popen(command)
self.dsa_signature = process.readline().strip()
process.close()
update = True

# if there is no length and it is a zip file
# extract it to a tempdir and calculate the length
# also parse the plist file for versions
if not self.length and path.endswith('.zip'):
zip_file = zipfile.ZipFile(path)
tempdir = tempfile.mkdtemp()
files = zip_file.namelist()
start_path = None

for f in files:
if f.endswith('/'):
d = os.path.join(tempdir, f)
if not start_path:
start_path = d
os.makedirs(d)
else:
zip_file.extract(f, tempdir)

total_size = 0
for dirpath, dirnames, filenames in os.walk(start_path):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)

info_plist = os.path.join(start_path, 'Contents/Info.plist')

if os.path.exists(info_plist):
plist = plistlib.readPlist(info_plist)

if not self.version and 'CFBundleVersion' in plist:
self.version = plist.get('CFBundleVersion')

if not self.short_version and 'CFBundleShortVersionString' in plist:
self.short_version = plist.get('CFBundleShortVersionString')

if not self.minimum_system_version and 'LSMinimumSystemVersion' in plist:
self.minimum_system_version = plist.get('LSMinimumSystemVersion')

shutil.rmtree(tempdir)

self.length = total_size
update = True

if update:
self.save()


# Calculate file size
if not self.length :
# TODO: set correct size
self.length = 0

super(Version, self).save(*args, **kwargs)

class SystemProfileReport(models.Model):
"""A system profile report"""
Expand Down
2 changes: 1 addition & 1 deletion sparkle/templates/sparkle/appcast.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</description>
<pubDate>{{ version.published|date:"r" }}</pubDate>
{% if version.minimum_system_version %}<sparkle:minimumSystemVersion>{{ version.minimum_system_version }}</sparkle:minimumSystemVersion>{% endif %}
<enclosure url="http://{{ site.domain }}{{ version.update.url }}" sparkle:version="{{ version.version }}" {% if version.short_version %}sparkle:shortVersionString="{{ version.short_version }}"{% endif %} length="{{ version.length }}" type="application/octet-stream" {% if version.dsa_signature %}sparkle:dsaSignature="{{ version.dsa_signature }}"{% endif %} />
<enclosure url="{{ version.update.url }}" sparkle:version="{{ version.version }}" {% if version.short_version %}sparkle:shortVersionString="{{ version.short_version }}"{% endif %} length="{{ version.length }}" type="application/octet-stream" {% if version.dsa_signature %}sparkle:dsaSignature="{{ version.dsa_signature }}"{% endif %} />
</item>
{% endfor %}
</channel>
Expand Down

0 comments on commit ef81c0f

Please sign in to comment.