Esempio n. 1
0
	def writefile(self,filename,sha1v):
		file = self.getfile(filename)
		path = self.dir+filename
		if os.path.isfile(path):
			input = FileUtil.open(path,"r")
			oldfile = input.read()
			input.close()
		else:
			oldfile = None
		output = FileUtil.open(path,"wb")
		output.write(file)
		print 'Update	'+filename+'				OK!'
		output.close()
		input = FileUtil.open(path,"rb")
		sha1vv = FileUtil.get_file_sha1(input)
		#print sha1v.strip()
		#print sha1vv.strip()
		input.close()
		if sha1v.strip()==sha1vv.strip() :
			print 'Verify	'+filename+'				OK!'
		else:
			print 'Verify	'+filename+'				Fail!'
			if oldfile:
				output = FileUtil.open(path,"wb")
				output.write(oldfile)
				output.close()
			print 'Recover	'+filename+'				OK!'
		if filename.strip() == '/autoupdate.ini'.strip():
			newconfig = Config(__config__)
			newconfig.writeconfig('autoupdate', 'server',common.AUTOUPDATE_SERVER_STR)
			print 'ReWrite	/autoupdate.ini				OK!'
			common.reloadini()
			print 'ReLoad	/autoupdate.ini				OK!'
Esempio n. 2
0
 def writefile(self, filename, sha1v):
     file = self.getfile(filename)
     path = self.dir + filename
     if os.path.isfile(path):
         input = FileUtil.open(path, "r")
         oldfile = input.read()
         input.close()
     else:
         oldfile = None
     output = FileUtil.open(path, "wb")
     output.write(file)
     print "Update	" + filename + "				OK!"
     output.close()
     input = FileUtil.open(path, "rb")
     sha1vv = FileUtil.get_file_sha1(input)
     # print sha1v.strip()
     # print sha1vv.strip()
     input.close()
     if sha1v.strip() == sha1vv.strip():
         print "Verify	" + filename + "				OK!"
     else:
         print "Verify	" + filename + "				Fail!"
         if oldfile:
             output = FileUtil.open(path, "wb")
             output.write(oldfile)
             output.close()
         print "Recover	" + filename + "				OK!"
     if filename.strip() == "/autoupdate.ini".strip():
         newconfig = Config(__config__)
         newconfig.writeconfig("autoupdate", "server", common.AUTOUPDATE_SERVER_STR)
         print "ReWrite	/autoupdate.ini				OK!"
         common.reloadini()
         print "ReLoad	/autoupdate.ini				OK!"
Esempio n. 3
0
 def writefile(self, filename, sha1v):
     file = self.getfile(filename)
     path = self.dir + filename
     if os.path.isfile(path):
         input = FileUtil.open(path, "r")
         oldfile = input.read()
         input.close()
     else:
         oldfile = None
     output = FileUtil.open(path, "wb")
     output.write(file)
     print 'Update	' + filename + '				OK!'
     output.close()
     input = FileUtil.open(path, "rb")
     sha1vv = FileUtil.get_file_sha1(input)
     #print sha1v.strip()
     #print sha1vv.strip()
     input.close()
     if sha1v.strip() == sha1vv.strip():
         print 'Verify	' + filename + '				OK!'
     else:
         print 'Verify	' + filename + '				Fail!'
         if oldfile:
             output = FileUtil.open(path, "wb")
             output.write(oldfile)
             output.close()
         print 'Recover	' + filename + '				OK!'
     if filename.strip() == '/autoupdate.ini'.strip():
         newconfig = Config(__config__)
         newconfig.writeconfig('autoupdate', 'server',
                               common.AUTOUPDATE_SERVER_STR)
         print 'ReWrite	/autoupdate.ini				OK!'
         common.reloadini()
         print 'ReLoad	/autoupdate.ini				OK!'
def makehash(dir,topdown=True):
	try : 
		print 'Generating '+common.CONFIG_SHA1+' table...'
		FileUtil.if_has_file_remove(common.CONFIG_SHA1)
		sha1 = Config(common.CONFIG_SHA1)
		for root, dirs, files in os.walk(dir, topdown):
			for name in files:
				path = os.path.join(root,name)
				newpath = path.replace(dir,'$path$')
				regexpath = path.replace(dir,'.')
				if regexpath.startswith(common.REGEX_START) or regexpath.endswith(common.REGEX_END):
					continue
				else:
					sha1v = FileUtil.sumfile(path)
					sha1.writeconfig('FILE_SHA1',newpath,sha1v)
		print 'DONE generate '+common.CONFIG_SHA1+' table!'
		return sha1
	except Exception as e:
		print 'FAIL to generate '+common.CONFIG_SHA1+' table!'
		print e
		sys.exit()
Esempio n. 5
0
def makehash(dir, topdown=True):
    try:
        print 'Generating ' + common.CONFIG_SHA1 + ' table...'
        FileUtil.if_has_file_remove(common.CONFIG_SHA1)
        sha1 = Config(common.CONFIG_SHA1)
        for root, dirs, files in os.walk(dir, topdown):
            for name in files:
                path = os.path.join(root, name)
                newpath = path.replace(dir, '$path$')
                regexpath = path.replace(dir, '.')
                if regexpath.startswith(
                        common.REGEX_START) or regexpath.endswith(
                            common.REGEX_END):
                    continue
                else:
                    sha1v = FileUtil.sumfile(path)
                    sha1.writeconfig('FILE_SHA1', newpath, sha1v)
        print 'DONE generate ' + common.CONFIG_SHA1 + ' table!'
        return sha1
    except Exception as e:
        print 'FAIL to generate ' + common.CONFIG_SHA1 + ' table!'
        print e
        sys.exit()