Skip to content

Commit

Permalink
Merge pull request #85 from iewnfod/dev
Browse files Browse the repository at this point in the history
Update to Nightly
  • Loading branch information
iewnfod authored Apr 4, 2024
2 parents 33673b8 + f7cbe55 commit e1bf2ff
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ It runs the entire file if `filepath` is provided, otherwise, it enters playgrou
- `recursion-limit(rl)`
all integer number as the recursion depth limit of the interpreter.

- `integrity-protection`

- `true`: Enable integrity protection.
- `false`: Disable integrity protection.

> Integrity Protection prevent any accidental or malicious modification of the interpreter.
> This protection will be automatically disabled in developer mode.
- `dev`

- `true`: Enable developer mode.
Expand Down
9 changes: 9 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ cpc [file_paths] [options]
- `true`: 启用开发者模式。
- `false`: 关闭开发者模式。

- `integrity-protection`

- `true`: 启用完整性保护。
- `false`: 禁用完整性保护。

> 完整性保护将会阻止任何意外或恶意的解释器修改。
> 此保护将在开发者模式下被自动禁用。
- 开发者选项

- `dev.simulate-update`
Expand Down
4 changes: 4 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from src.line_commands import run_command
from src.update import update
from src.update import update_expired
from src.update import integrity_protection

import sys
import os
Expand Down Expand Up @@ -193,6 +194,9 @@ def main(input_=None, output_=None, addition_file_name=None):
if addition_file_name:
file_paths.add(addition_file_name)

if not config.get_config('dev') and config.get_config('integrity-protection'):
integrity_protection()

#自动更新
if config.get_config('dev.simulate-update') or (config.get_config('auto-update') and not config.get_config('dev') and update_expired()):
update()
Expand Down
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, config_file_name=".cpc_config.json"):
self.config = {
'remote': _Config('remote', 'https://github.com/iewnfod/CAIE_Code.git', remote_update),
'dev': _Config('dev', False, dev_mod),
'integrity-protection': _Config('integrity-protection', True, integrity_protection),
'branch': _Config('branch', 'stable', branch_update),
'rl': _Config('recursion-limit', 1000, recursive_limit),
'dev.simulate-update': _Config('dev.simulate-update', False, simulate_update),
Expand Down
2 changes: 2 additions & 0 deletions src/config_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def update(self, obj, val):

dev_mod = DictConfig({'true': True, 'false': False})

integrity_protection = DictConfig({'true': True, 'false': False})

branch_update = SetConfig({'stable', 'nightly', 'dev'})

simulate_update = DictConfig({'true': True, 'false': False})
Expand Down
3 changes: 2 additions & 1 deletion src/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ def get_value(value):
return options_dict[value]

def standard_output():
import datetime
print(f'CAIE Pseudocode Interpreter v{VERSION} ({get_current_branch()}/{get_commit_hash_msg()[0]})')
print(f'Using {PLATFORM}')
print('Repository at \033[4mhttps://github.com/iewnfod/CAIE_Code/\33[0m')
print('Copyright (c) 2023 Iewnfod. ')
print(f'Copyright © {datetime.datetime.now().year} Iewnfod. ')
print('All Rights Reserved. ')

def open_parse_info():
Expand Down
15 changes: 15 additions & 0 deletions src/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ def show_notification(_branch):
else:
print("🙁No developer notification available.")

def integrity_protection():
repo = git.Repo(HOME_PATH)
if not os.environ.get('CODESPACES'):
current_branch = get_current_branch()
local_commit = repo.head.commit
remote_branch = repo.remote().refs[current_branch]
remote_commit = remote_branch.commit
diff = local_commit.diff(remote_commit)

if diff or repo.is_dirty():
repo.git.reset('--hard', remote_commit)
print("❗INTEGRITY WARNING❗")
print("Changes have been discarded")
print("---------------------------------")

def update():
from .global_var import config
if os.getenv('CODESPACES'):
Expand Down

0 comments on commit e1bf2ff

Please sign in to comment.