Beispiel #1
0
 def combine(self):
     self.cmd_list = SList([])
     CHARACTER = [8, 9] + range(32, 128)
     tem_cmd = []
     tem_timestamp = []
     for item in self.operation_list:
         if len(item[1]) > 1 and '27' in item[1]:
             continue
         if len(filter(lambda x: int(x) < 0, item[1])) > 0:
             continue
         if '4' in item[1]:
             continue
         for op in item[1]:
             tem_timestamp.append(item[0])
             tem_cmd.append(op)
             if not int(op) in CHARACTER:
                 content, delimiter = self._convert_to_text(tem_cmd)
                 self.cmd_list.append({
                     'action':
                     'shell',
                     'content':
                     content,
                     'delimiter':
                     delimiter,
                     'timestamp':
                     int(tem_timestamp[0]),
                     'timestamp_end':
                     int(tem_timestamp[-1])
                 })
                 tem_cmd = []
                 tem_timestamp = []
     return self
Beispiel #2
0
    def combine(self):
        prev_command = False
        self.cmd_list = SList([])
        for item in self.operation_list:
            if item['action'] in ['insert', 'remove']:
                item['content'] = u"\n".join(item['lines'])
            elif item['action'] in ['copy', 'paste']:
                item['content'] = item['text']
            elif item['action'] in ['open', 'save']:
                item['content'] = ''
            else:
                continue

            if not prev_command:
                prev_command = item
                continue
            if (prev_command['action'],
                    item['action']) in [(u'insert', u'remove'),
                                        (u'insert', u'insert'),
                                        (u'remove', u'remove')]:
                if item['action'] == u'insert' and prev_command[
                        'action'] == u'insert' and str(
                            prev_command['end']) == str(item['start']):
                    prev_command['content'] += item['content']
                    prev_command['end'] = item['end']
                elif item['action'] == u'remove' and str(
                        prev_command['start']) == str(item['end']):
                    prev_command['content'] += item['content']
                    prev_command['start'] = item['start']
                elif item['action'] == u'insert' and prev_command[
                        'action'] == u'remove' and str(
                            prev_command['end']) == str(item['end']):
                    prev_length = len(prev_command['content'])
                    tem_length = len(item['content'])
                    if prev_length - tem_length < 0:
                        prev_command['content'] = item['content'][:tem_length -
                                                                  prev_length]
                        prev_command['action'] = u'remove'
                    else:
                        prev_command['content'] = prev_length[
                            'content'][:tem_length - prev_length]
                else:
                    self.cmd_list.append(prev_command)
                    prev_command = item
            else:
                self.cmd_list.append(prev_command)
                prev_command = item
        if prev_command:
            self.cmd_list.append(prev_command)
        return self
Beispiel #3
0
    def __init__(self, root_path):
        self.NAME_PATTERN = re.compile(
            '(.*)([0-9]{2})_([0-9]{2})_([0-9]{4})_([0-9]{2})_([0-9]{2})\+?([0-9]+)?.log_?$'
        )
        self.item_set = SList()

        os.chdir(root_path)
        self.ROOT_PATH = os.path.abspath(os.getcwd())

        for dir_item in os.listdir(self.ROOT_PATH):
            if os.path.isdir(os.path.join(self.ROOT_PATH, dir_item)):
                self._process_single_item(dir_item)
            else:
                print "Not a directory: {}".format(dir_item)
Beispiel #4
0
from slist import SList
if __name__ == '__main__':
    s = SList()
    s.insert_front('orange')
    s.insert_front('apple')
    s.insert_after('cherry', s.head.next)
    s.insert_front('pear')
    s.print_list()
    print('cherry는 {0}번째'.format(s.search('cherry')))
Beispiel #5
0
### SKU CoE ITE - ParkSooYoung ###
### Grade 2 , Semester 1 , Chapter 2 , Number 2 ###

from slist import SList  # slist.py에서 SList를 import (2-1-2-1 slist.py를 slist.py로 이름 변경 필요)
if __name__ == '__main__':  # 이 파이썬 파일(모듈)이 메인이면
    s = SList()  # 단순연결리스트 생성
    s.insert_front('orange')  # head -> orange
    s.insert_front('apple')  # apple -> orange -> cherry
    s.insert_after('cherry', s.head.next)
    s.insert_front('pear')
    s.print_list()  # pear -> apple -> orange -> cherry
    print('cherry는 %d번째' % s.search('cherry'))
    print('kiwi는', s.search('kiwi'))
    print('배 다음 노드 삭제 후 : \t\t', end='')
    s.delete_after(s.head)
    s.print_list()
    print('첫 노드 삭제 후 : \t\t', end='')
    s.delete_front()
    s.print_list()
    print('첫 노드로 망고, 딸기 삽입 후 : \t', end='')
    s.insert_front('mango')
    s.insert_front('strawberry')
    s.print_list()
    s.delete_after(s.head.next.next)
    print('오렌지 다음 노드 삭제 후 : \t', end='')
    s.print_list()
def stack(s):

    brackets = SList()

    while s :

        p = s.pop(0)

        if brackets.is_empty():

            if p == "}" or p == ")":

                print("Wrong brackets.")

                return

            elif p == "{" or p == "(":

                brackets.push(p)
                print(p)

        else:

            if p == '}':

                pop = brackets.pop()
                print(p)

                if pop != '{':

                    print("Wrong brackets.")

                    return


            elif p == ')':

                pop = brackets.pop()
                print(p)

                if pop != '(':

                    print("Wrong brackets.")

                    return

            elif p == "{" or p == "(":

                brackets.push(p)
                print(p)


    if brackets.is_empty():

        print("Good brackets.")

        return

    else:

        print("Wrong brackets.")

        return
Beispiel #7
0
 def setUp(self):
     self.list = SList()