Jump to content

A whole bunch of stuff. Stacks, recursive file copying (implemented iteratively) and more...


elektron
 Share

Recommended Posts

Hello everyone,

I've been working on this for a couple of months now, improving as I go. I still think that all of you are going to take two looks at this code and laugh at me, but I'd really like someone to look at this. I've done a couple of things:

I've written a stack data structure that performs pushes and pops is O(1) time.

I've written a function that recursively copies a directory tree, and is capable of verifying files as it goes along the way. It will also use callback functions to notify your GUI and keep it from freezing up.

I've make a function that will recursively list all the files in a given directory.

I'm in the process of writing a script that allows scripts to communicate through dropbox and simplifies dropbox management. The scripts that allow scripts to communicate with each other can be used on files and folders other than dropbox -- think network share -- because the whole thing purely using files. All it depends on is that there is a place it can put a folder with a bunch of files in it.

Whole ton of cool stuff, this is like 2500 lines of code.

For the sake of simplicity, I've put the code up on GitHub. You can check it out at:

https://github.com/alvonellos/AutoIt_Code-Snippets

Comment if you plan on using it, are using it, or find any potential bugs.

I've pulled this from production code, so if you see anything that shouldn't be there, let me know

Take Care,

-- Alex

Link to comment
Share on other sites

Hello elektron, I am currently looking for away to communicate with my machines from a distance. I figured the best thing I could do is send texts to my email and run a reactive email listener. However I've never worked with things like that and I am having trouble getting started. This sounds like if I had access to my dropbox account I could update a file with messages for my distant computers running a listener on my dropbox account. I hope this is not redundant, is that a goal of this project?

Link to comment
Share on other sites

Hello elektron, I am currently looking for away to communicate with my machines from a distance. I figured the best thing I could do is send texts to my email and run a reactive email listener. However I've never worked with things like that and I am having trouble getting started. This sounds like if I had access to my dropbox account I could update a file with messages for my distant computers running a listener on my dropbox account. I hope this is not redundant, is that a goal of this project?

Yes. The __DROPBOX__COMM__* namespace was intended exclusively for inter-script communication.

I wanted to make communication between scripts more natural, so I created this script and approached the problem a little bit differently.

I have this model of a "channel" by which the scripts, (or people for that matter) can "subscribe" to. It's pretty neat.

There are a few bugs in the scripts and I'm trying to resolve them here and there as I use the code, but what I really need is another set of eyes to help me work on this code -- it's gotten pretty massive.

Check my GitHub profile and look for DB_CHAT.exe, you're going to use that as a "shell."

Then check out this example:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.8.1
Author: Alexander Alvonellos

Script Function:
Host script for the client running dropbox
and hosting the data used for vp update.

#ce ----------------------------------------------------------------------------
#include "../Include/__DROPBOX.au3"
#include "../Include/__GENERAL.au3"
OnAutoItExitRegister("abort")
Global $DATA_HOST_DEFAULT_CHANNEL_NAME = "comm"
Global $DATA_HOST_DEFAULT_CHANNEL_PATH = @ScriptDir
Global $DATA_HOST_DEFAULT_LOG_FUNCTION = "cerr"
main()
While(True)
Sleep(100)
WEnd

Func main()
cerr("In main(), initializing...")
Local $bContactResult = __DROPBOX__COMM__CREATE_CHANNEL($DATA_HOST_DEFAULT_CHANNEL_NAME, _
$DATA_HOST_DEFAULT_CHANNEL_PATH, _
$DATA_HOST_DEFAULT_LOG_FUNCTION)
If( $bContactResult = True ) Then
cerr("In main(), I've created the channel, " & $DATA_HOST_DEFAULT_CHANNEL_NAME & ". " & _
"No errors were detected.")
Else
Local $msg = "In main(), "
If( @error = -1 ) Then
$msg &= "there was an error creating channel directory. Attempting to resolve."
__DROPBOX__TERMINATE("cerr");
$bContactResult = __DROPBOX__COMM__CREATE_CHANNEL($DATA_HOST_DEFAULT_CHANNEL_NAME, _
$DATA_HOST_DEFAULT_CHANNEL_PATH, _
$DATA_HOST_DEFAULT_LOG_FUNCTION)
__DROPBOX__INITIALIZE("cerr");
If( $bContactResult = True ) Then
$msg &= " Resolution successful."
Else
$msg &= " Resolution unsuccessful."
EndIf
ElseIf( @error = -2 ) Then
$msg &= " error creating configuration file."
ElseIf( @error = -3 ) Then
$msg = "In main(), channel already exists, everything's just fine."
Else
$msg = "In main(), BAD MAGIC."
EndIf
cerr($msg)
EndIf

Local $bPurgeResult = __DROPBOX__COMM__PURGE($DATA_HOST_DEFAULT_CHANNEL_NAME, _
$DATA_HOST_DEFAULT_CHANNEL_PATH, _
$DATA_HOST_DEFAULT_LOG_FUNCTION)

cerr("In main(), purged old datagrams from channel " & $DATA_HOST_DEFAULT_CHANNEL_NAME & ".")
Local $bSubscribeResult = __DROPBOX__COMM__SUBSCRIBE($DATA_HOST_DEFAULT_CHANNEL_NAME, _
$DATA_HOST_DEFAULT_CHANNEL_PATH, _
"RX_DATA_CALLBACK", _
$DATA_HOST_DEFAULT_LOG_FUNCTION)
EndFunc

Func RX_DATA_CALLBACK($hFile)
$szDatum = FileRead($hFile, -1)
$aszDatumBuf = StringSplit($szDatum, @LF, 2)
If( $aszDatumBuf[1] <> @ComputerName ) Then
RX_PARSE_COMMAND($aszDatumBuf[3])
EndIf
EndFunc
Func vars()
ConsoleWrite($DATA_HOST_DEFAULT_CHANNEL_NAME & "::" & $DATA_HOST_DEFAULT_CHANNEL_PATH)
EndFunc
Func RX_PARSE_COMMAND($szCommand)
;__DROPBOX__TERMINATE("cerr")
Local $oExecResult = Call($szCommand)
;__DROPBOX__INITIALIZE("cerr")
__DROPBOX__COMM__WRITE($DATA_HOST_DEFAULT_CHANNEL_NAME, _
$DATA_HOST_DEFAULT_CHANNEL_PATH, _
$oExecResult, _
$DATA_HOST_DEFAULT_LOG_FUNCTION)
EndFunc

Func abort()
cerr("In abort(), exiting.")
Local $oRemoveResult = __DROPBOX__COMM__REMOVE_CHANNEL("comm", @ScriptDir)
Exit
EndFunc

Func cerr($msg)
;__GENERAL__CERR($msg)
ConsoleWrite($msg & @LF)

EndFunc

You may have to play with it to get it work. I just pulled this code from an environment that I didn't intend to release out as an example just yet.... but. Yeah.

Let me know if you find a bug.

-- Alex.

Edited by elektron
Link to comment
Share on other sites

Thank you Alex, I will play with it this week. I'm in over my head with my project, but your project is a system I have need of really want. I'll see what I can do.

Edited by Xandy
Link to comment
Share on other sites

HI Xandy

I like the dropbox concept of communications.

Where I'm looking at it is to send files/comms to my customers in the background.

Just a few questions...Iv'e only glanced over your code so far so sorry if they are DUMB ones. :)

I assume that drobox will have to be running on each machine and loged into the same dropbox.

Do you have any idea about the situation where a computer has it's own dropbox (different account) and you want to run this?

(I have a few ideas but I wanted to know what you think first)

If you need any help let me know (PM is fine "and I'll get notification" if you want to keep this thread clean of chatter)

keep up the good work!

John Morrison

Link to comment
Share on other sites

HI Xandy

I like the dropbox concept of communications.

Where I'm looking at it is to send files/comms to my customers in the background.

Just a few questions...Iv'e only glanced over your code so far so sorry if they are DUMB ones. Posted Image

I assume that drobox will have to be running on each machine and loged into the same dropbox.

Do you have any idea about the situation where a computer has it's own dropbox (different account) and you want to run this?

(I have a few ideas but I wanted to know what you think first)

If you need any help let me know (PM is fine "and I'll get notification" if you want to keep this thread clean of chatter)

keep up the good work!

John Morrison

No problem. I think your problem is you don't have quite a handle on all the features of Dropbox. In dropbox, you can create a "shared folder" and share them with other dropbox accounts.

Dropbox is such a well-written piece of software...

Another thing, this script was awfully misnamed. Although I created it to use dropbox and with dropbox in mind, I suppose it could work with any platform where files are hosted on a central server and can be accessed as a file. This makes it possible for scripts to communicate with one another using network shares and so forth.

Now, there are a couple of things that I want you to keep in mind, there are some serious bugs in this script, and I'm working on them, but I really need someone to help me with it. If you can take a serious glance at the code, and fork your own version in GitHub and start contributing and submit a pull request, that would help with the development process a lot.

Link to comment
Share on other sites

No problem. I think your problem is you don't have quite a handle on all the features of Dropbox. In dropbox, you can create a "shared folder" and share them with other dropbox accounts.

Yep know all about that. I had to set up several dropboxs for a customer that has several businesses within the one business.

He needed to have the ALL syncing back to one computer. Dropbox doesn't allow you to sync to more than one dropbox from the same computer.

Well they do with a little trick I found (well not so little but easy when you know how).

So I got put through teh wringer on my first contact with dropbox.

Dropbox is such a well-written piece of software...

Agree!

Another thing, this script was awfully misnamed. Although I created it to use dropbox and with dropbox in mind, I suppose it could work with any platform where files are hosted on a central server and can be accessed as a file. This makes it possible for scripts to communicate with one another using network shares and so forth.

Might be worth a rename before it goes too far. Something that reflects it's true nature or you'll be stuck with it.

Now, there are a couple of things that I want you to keep in mind, there are some serious bugs in this script, and I'm working on them, but I really need someone to help me with it. If you can take a serious glance at the code, and fork your own version in GitHub and start contributing and submit a pull request, that would help with the development process a lot.

First step is outline what bugs you know of in the code. That way contributers can get them out of the way first. Because you know the code I may not trip over the bugs untill it's too late....

Also a spec of HOW you want the system to work and WHAT you eventually want it to do. That will put the contributers on the same page you are.

So if you can let me/us know those details then I/we maybe able to help out. :)

Onward and upward

John Morrison

Link to comment
Share on other sites

Yep know all about that. I had to set up several dropboxs for a customer that has several businesses within the one business.

He needed to have the ALL syncing back to one computer. Dropbox doesn't allow you to sync to more than one dropbox from the same computer.

Well they do with a little trick I found (well not so little but easy when you know how).

So I got put through teh wringer on my first contact with dropbox.

Agree!

Might be worth a rename before it goes too far. Something that reflects it's true nature or you'll be stuck with it.

First step is outline what bugs you know of in the code. That way contributers can get them out of the way first. Because you know the code I may not trip over the bugs untill it's too late....

Also a spec of HOW you want the system to work and WHAT you eventually want it to do. That will put the contributers on the same page you are.

So if you can let me/us know those details then I/we maybe able to help out. :)

Onward and upward

John Morrison

That sounds great, I've been debugging all day working on this script so far and I've fixed so many bugs. How should I put the bugs, should I add them as an issue in GitHub's issue tracker, or should I do something different?

I'm about to make a gigantic commit here, probably today, I've fixed a lot of bugs in the script, and the commit changes will be outlined later tonight when I'm not on company time.

I appreciate all the advice. I've never done group programming over the internet, so I have no idea where to begin to start "leading" a project myself...

Perhaps a rename is in accord, but I want to get it working (completely) with dropbox before I even begin to guarantee it'll work with something else.

There are a few bugs with __REMOVE_CHANNEL(), where it won't delete a channel completely. I don't know how to unlock it and delete it forcefully.

I'll post back here when I make my commit.

Link to comment
Share on other sites

Okay, the new changes are committed to my GitHub. I fixed many bugs in __DROPBOX.au3, added documentation (as requested) added a tasks section, and added a list of known bugs and a whole bunch of stuff. Check it out. :-)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...