<commit_before>#!/usr/bin/python

# Gitless - a version control system built on top of Git.
# Copyright (c) 2013  <NAME>.
# Licensed under GNU GPL, version 2.

"""Build Gitless package."""


import argparse
import compileall
import os
import re
import shutil
import stat


def main():
  parser = argparse.ArgumentParser(
      description="Build Gitless package")
  parser.add_argument('version', help='name of the version to package')

  args = parser.parse_args()

  rx = re.compile('build.py')

  cwd = os.getcwd()

  print 'Compiling all python files'
  # TODO(sperezde): compile with -OO.
  compileall.compile_dir(cwd, ddir=args.version, force=True, rx=rx)
  print 'Done compiling'

  print 'Creating dir %s' % args.version
  os.mkdir(args.version)
  print 'Dir created'

  for f in os.listdir(cwd):
    if f.endswith('.pyc'):
      new_path = os.path.join(args.version, f) 
      print 'moving file %s to %s' % (f, new_path)
      os.rename(f, new_path)
      _maybe_create_exec_file(f, args.version)

  _create_exec_file('gl', args.version, is_gl=True)

  gitpylib = os.path.join(cwd, 'gitpylib')
  gitpylib_dst = os.path.join(args.version, 'gitpylib')
  os.mkdir(gitpylib_dst)

  for f in os.listdir(gitpylib):
    if f.endswith('.pyc'):
      new_path = os.path.join(gitpylib_dst, f) 
      src_path = os.path.join('gitpylib', f)
      print 'moving file %s to %s' % (src_path, new_path)
      os.rename(src_path, new_path)

  shutil.copy('LICENSE.md', os.path.join(args.version, 'LICENSE.md'))

  _create_postflight_file(args.version)

  print 'Done'


def _maybe_create_exec_file(f, dst):
  match = re.match('gl_(\w+).pyc', f)
  if match:
    cmd = match.group(1)
    _create_exec_file(cmd, dst)


def _create_exec_file(cmd, dst, is_gl=False):
  if is_gl:
    path = os.path.join(dst, cmd)
  else:
    path = os.path.join(dst, 'gl-' + cmd)
  print 'Creating exec file for %s at %s' % (cmd, path)
  f = open(path, 'a')
  f.write('#!/bin/bash\n')
  if is_gl:
    f.write('python /usr/local/gitless/gl.pyc "$@"')
  else:
    f.write('python /usr/local/gitless/gl_%s.pyc "$@"' % cmd)
  f.close()
  os.chmod(path, (
    stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP))
  print 'Done creating exec file for %s at %s' % (cmd, path)


def _create_postflight_file(dst):
  print 'Creating postflight file'
  path = os.path.join(dst, 'postflight')
  f = open(path, 'a')
  f.write('#!/bin/bash\n')
  f.write('echo \'/usr/local/gitless\' > /etc/paths.d/gitless\n')
  f.close()
  os.chmod(path, (
    stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP))
  print 'Done creating postflight file'


if __name__ == '__main__':
  main()
<commit_msg>Fixed permissions issue that arised in linux<commit_after>#!/usr/bin/python

# Gitless - a version control system built on top of Git.
# Copyright (c) 2013  <NAME>.
# Licensed under GNU GPL, version 2.

"""Build Gitless package."""


import argparse
import compileall
import os
import re
import shutil
import stat

FILE_PERMISSIONS = (
    stat.S_IRUSR |  # Owner reads.
    stat.S_IWUSR |  # Owner writes.
    stat.S_IXUSR |  # Owner executes.
    stat.S_IRGRP |  # Group reads.
    stat.S_IXGRP |  # Group writes.
    stat.S_IROTH |  # Other reads.
    stat.S_IXOTH    # Other executes.
)


def main():
  parser = argparse.ArgumentParser(
      description="Build Gitless package")
  parser.add_argument('version', help='name of the version to package')

  args = parser.parse_args()

  rx = re.compile('build.py')

  cwd = os.getcwd()

  print 'Compiling all python files'
  # TODO(sperezde): compile with -OO.
  compileall.compile_dir(cwd, ddir=args.version, force=True, rx=rx)
  print 'Done compiling'

  print 'Creating dir %s' % args.version
  os.mkdir(args.version)
  print 'Dir created'

  for f in os.listdir(cwd):
    if f.endswith('.pyc'):
      new_path = os.path.join(args.version, f) 
      print 'moving file %s to %s' % (f, new_path)
      os.rename(f, new_path)
      _maybe_create_exec_file(f, args.version)

  _create_exec_file('gl', args.version, is_gl=True)

  gitpylib = os.path.join(cwd, 'gitpylib')
  gitpylib_dst = os.path.join(args.version, 'gitpylib')
  os.mkdir(gitpylib_dst)

  for f in os.listdir(gitpylib):
    if f.endswith('.pyc'):
      new_path = os.path.join(gitpylib_dst, f) 
      src_path = os.path.join('gitpylib', f)
      print 'moving file %s to %s' % (src_path, new_path)
      os.rename(src_path, new_path)

  shutil.copy('LICENSE.md', os.path.join(args.version, 'LICENSE.md'))

  _create_postflight_file(args.version)

  print 'Done'


def _maybe_create_exec_file(f, dst):
  match = re.match('gl_(\w+).pyc', f)
  if match:
    cmd = match.group(1)
    _create_exec_file(cmd, dst)


def _create_exec_file(cmd, dst, is_gl=False):
  if is_gl:
    path = os.path.join(dst, cmd)
  else:
    path = os.path.join(dst, 'gl-' + cmd)
  print 'Creating exec file for %s at %s' % (cmd, path)
  f = open(path, 'a')
  f.write('#!/bin/bash\n')
  if is_gl:
    f.write('python /usr/local/gitless/gl.pyc "$@"')
  else:
    f.write('python /usr/local/gitless/gl_%s.pyc "$@"' % cmd)
  f.close()
  os.chmod(path, FILE_PERMISSIONS)
  print 'Done creating exec file for %s at %s' % (cmd, path)


def _create_postflight_file(dst):
  print 'Creating postflight file'
  path = os.path.join(dst, 'postflight')
  f = open(path, 'a')
  f.write('#!/bin/bash\n')
  f.write('echo \'/usr/local/gitless\' > /etc/paths.d/gitless\n')
  f.close()
  os.chmod(path, FILE_PERMISSIONS)
  print 'Done creating postflight file'


if __name__ == '__main__':
  main()

{'fraction_non_alphanumeric': 0.1510791366906475, 'fraction_numerical': 0.002158273381294964, 'mean_word_length': 3.4523618895116095, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5224751', 'n_tokens_mistral': 2251, 'n_tokens_neox': 2153, 'n_words': 496}