Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update config.py #635

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update config.py
Updated the config.py file to Python3.
  • Loading branch information
texasbe2trill committed Oct 30, 2022
commit a7022fa818ea07134f828211c082e7f5b2ecd8d7
45 changes: 25 additions & 20 deletions cpyrit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,53 @@
# You should have received a copy of the GNU General Public License
# along with Pyrit. If not, see <http://www.gnu.org/licenses/>.

from __future__ import with_statement

import os
import sys


def default_config():
config = {'default_storage': 'file://',
'use_CUDA': 'false',
'use_OpenCL': 'false',
'rpc_server': 'false',
'rpc_announce': 'true',
'rpc_announce_broadcast': 'false',
'rpc_knownclients': '',
'workunit_size': '75000',
'limit_ncpus': 0}
"""Defines the default configuration for Pyrit"""
config = {
"default_storage": "file://",
"use_CUDA": "false",
"use_OpenCL": "false",
"rpc_server": "false",
"rpc_announce": "true",
"rpc_announce_broadcast": "false",
"rpc_knownclients": "",
"workunit_size": "75000",
"limit_ncpus": 0,
}
return config


def read_configfile(filename):
"""Reads the configuration file and then returns config"""
config = default_config()
with open(filename, 'rb') as f:
with open(filename, "rb") as f:
for line in f:
if line.startswith('#') or '=' not in line:
if line.startswith("#") or "=" not in line:
continue
option, value = map(str.strip, line.split('=', 1))
option, value = list(map(str.strip, line.split("=", 1)))
if option in config:
config[option] = value
else:
print >> sys.stderr, "WARNING: Unknown option '%s' " \
"in configfile '%s'" % (option, filename)
print(
f"WARNING: Unknown option {option} in configfile {filename}",
file=sys.stderr,
)
return config


def write_configfile(config, filename):
with open(filename, 'wb') as f:
"""Writes to the config file"""
with open(filename, "wb") as openfile:
for option, value in sorted(config.items()):
f.write("%s = %s\n" % (option, value))
openfile.write(f"{option} = {value}\n")


configpath = os.path.expanduser(os.path.join('~', '.pyrit'))
default_configfile = os.path.join(configpath, 'config')
configpath = os.path.expanduser(os.path.join("~", ".pyrit"))
default_configfile = os.path.join(configpath, "config")

if os.path.exists(default_configfile):
cfg = read_configfile(default_configfile)
Expand Down