I am making a jython application that needs a config/settings file (and probably eventually directory) but I want it be stored in the expected/correct directory for each os.
~/.app_name/config in linux
c:/documents and Settings/User/app_name ?? in windows.
I have found this:
http://snipplr.com/view/7354/home-directory-crossos/
but this is for python and I have feeling that this might not necessary work for jython/windows and I don't have any dev stuff set up in my windows VM to test at this moment
If someone could provide any insight into the "best practices" (for jython) for achieving this I would greatly appreciate it.
Thanks.
EDIT:
Here is what I have come up with that seems to be working...I would appreciate any feedback
import os
from java.lang import System
from java.io import File
os_name = System.getProperty('os.name')
os_sep = File.separator
app_name = 'ctrlmac'
if os_name == 'Windows':
config_dir = os.environ["APPDATA"] + os_sep + app_name
else:
config_dir = os.path.expanduser("~") + os_sep + '.' + app_name
print config_dir
Related
I'm trying to test a hy project with pytest but am having trouble with pytest discovering my tests. What needs to be done so that pytest can pick up tests written in hy? I've made the assumption that tests can be written in hy and discovered by pytest because of the native_tests section in the main hy repo. If this is a bad assumption, no need to read on. Please let me know.
My project root looks something like this:
src
.hy program files
tests
__init__.py
test_*.hy test files where each test function is prefixed with test-*
pytest.ini
inside of pytest.ini I have the following:
[pytest]
python_functions = test_* is_test_* hyx_test_* hyx_is_test_*
testpaths = tests
I stole the python_functions section out of the hy repo's setup.cfg
Thank you!
The missing ingredient is Hy's confest.py, which defines hook functions pytest uses to discover tests. For example, we define pytest_collect_file like this:
def pytest_collect_file(parent, path):
if (path.ext == ".hy"
and NATIVE_TESTS in path.dirname + os.sep
and path.basename != "__init__.hy"):
if hasattr(pytest.Module, "from_parent"):
pytest_mod = pytest.Module.from_parent(parent, fspath=path)
else:
pytest_mod = pytest.Module(path, parent)
return pytest_mod
Looking at this, specifically:
containers = {'us-west-2': '433757028032.dkr.ecr.us-west-2.amazonaws.com/xgboost:latest',
'us-east-1': '811284229777.dkr.ecr.us-east-1.amazonaws.com/xgboost:latest',
'us-east-2': '825641698319.dkr.ecr.us-east-2.amazonaws.com/xgboost:latest',
'eu-west-1': '685385470294.dkr.ecr.eu-west-1.amazonaws.com/xgboost:latest'}
sess = sagemaker.Session()
xgb = sagemaker.estimator.Estimator(containers[boto3.Session().region_name],
role,
instance_count=1,
instance_type='ml.m4.xlarge',
output_path='s3://{}/{}/output'.format(bucket, prefix),
sagemaker_session=sess)
where do these entries (contain image names?):
'685385470294.dkr.ecr.eu-west-1.amazonaws.com/xgboost:latest'
come from? I am especially after a eu-west-2 one - hope there is one (-: Thanks!
PS:
It may be that I can just run - at run time?:
from sagemaker import image_uris
image_uris.retrieve(framework='xgboost', region='eu-west-2', version='latest')
I'm not an expert, but those are the container registry path and you can find the full list here.
Yes.
You can use this code snippet:
from sagemaker import image_uris
image_uris.retrieve(framework='xgboost', region='eu-west-2', version='latest')
and it will give you this value:
644912444149.dkr.ecr.eu-west-2.amazonaws.com/xgboost:latest
This is the latest version of the container but it not recommended to run in prod environments.
https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-algo-docker-registry-paths.html
This is my first time putting a question here. Some background, I started coding on Django this year and Python more than a year but less than 2 years so I don't much. This problem is a concern to my what I developing in at work. And my team working on it is novice or no experience on coding Python or Django or both.
The Problem
We have a web app based on Django 3.0.2 and use MSSQL for the db. Our company policy is to use Windows server and IIS as the prod and test server. We done a lot of work on it and all work well except for some python library and Django module that don't work, mainly Xlwings and Django-post-office. For XLwings, it doesn't run the code and Excel(we have valid license and latest Excel programme on the server).
code below;
filepath = BASE_DIR + '\\media\\Template.xlsm'
temp_path = BASE_DIR + '\\media\\' + '{}.{}'.format(uuid4().hex, 'xlsm')
shutil.copyfile(filepath, temp_path)
pythoncom.CoInitialize()
app1 = xw.App(visible=True)
wt = xw.Book(temp_path)
sht = wt.sheets['Cover']
sht.range('E5').value = request.POST.get('year')
sht.range('E6').value = request.POST.get('company')
sht.range('E7').value = companydata.employer_no
sht.range('E8').value = email
wt.save(temp_path)
app1.quit()
As for Django-post-office, we have a module using it that got it working but other modules using it doesn't work. Same code that is used except for the template and subject.
Code below;
plaintext = get_template('template.txt')
htmly = get_template('template.html')
mail.send(
[email],
NAME_EMAIL_DOMAIN,
message = plaintext.render(info),
html_message = htmly.render(info),
subject = f'Subject',
priority = 'now',
attachments = {
'RemunerationTemplate.xlsm': temp_path,
},
)
The bizarre thing is it work on CMD but it just doesn't work on IIS. We don't know why and how to rectify it. We ask the IT Support (department responsible for the servers) said that the test server is not restricted.
The Fail Fix
Try change IIS config, enviroment etc - No Dice
Change code - We are noobs, idk what's wrong but clearly doesn't work
Google it - too sparse for info
Ask the IT support guy if he has any idea - he doesn't care much on it and just say to me to piss off
So, I grateful if any help for this since we are nearing the deployment date and this issue is haunting me in my sleep for the past week already. Thank You
How can I get the current DNN Logo file's Absolute URL Path?
Currently, Google picks up the Relative Path. /Portals/2/Images/logo.png
I need the full path with the domain name.
I want something almost like: PortalSettings.PortalAlias.PortalID
The Google Structured Data Tool gives the following path after I have added itemprop="logo" to the logo.ascx file found under Admin/Skins in DNN.
I came up with the following code, but I only still need the protocol which will be http:// or https://
The code below will generate dnndev.me/Portals/2/Images/logo.png
I just need to figure out how to get the protocol. I am sure the code below can be simplified.
PortalLogoPath = PortalSettings.Current.PortalAlias.HTTPAlias + PortalSettings.HomeDirectory + PortalSettings.LogoFile;
PortalLogoPath = HttpContext.Current.Request.Url.Scheme + "://" + PortalSettings.Current.PortalAlias.HTTPAlias + PortalSettings.HomeDirectory + PortalSettings.LogoFile;
How can I force ddt to show me stacktrace? I can only see parts of templates in which queries are executed. But there are no views which generates queries. I set
'ENABLE_STACKTRACES' : True
in settings but this does not help me. I have version 0.9.4.
Allow myself to quote... myself:
You can patch your 0.9.4 install by changing debug_toolbar/panels/sql.py:197 to read
params = map(escape, os.path.split(frame[0]) + frame[1:])
(and import os.path somewhere above).
It looks like this issue was fixed in 12fdf7e (render_stacktrace).