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

# Based on previous work by
# <NAME> (see: http://stackoverflow.com/questions/10217067/implementing-a-full-python-unix-style-daemon-process)
# and <NAME> (see: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/)

# Adapted by M.Hendrix [2015]

# daemon99.py creates an XML-file and uploads data to the server.

import os, sys, shutil, glob, platform, time, commands
from libdaemon import Daemon

DEBUG = False

class MyDaemon(Daemon):
	def run(self):
		sampleptr = 0
		samples = 1
		#datapoints = 1
		#data = range(samples)

		sampleTime = 60
		cycleTime = samples * sampleTime

		myname = os.uname()[1]
		# mount_path = '/srv/array1/dataspool/'
		mount_path = '/tmp/test'
		remote_path = mount_path + myname
		remote_lock = remote_path + '/client.lock'

		# sync to whole minute
		waitTime = (cycleTime + sampleTime) - (time.time() % cycleTime)
		if DEBUG:
			print "NOT waiting {0} s.".format(waitTime)
		else:
			time.sleep(waitTime)
		while True:
			startTime=time.time()

			if os.path.ismount(mount_path):
				do_mv_data(remote_path)
				do_xml(remote_path)
			else:
				if DEBUG:print "dataspool not available"

			waitTime = sampleTime - (time.time() - startTime) - (startTime%sampleTime)
			if (waitTime > 0):
				if DEBUG:print "Waiting {0} s".format(waitTime)
				time.sleep(waitTime)

def do_mv_data(rpath):
	hostlock = rpath + '/host.lock'
	clientlock = rpath + '/client.lock'
	count_internal_locks=1

	# wait 5 seconds for processes to finish
	time.sleep(5)

	while os.path.isfile(hostlock):
		if DEBUG:print "hostlock exists"
		# wait while the server has locked the directory
		time.sleep(1)

	# server already sets the client.lock. Do it anyway.
	lock(clientlock)

	# prevent race conditions
	while os.path.isfile(hostlock):
		if DEBUG:print "hostlock exists. WTF?"
		# wait while the server has locked the directory
		time.sleep(1)<commit_msg>path is not a mount<commit_after>#!/usr/bin/env python

# Based on previous work by
# <NAME> (see: http://stackoverflow.com/questions/10217067/implementing-a-full-python-unix-style-daemon-process)
# and <NAME> (see: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/)

# Adapted by M.Hendrix [2015]

# daemon99.py creates an XML-file and uploads data to the server.

import os, sys, shutil, glob, platform, time, commands
from libdaemon import Daemon

DEBUG = False

class MyDaemon(Daemon):
	def run(self):
		sampleptr = 0
		samples = 1
		#datapoints = 1
		#data = range(samples)

		sampleTime = 60
		cycleTime = samples * sampleTime

		myname = os.uname()[1]
		# mount_path = '/srv/array1/dataspool/'
		mount_path = '/tmp/test'
		remote_path = mount_path + myname
		remote_lock = remote_path + '/client.lock'

		# sync to whole minute
		waitTime = (cycleTime + sampleTime) - (time.time() % cycleTime)
		if DEBUG:
			print "NOT waiting {0} s.".format(waitTime)
		else:
			time.sleep(waitTime)
		while True:
			startTime=time.time()

			if os.path.exists(remote_path):
				do_mv_data(remote_path)
				do_xml(remote_path)
			else:
				if DEBUG:print remote_path + " not available"

			waitTime = sampleTime - (time.time() - startTime) - (startTime%sampleTime)
			if (waitTime > 0):
				if DEBUG:print "Waiting {0} s".format(waitTime)
				time.sleep(waitTime)

def do_mv_data(rpath):
	hostlock = rpath + '/host.lock'
	clientlock = rpath + '/client.lock'
	count_internal_locks=1

	# wait 5 seconds for processes to finish
	time.sleep(5)

	while os.path.isfile(hostlock):
		if DEBUG:print "hostlock exists"
		# wait while the server has locked the directory
		time.sleep(1)

	# server already sets the client.lock. Do it anyway.
	lock(clientlock)

	# prevent race conditions
	while os.path.isfile(hostlock):
		if DEBUG:print "hostlock exists. WTF?"
		# wait while the server has locked the directory
		time.sleep(1)
{'fraction_non_alphanumeric': 0.11790619331433014, 'fraction_numerical': 0.01813941435605079, 'mean_word_length': 3.8553459119496853, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '854030', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1355, 'n_words': 355}