Пример #1
0
def normalize_config(config):
    #finished
    """Check config file's structure and contents for everything that can make the daemon fail, spits out warnings about inconsistent entries and deletes them from the daemon's dictionary"""
    #Should there be some problems with the logfile, log to the /var/log/daemon.log
    #Well, an empty file with curly braces should do. But Python has its own way of handling a try to get a value from a dict by a non-existent key.
    #Precisely, it returns an exception, and to catch this, we need to wrap in try:except many blocks.
    #I think that the most efficient way is adding the basic keys (config, exceptions, rules and default section) if they don't exist in the actual dictionary. 
    #Checking everything else is already handled by all the other functions.
    categories = {"globals":{}, "exceptions":[], "rules":[], "default":{}}
    for category in categories.keys():  
        if category not in config.keys():
            config[category] = categories[category]
    #Now check if logfile exists. If it doesn't, we have to create it.
    try:
        logfile_var = config["globals"]["logfile"]
    except KeyError:
        logfile_var = "/var/log/pautomount.log"
    if not os.path.exists(logfile_var):
        try:
            os.touch(logfile_var)
        except:
            logger("Logfile creation in path "+logfile_var+" not permitted. Falling back to default.")
            logfile_var = "/var/log/daemon.log"   
    config["globals"]["logfile"] = logfile_var
    #OK. We have a logfile that should work. I suppose we can just redirect stderr and let all 
    #the uncaught exception output appear there.
    #Checks will be added to this function in case lack of check can mean something dreadful.
    return config
Пример #2
0
 def create_config_file(self, file_name, content):
     config_dir = os.path.join(settings.PROJECT_DIR, "analyse/tests/configs/")
     config = os.path.join(config_dir, file_name)
     os.touch(config)
     f = open(config, "w")
     f.write(content)
     return config
Пример #3
0
 def write_to_temp(self, file, content):
     temp_dir = os.path.join(settings.PROJECT_DIR, "temp")
     os.makedirs_p(temp_dir)
     temp_file = os.path.join(temp_dir, file)
     os.touch(temp_file)
     f = open(temp_file, "w")
     f.write(content)
     return temp_file
Пример #4
0
def check_file(file_path, file_name):
    print("-------------FILE_CHECK------------------")
    chfile = os.path.isfile(file_path)
    wfile = ntpath('/../../').root
    if os.path.exists(file_name):
        print("I get the file >Hi dude")
        if not os.path.exists(file_name):
            print(("The File s% it's not created " % file_name))
            os.touch(file_name)
            print(("The file s% has been Created ..." % file_name))
Пример #5
0
    def __init__(self, path: str):
        self.db_path = os.path.join(path, "db/db.sqlite")

        try:
            con = sqlite3.connect(self.db_path, check_same_thread=False)
        except:
            os.touch(self.db_path)

        if os.stat(self.db_path).st_size == 0:
            try:
                c = con.cursor()
                c.execute("""CREATE TABLE IF NOT EXISTS Data
                    ( protocol TEXT, url TEXT PRIMARY KEY UNIQUE, data TEXT, lastvisit INTEGER )
                """)
            except Exception as e:
                raise e
Пример #6
0
    def testShouldReturnTrueIfAllResultsJsonGenerated(self):
        project1 = self.config.result_dir()
				
        os.touch(os.path.join(project1, 'build_times.txt'))
        os.touch(os.path.join(project1, 'pass_rate.txt'))
        os.touch(os.path.join(project1, 'per_build_time.txt'))
        os.touch(os.path.join(project1, 'successful_rate.txt'))
        
        self.assertEquals(True, self.config.has_result())
Пример #7
0
def make_dir():
    log_path = './log'
    model_path = './model'
    svm_log = './log/multi_svm.log'
    svm_train = './log/multi_svm_train.log'
    log_error = './log/multi_svm_error.log'
    train_data = './train_data'

    if not os.path.exists(log_path):
        os.mkdir(log_path)
        logger.info("multi_svm의 log를 저장할./log 디렉토리를 생성하였습니다.")
        if not os.path.exists(log_error):
            os.touch(log_error)
            logger.info(
                "multi_svm의 error를 저장할./log/multi_svm_error.log파일을 생성하였습니다.")
        if not os.path.exists(svm_log):
            os.touch(svm_log)
            logger.info(
                "multi_svm을 사용한 주제예측을 시행일자가 저장될 ./log/multi_svm.log파일이 생성하었습니다."
            )
        if not os.path.exists(svm_train):
            os.touch(svm_train)
            logger.info(
                "multi_svm 모델훈련 시행일자가 저장될 ./log/multi_svm_train.log파일을 생성하였습니다"
            )
    if not os.path.exists(model_path):
        os.mkdir(model_path)
        logger.info("multi_svm model을 저장할 ./model 디렉토리를 생성하였습니다.")
    if not os.path.exists(train_data):
        os.mkdir(train_data)
        logger.info("multi_svm 모델 train data가 저장될 ./train_data 디렉토리를 생성하였습니다.")
Пример #8
0
def mass_to_colored_png(debug=False):
	# greyscale, unless a palette is detected
	for root, dirs, files in os.walk('../gfx/'):
		if 'pics' not in root and 'trainers' not in root:
			for name in files:
				if debug: print os.path.splitext(name), os.path.join(root, name)
				if os.path.splitext(name)[1] == '.2bpp':
					if os.path.splitext(name)[0]+'.pal' in files:
						to_png(os.path.join(root, name), None, os.path.join(root, os.path.splitext(name)[0]+'.pal'))
					else:
						to_png(os.path.join(root, name))
					os.touch(os.path.join(root, name))
	
	# only monster and trainer pics for now
	for root, dirs, files in os.walk('../gfx/pics/'):
		for name in files:
			if debug: print os.path.splitext(name), os.path.join(root, name)
			if os.path.splitext(name)[1] == '.2bpp':
				if 'normal.pal' in files:
					to_png(os.path.join(root, name), None, os.path.join(root, 'normal.pal'))
				else:
					to_png(os.path.join(root, name))
				os.touch(os.path.join(root, name))
	
	for root, dirs, files in os.walk('../gfx/trainers/'):
		for name in files:
			if debug: print os.path.splitext(name), os.path.join(root, name)
			if os.path.splitext(name)[1] == '.2bpp':
				to_png(os.path.join(root, name), None, os.path.join(root, name[:-5]+'.pal'))
				os.touch(os.path.join(root, name))
Пример #9
0
def mass_decompress(debug=False):
	for root, dirs, files in os.walk('../gfx/'):
		for name in files:
			if 'lz' in name:
				if '/pics' in root:
					if 'front' in name:
						id = root.split('pics/')[1][:3]
						if id != 'egg':
							with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read(), 'vert', sizes[int(id)-1])
						else:
							with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read(), 'vert', 4)
						to_file(os.path.join(root, 'front.2bpp'), de.pic)
						to_file(os.path.join(root, 'tiles.2bpp'), de.animtiles)
					elif 'back' in name:
						with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read(), 'vert')
						to_file(os.path.join(root, 'back.2bpp'), de.output)
				elif '/trainers' in root or '/fx' in root:
					with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read(), 'vert')
					to_file(os.path.join(root, os.path.splitext(name)[0]+'.2bpp'), de.output)
				else:
					with open(os.path.join(root, name), 'rb') as lz: de = Decompressed(lz.read())
					to_file(os.path.join(root, os.path.splitext(name)[0]+'.2bpp'), de.output)
				os.touch(os.path.join(root, name))
Пример #10
0
    'test2': '*****@*****.**',
    'test3': '*****@*****.**',
    'test4': '*****@*****.**'
}


def Dumpfile():
    f = file(fb, 'W')
    p.dump(list, f)
    f.close()


if os.path.isfile('fb.data'):
    friendab = 'fb.data'
else:
    os.touch('friendab.data')
    Dumpfile(fb)
    del fb
f = file(fb)
frilist = p.load(f)


class Person:
    def __init__(self, name):
        self.name = name

    def saysome(self):
        print 'The friedn %s,his E-mail is %s' % (sname, frilist[sname])


class addPerson:
Пример #11
0
        'Laexly':'*****@*****.**',
        'Fukc':'*****@*****.**',
        'Stifu':'*****@*****.**'
}


def Dumpfile(list):
        f=file(friendab,'w')
        p.dump(list,f)
        f.close()


if os.path.isfile('friendab.data'):
        friendab='friendab.data'
else:
        os.touch('friendab.data')
        Dumpfile(ab)
        del ab


f=file(friendab)
frilist=p.load(f)


class Person:
        def __init__(self,name):
                self.name=name
        def saysome(self):
                print 'The friend %s,his E-mail is %s '%(sname,frilist[sname])
class addPerson:
        def __init__(self,name,email):
Пример #12
0
 def testShouldReturnFalseIfAnyResultJsonIsMissing(self):
     project1 = self.config.result_dir()
     os.makedirs_p(project1)
     os.touch(os.path.join(project1, 'pass_rate.txt'))
     self.assertEquals(False, self.config.has_result())        
Пример #13
0
import os
import curtana.path as PATH

HOME = os.environ["HOME"]
MYCURTANA = os.path.join(HOME, ".curtana")
if __name__ == "__main__":
    os.mkdir(PATH.CURTANA)
    os.touch(PATH.RC)
Пример #14
0
     # Handles H3
     if (content.type == 'sub_sub_header'):
         text = text + '### ' + content.title + '\n\n'
     # Handles Code Blocks
     if (content.type == 'code'):
         text = text + '```\n' + content.title + '\n```\n'
     # Handles Images
     if (content.type == 'image'):
         text = text + '![' + content.id + '](' + content.source + ')\n\n'
     # Handles Bullets
     if (content.type == 'bulleted_list'):
         text = text + '* ' + content.title + '\n'
     # Handles Dividers
     if (content.type == 'divider'):
         text = text + '---' + '\n'
     # Handles Basic Text, Links, Single Line Code
     if (content.type == 'text'):
         text = text + content.title + '\n'
 title = post.title.replace(' ', '-')
 title = title.replace(',', '')
 title = title.replace(':', '')
 title = title.replace(';', '')
 title = title.lower()
 if post.title != "":
     try:
         os.touch('../content/journal/' + title + 'md')
     except:
         pass
     file = open('../content/journal/' + title + '.md', 'w')
     print('Wrote A New Page:' + title)
     file.write(text)