Пример #1
0
 def _compile_string_constant(self):
     string_const = self._tokenizer.get_token()
     self._vm_writer.write_push(MemorySegmentType.CONSTANT, len(string_const))
     self._vm_writer.write_call(*OS.get_string_new())
     for character in string_const:
         self._vm_writer.write_push(MemorySegmentType.CONSTANT, ord(character))
         self._vm_writer.write_call(*OS.get_string_append())
Пример #2
0
	def isKeyImported(self, id_):
		"""
		Checks if a public or private key is imported into the local keyring.
		
		@param id_	str:	An 8 or 16 character hex string
		"""
		return id_ + ":" in OS.runCMD("gpg --list-secret-keys --with-colons").stdout or \
			   id_ + ":" in OS.runCMD("gpg --list-public-keys --with-colons").stdout
Пример #3
0
    def get_OS(self):
        oss = []

        for OS_node in self.host_node.getElementsByTagName('osclass'):
            os = OS.OS(OS_node)
            oss.append(os)

        for OS_node in self.host_node.getElementsByTagName('osmatch'):
            os = OS.OS(OS_node)
            oss.append(os)

        return oss
Пример #4
0
    def __init__(self, name, time_stamp, header=None):
        self._platform = Platform.Platform()
        self._os = OS.OS()
        self._name = name
        self._ERR_FILE_EXIST = "ERROR: Log file '%s' already exists" % name
        self._ERR_FILE_OPEN = "ERROR: Unable to open log file '%s'" % name
        
        if self._os.is_file(name):
            raise Error.Error(msg=self._ERR_FILE_EXIST)
        else:
            try:
                f = open(name, 'w')
            except IOError:
                raise Error.Error(msg=self._ERR_FILE_OPEN)
            
            if header != None:
                f.write("%s\n" % header)

            line = "Generated %s" % time_stamp.as_string()
            f.write(line+"\n\n")
            line = "System: %s" % self._platform.system()
            f.write(line+"\n")
            line = "Python version: %s" % self._platform.python_version()
            f.write(line+"\n")
            line = ("Python implementation: %s" 
                    % self._platform.python_implementation())
            f.write(line+"\n\n")
            f.close()
Пример #5
0
 def hasRule(cls, port, policy, proto="tcp", source="0/0", dest="0/0", states=[]):
     if not isinstance(port, list):
         port = list(port)
     policy = policy.upper()
     assert policy in ["ACCEPT", "DROP"]
     
     proto = proto.lower()
     if not isinstance(proto, list):
         proto = list(proto)
     
     states = [state.upper() for state in states]
     if not isinstance(states, list):
         states = list(states)
     
     if source == ["anywhere"]:
         source = ["0/0"]
     if dest == ["anywhere"]:
         dest = ["0/0"]
     
     if proto != ["all"]:
         proto = [proto, "all"]
     
     for line in OS.runCMD("sudo iptables -L").stdout:
         line = line.split()
         if line[0] == policy and line[1] in proto and line[3] == 
         
     sshFinder = lambda x: x[0] == "ACCEPT" and x[1] in ["tcp", "all"] and x[3] == "anywhere" and x[4] == "anywhere" and "dpt:ssh" in x[5:]
Пример #6
0
	def encrypt(self, inputFilePath, keyID):
		"""
		Encrypts a file.
		
		Note that the necessary keys must already be imported, signed, and trusted in the local keyring
		in order for encryption to work.
		
		@param inputFilePath	str:	File to encrypt. Will not be modified.
		@param keyID			str:	An 8 or 16 character hex string
		@return					str:	Path of the encrypted file
		"""
		inputFilePath = str(inputFilePath)
		outputFilePath = inputFilePath + ".pgp"
		if os.path.exists(outputFilePath):
			os.remove(outputFilePath)
		OS.runCMD("gpg --batch -r %s --output %s --encrypt %s", (keyID, outputFilePath, inputFilePath))
		return outputFilePath
Пример #7
0
	def decrypt(self, inputFilePath, password=None):
		"""
		Decrypts a file.
		
		Note that the necessary keys must already be imported, signed, and trusted in the local keyring
		in order for decryption to work.
		
		@param inputFilePath	str:	File to decrypt. Must have .pgp extension. Will not be modified.
		@param password			str:	Password of private key in keyring, or None if no password.
		@return					str:	Path of the decrypted file
		"""
		inputFilePath = str(inputFilePath)
		assert inputFilePath.endswith(".pgp")
		outputFilePath = os.path.splitext(inputFilePath)[0]
		if os.path.exists(outputFilePath):
			os.remove(outputFilePath)
		if password != None:
			OS.runCMD("gpg --batch --passphrase %s --output %s --decrypt %s", (password, outputFilePath, inputFilePath))
		else:
			OS.runCMD("gpg --batch --output %s --decrypt %s", (outputFilePath, inputFilePath))
		return outputFilePath
Пример #8
0
 def _compile_operators(self, operator_list, unary=False):
     for op in operator_list:
         if op == '*':
             self._vm_writer.write_call(*OS.get_multiply())
         if op == '/':
             self._vm_writer.write_call(*OS.get_divide())
         elif op == '+':
             self._vm_writer.write_arithmetic(ArithmeticCommandType.ADD)
         elif (op == '-') & (unary == False):
             self._vm_writer.write_arithmetic(ArithmeticCommandType.SUB)
         elif op == '-':
             self._vm_writer.write_arithmetic(ArithmeticCommandType.NEG)
         elif op == '=':
             self._vm_writer.write_arithmetic(ArithmeticCommandType.EQ)
         elif op == '>':
             self._vm_writer.write_arithmetic(ArithmeticCommandType.GT)
         elif op == '<':
             self._vm_writer.write_arithmetic(ArithmeticCommandType.LT)
         elif op == '&':
             self._vm_writer.write_arithmetic(ArithmeticCommandType.AND)
         elif op == '|':
             self._vm_writer.write_arithmetic(ArithmeticCommandType.OR)
         elif op == '~':
             self._vm_writer.write_arithmetic(ArithmeticCommandType.NOT)
Пример #9
0
	def getKeyID(self, filename):
		"""
		Gets first key ID of the key in filename.
		
		@return str:	8 character hex string
		"""
		filename = str(filename)
		
		id_ = None
		for line in OS.runCMD("gpg --with-colons %s", filename).stdout.split("\n"):
			line = line.split(":")
			if line[0] == "pub":
				if id_ != None:
					raise Exception("More than 1 key found in " + filename)
				id_ = line[4][8:]
		return id_
Пример #10
0
    def do_mycommand(self, args, arguments):
        """
        ::
          Usage:
                mycommand path

          Arguments:
              path   the folder path for all the file we need to upload to the server

        """
        client = mqtt.Client()
        client.reinitialise()

        client.connect("www.youtube.com")

        files = os.listdir(arguments)
        for file in files:
          client.publish('filename',file)
        
        client.disconnect()
Пример #11
0
import OS
import time

start = time.perf_counter()
for x in range(1000):
    pid = OS.getpid()

finish = time.perf_counter()

final = finish - start

print(final)
Пример #12
0
	def importPublicKey(self, keyFile):
		keyFile = str(keyFile)
		OS.runCMD("gpg --batch --import %s", keyFile)
Пример #13
0
 def __init__(self):
     self._os = OS.OS()
     self._existing_file = "mocks/test.log"
     self._non_existing_file = "mocks/non_existing_file"
Пример #14
0
	def markKeyTrusted(self, id_):
		"""
		LIMITATION: Owner trust of key can't be set non-interactively for it due to limitations in the gnupg interface
		"""
		OS.runCMD("gpg --edit-key %s trust quit", id_)
Пример #15
0
	def signKey(self, id_):
		"""
		LIMITATION: If key is already signed, gnupg prints out key information to terminal even if stdout is connected to pipe
		"""
		OS.runCMD("gpg --batch --lsign-key %s", id_)
Пример #16
0
	def importPrivateKey(self, keyFile):
		keyFile = str(keyFile)
		OS.runCMD("gpg --batch --allow-secret-key-import --import %s", keyFile)
#test 2: check time average of L = 32 is 53.9

p1 = 0.5
p2 = 0.5

for l in [16, 32]:

    i = 0

    tc = []

    h1 = []

    t = []

    sandbox = OS.box(l, N, p1, p2)

    while i <= N:

        #drive

        sandbox.drive()

        sandbox.relax()

        if sandbox.steady() == True:

            h = 0

            tc.append(i)
Пример #18
0
import DecisionMaking
import random
import OS


training_steps = 5000
epsilon        = 0.5
load_period    = 40
min_vms        = 4
max_vms        = 15


scenario = OS.OSScenario(load_period=load_period, min_vms=min_vms, max_vms=max_vms)

dm = DecisionMaking.DecisionMaker("/home/ubuntu/tiramola/decisionMaking.json",
                                  "/home/ubuntu/tiramola/training.data")
dm.set_prioritized_sweeping()
dm.set_splitting(DecisionMaking.ANY_POINT)
dm.set_state(scenario.get_current_measurements())



for time in range(training_steps):
    if random.uniform(0, 1) <= epsilon:
        action = random.choice(dm.get_legal_actions())
    else:
        action = dm.suggest_action()

    scenario.execute_action(action)
    meas = scenario.get_current_measurements()
Пример #19
0
 def _compile_constructor_pointer_segment_setup(self, num_words):
     if num_words != 0:
         self._vm_writer.write_push(MemorySegmentType.CONSTANT, num_words)
     self._vm_writer.write_call(*OS.get_alloc())
     self._vm_writer.write_pop(MemorySegmentType.POINTER, 0)
Пример #20
0
reload(sys)
sys.setdefaultencoding('utf-8')
temporary_folder = os.path.expanduser('~/Temporary')

## 커스텀 모듈 ##
pymodule_path = '/home/sungyo/Unison/script/module/python'
sys.path.append(pymodule_path)
# sys.path.append('../')
import IO
Config = IO.Shelve(filename='./Data/gooviewer_config.dat')
File = IO.File()
Log = IO.Log(log_name='ViewerPanel', filelogging=False)

import OS
FileManager = OS.FileManager()

import View.Configure
import Data.WildCard
wildcard = Data.WildCard.getKeywords()
wildcard_on_listdir = wildcard[1]

# import self.ImageCtrl
# ImageCtrl = self.ImageCtrl.ImageCtrl()


# class ViewerPanel(wx.Panel):
class ViewerPanel(wx.ScrolledWindow):
    def __init__(self, parent, imageCtrl):

        wx.ScrolledWindow.__init__(self, parent)
Пример #21
0
    for jg in range(M):  # the number of realisations

        #open a file named l

        fileout = open(f"{l}_{jg}", "wb")

        i = 0

        h1 = []

        t = []

        tc = []

        sandbox = OS.box(l, N, p1, p2)

        while i <= N:

            #drive

            sandbox.drive()

            sandbox.relax()

            tt = i

            if sandbox.steady() == True:

                tc.append(i)
Пример #22
0
 def __init__(self):
     self._os = OS.OS()
     self._ts = TimeStamp.TimeStamp()
     self._existing_log_file = "mocks/test.log"