<commit_before>#!/usr/bin/env python

import errno
import glob
import os
import subprocess
import sys
import tempfile

from lib.util import *


SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))


def main():
  try:
    ensure_s3put()
    if not dist_newer_than_head():
      create_dist = os.path.join(SOURCE_ROOT, 'script', 'create-dist.py')
      subprocess.check_call([sys.executable, create_dist])
    upload()
  except AssertionError as e:
    return e.message


def ensure_s3put():
  output = ''
  try:
    output = subprocess.check_output(['s3put', '--help'])
  except OSError as e:
    if e.errno != errno.ENOENT:
      raise
  assert 'multipart' in output, 'Error: Please install boto and filechunkio'


def dist_newer_than_head():
  with scoped_cwd(SOURCE_ROOT):
    try:
      head_time = subprocess.check_output(['git', 'log', '--pretty=format:%at',
                                           '-n', '1']).strip()
      dist_time = os.path.getmtime(os.path.join(SOURCE_ROOT, 'atom-shell.zip'))
    except OSError as e:
      if e.errno != errno.ENOENT:
        raise
      return False

  return dist_time > int(head_time)


def upload():
  os.chdir(SOURCE_ROOT)
  bucket, access_key, secret_key = s3_config()
  commit = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip()

  s3put(bucket, access_key, secret_key, SOURCE_ROOT,
        'atom-shell/{0}'.format(commit), glob.glob('atom-shell*.zip'))

  update_version(bucket, access_key, secret_key)
<commit_msg>Use result of `git describe` as version.<commit_after>#!/usr/bin/env python

import errno
import glob
import os
import subprocess
import sys
import tempfile

from lib.util import *


SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))


def main():
  try:
    ensure_s3put()
    if not dist_newer_than_head():
      create_dist = os.path.join(SOURCE_ROOT, 'script', 'create-dist.py')
      subprocess.check_call([sys.executable, create_dist])
    upload()
  except AssertionError as e:
    return e.message


def ensure_s3put():
  output = ''
  try:
    output = subprocess.check_output(['s3put', '--help'])
  except OSError as e:
    if e.errno != errno.ENOENT:
      raise
  assert 'multipart' in output, 'Error: Please install boto and filechunkio'


def dist_newer_than_head():
  with scoped_cwd(SOURCE_ROOT):
    try:
      head_time = subprocess.check_output(['git', 'log', '--pretty=format:%at',
                                           '-n', '1']).strip()
      dist_time = os.path.getmtime(os.path.join(SOURCE_ROOT, 'atom-shell.zip'))
    except OSError as e:
      if e.errno != errno.ENOENT:
        raise
      return False

  return dist_time > int(head_time)


def upload():
  os.chdir(SOURCE_ROOT)
  bucket, access_key, secret_key = s3_config()
  commit = subprocess.check_output(['git', 'describe', '--tags']).strip()

  s3put(bucket, access_key, secret_key, SOURCE_ROOT,
        'atom-shell/{0}'.format(commit), glob.glob('atom-shell*.zip'))

  update_version(bucket, access_key, secret_key)

{'fraction_non_alphanumeric': 0.13561553653719552, 'fraction_numerical': 0.004608294930875576, 'mean_word_length': 3.372661870503597, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1498426', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1019, 'n_words': 228}