<commit_before>#!/usr/bin/env python3
import os, os.path
import shlex
import sys

import logging
logger=logging.getLogger(__name__)
debug, info, warning, error, panic = logger.debug, logger.info, logger.warning, logger.error, logger.critical

from .tools import *
from .utils import *

def _move(src, dest):
	assert os.path.exists(src)
	if os.path.exists(dest):
		assert os.path.isdir(dest)
	if os.path.relpath(src) == os.path.relpath(dest):
		return ''
	shsrc = shlex.quote(src)
	if dest.endswith(src):
		shdest = os.path.join(shlex.quote(dest[:-len(src)]), '"$src"')
	elif dest.startswith(src):
		shdest = os.path.join('"$src"', shlex.quote(dest[len(src):]))
	else:
		shdest = shlex.quote(dest)
	syntax = '''src={shsrc} dest={shdest}
  [[ -d "$dest" ]] || mkdir -p "$dest"
  [[ -d "$src" ]] && $MV -t "$dest" "$src"/*.* || file_error "$src"
'''.format(**locals())
	return syntax
def hier_arrange(*args, prefix='', init='', **kwargs):<commit_msg>shell expansion more sane<commit_after>#!/usr/bin/env python3
import os, os.path
import shlex
import sys

import logging
logger=logging.getLogger(__name__)
debug, info, warning, error, panic = logger.debug, logger.info, logger.warning, logger.error, logger.critical

from .tools import *
from .utils import *

def _move(src, dest):
	assert os.path.exists(src)
	if os.path.exists(dest):
		assert os.path.isdir(dest)
	if os.path.relpath(src) == os.path.relpath(dest):
		return ''
	shsrc = shlex.quote(src)
#	if dest.endswith(src):
#		shdest = os.path.join(shlex.quote(dest[:-len(src)]), '"$src"')
	if src in dest:
		shdest = shlex.quote(dest).replace(src, '"$src"')
	else:
		shdest = shlex.quote(dest)
	syntax = '''src={shsrc} dest={shdest}
  [[ -d "$dest" ]] || mkdir -p "$dest"
  [[ -d "$src" ]] && $MV -t "$dest" "$src"/*.* || file_error "$src"
'''.format(**locals())
	return syntax
def hier_arrange(*args, prefix='', init='', **kwargs):
{'fraction_non_alphanumeric': 0.20212201591511936, 'fraction_numerical': 0.0010610079575596816, 'mean_word_length': 4.75, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1239342', 'n_tokens_mistral': 732, 'n_tokens_neox': 709, 'n_words': 164}