I'm doing tests for a system on which the output depends on the current date, the system compares the output with an expected output I prepared previously.
For the test to pass, I shall invoke the system with the same date so I can obtain the same results and the test can succeed. otherwise, the test will fail.
I want to set the current date within the cmd scope ONLY without affecting the current date of the system.
This date is accessed either using the latex (\the\year) variable and from python using the datetime library (datetime.now()).
I tried using the date command but this changes the date in the system which triggers many operations and errors (Antivirus updates, etc ...) because its a corporate server so I should not change the date of the server while running the tests.
I can write code to neglect the comparison of the dates, but this operation is too complicated as the date is written in generated PDFs and many other files are in different formats.
So, is it possible to change the current date within the windows 10 command line ONLY (Not system scope)?
you might find your answer here Stackoverflow Discussion about Datetime from CMD and here Getting Datetime independently from Windows locale
Furthermore, you can set a locale in python this way:
import locale
locale.setlocale(locale.LC_TIME, "your/locale/here")
making something that works across both Python and LaTeX is awkward and very OS specific. google suggests that tools like RunAsDate exists for Windows but they hook some pretty nasty internal calls to do things
as #ndclt suggested, in Python the standard approach would be to "mock" the relevant functions out such that they return a known value. under LaTeX you could write a "test harness" that does \year=2000 \input{orig.tex}
Related
(I'm not a pyschologist nor pysychopy export but helping one)
We're developing an expirement using the Coder (not Builder).
The output of an experiment is written out using the data.ExperimentHandler.addData().
When I run the application on my machine I get output like this:
,,1,1,z,f,o,o,1.254349554568762,0.8527608618387603,0.0,1.0,FSAS,,,,,,,,,,,,,,,52,male,52,
When the other person runs the application she gets:
;;0;1;z;z;j;j;105.498.479.999.369;0.501072800019756;1.0;1.0;FNES;;;;;;;;;;;;;;;23;male;0
(the difference I want to show is about format, not the values)
There are 2 differences:
RT values > 1 are printed wrong: the value 105.498.479.999.369 (RT less then 1.5s) should be 1.05498479999369
value separator is ; in my output and , in hers. I don't know what is the best value separator comma or semilcolon for later processing in R ?
I think it has to do something with regional settings.
Question: Is it possible to force the format so the application always generates the same output format independant from local settings ?
You don't specify whether you are using the graphical Builder interface to PsychoPy to generate your Python script, or writing a custom script directly in Python.
If using the Builder interface, click the "Experiment settings" toolbar icon select the "Data" tab, and specify that the datafile delimiter should be "comma" rather than "auto".
If running your own script, then in the saveAsWideText() method of the ExperimentHandler class, similarly specify ',' as the delim parameter. The API is here:
https://psychopy.org/api/data.html
In future, you will likely get better support at the dedicated PsychoPy forum at https://discourse.psychopy.org
The actual PsychoPy developers and other experienced users are much more likely to see your queries there compared to here at StackOverflow.
I found this answer, and it somewhat provides what I needed, but I wanted to ask about any problems that can occur when storing and pulling files from Dropbox based on date.
I have an employee list with the filename empList.txt sitting in a DB folder named empList-20171106_183150. The folder name has the year,month,day and time right down to the second, appended to it(YYYYMMDD_HHMMSS).
Locally, I have a python script that has a log(txt), which just contains the date of the last time the script went and downloaded the updated list. The log looks like this if the last time the script ran was on Nov 01 2017 at 9am
20171101_090020
If I used Dropbox and a script written in Python to download the lastest version based on the date/time, are there any disadvantages to doing this?
I just compare the date stored in the log, to the date appended on the folder. If the date of folder in DB is greater, a download is needed. My only concern is during the date comparison and download, one of the managers might upload a new list, meaning I would have to run the script again.
How do complete programs such as MalwareBytes or internet security software manage a user downloading an update when they make a new update available at the same time? For me, I just run the update again to make sure while I was checkking/updating a new update wasn't made available.
I wouldn't recommend using date comparisons, because of potential issues with race conditions, like you mentioned, etc.
The Dropbox API exposes ways to tell if things have changed instead. Specifically, when downloading the file, you should store the metadata for the version of the file you downloaded. In particular, FileMetadata.rev or FileMetadata.content_hash would be useful.
If you then check again later and either of those values are different than the last one you downloaded, you know something has changed, so you should re-download.
I need to access the date and time in ubuntu from a program.This program may not use any commands to do this. So making a call to date is not an option.
Is there a file or files which hold this information?
Where can it be found ?
No, read time(7). There are some system calls (listed in syscalls(2)...) to query the time (since Unix Epoch); in particular time(2) and clock_gettime(2).
You then need to convert that time into a string, probably using localtime(3) then strftime(3). That conversion use some files notably /etc/timezone (and some under /usr/share/zoneinfo/ ...) according to TZ variable (see environ(7) and locale(7)).
BTW, date is free software (so you could study its source code). And you could strace(1) it.
See also vdso(7) and this.
I am writing a script to export alembic caches of animation in a massive project containing lots of maya files. Our main character is having an issue; along the way his eyes somehow ended up with the same name. This has created issues with the alembic export. Dose maya already have a sort of clean up function that can correct matching names?
Any two objects can have the same names, but never the same DAG paths. In your script, make sure all your ls, listRelatives calls etc. Have the full path or longName or long flags set so you always operate on the full DAG paths as opposed to the possibly conflicting short names.
To my knowledge maya (and its python api) does not offer anything like that.
You'll have to run a snippet on export to check for duplicates before export.
Or, alternatively use an already existing script and run that.
I would like to write a small script that does the following (and that I can then run using my crontab):
Look into a directory that contains directories whose names are in some date format, e.g. 30-10-09.
Convert the directory name to the date it represents (of course, I could put this information as a string into a file in these directories, that doesn't matter to me).
Compare each date with the current system time and find the one that has a specific time difference to the current system date, e.g. less than two days.
Then, do something with the files in that directory (e.g., paste them together and send an email).
I know a little bash scripting, but I don't know whether bash can itself handle this. I think I could do this in R, but the server where this needs to run doesn't have R.
I'm curious anyway to learn a little bit of either Python or Ruby (both of which are on the server).
Can someone point me in the right direction what might be the best way to do this?
I would suggest using Python. You'll need the following functions:
os.listdir gives you the directory contents, as a list of strings
time.strptime(name, "%d-%m-%y") will try to parse such a string, and return a time tuple. You get a ValueError exception if parsing fails.
time.mktime will convert a time tuple into seconds since the epoch.
time.time returns seconds since the epoch
the smtplib module can send emails, assuming you know what SMTP server to use. Alternatively, you can run /usr/lib/sendmail, through the subprocess module (assuming /usr/lib/sendmail is correctly configured)